Files
wordcraft/crates/engine/src/session/lifecycle.rs
T
Martin BallandClaude Sonnet 5.5 bf8b37759c Ctrl/Cmd+Shift+V pastes text only when no formatting was copied, as in Word (#1537) (#5616)
* #1537: Ctrl/Cmd+Shift+V pastes text only when no formatting was copied, as in Word for Windows

With formatting picked up by Ctrl/Cmd+Shift+C it still pastes the formatting.
Closes #1537, #4943; takes over #1562.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — a browser's Mod+Shift+V paste event pastes text only, once (CodeRabbit)

On the web the key no longer pastes as well: the paste event that follows carries the text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — copied formatting stays for every Mod+Shift+V; a browser's paste after it is ignored (wanikhawar)

Copy Formatting keeps its formatting apart from the one-shot Format Painter brush, so a second
Mod+Shift+V pastes formatting again instead of text, and Mod+Shift+C no longer arms the brush.
After Mod+Shift+V pastes formatting, the browser's paste event for the same keystroke is ignored;
paste events read the modifiers held in event order. Only Mod+Shift+V itself falls back to Keep
Text Only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCYPZSei56X4AGFPSu5

* #1537: review — one format buffer, formatting-only copy, browser paste suppression only where it exists

- ignore_next_paste armed only for Mod+Shift+V on platforms that send a paste event after it (web); never for a rebound key
- the ignored paste is dropped before equation and picture-file handling
- Event::Paste takes paste_mods so they don't leak into later pastes
- Copy Formatting and Format Painter replace each other; a used-up brush no longer hands over to older copied formatting
- copied formatting carries no hyperlink or revision marks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — shared format buffer, no tracked paragraph changes, pointer press ends the paste wait

- picked_format strips ParaProps fmt_change/num_change
- Format Painter pick is stored in copied_format too; a used-up or cancelled brush leaves it
- a pointer press clears ignore_next_paste
- docs: repeat-until-replaced wording

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — a caret Paste Formatting keeps the target's own link and tracked marks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — an unrelated key's modifiers can't steer a later paste event

A separate paste_event_mods is set by Mod changes and Mod+V's press, and cleared by any other key, a pointer press or focus change; the release path keeps paste_mods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — the text-only paste test checks the destination's own formatting stays (CodeRabbit)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — the docs say a Format Painter pick counts as picked-up formatting too (CodeRabbit)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — a dropped paste uses up its modifiers; range Paste Formatting keeps the link (alehel)

- The browser paste event dropped after a formatting paste now clears paste_event_mods too, so a
  later menu-bar paste isn't read as Keep Text Only. Note the no-text clipboard case.
- Test that Paste Formatting over a selection keeps the target's hyperlink.
- session.rs: copied_format holds a Format Painter pick too.
- ROADMAP: entry moved up with the other 2026-11-04 entries; stray blank line dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — the wait for Mod+Shift+V's browser paste ends after a second, so a later menu-bar paste isn't dropped (FredApps)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCX8G9hbs6XYZFsgjbL

* #1537: review — an expired paste wait drops the chord's noted Mod+Shift too (CodeRabbit)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCX8G9hbs6XYZFsgjbL

* #1537: review — dropping the paired paste uses up its modifiers; range Paste Formatting keeps the target's link

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: review — restore ui-parity status line; add Paste Formatting row to typing-parity

docs/ui-parity.md: the rebase had replaced main's status line with an older one;
restore it and prepend this PR's entry. docs/typing-parity.md: add the
Ctrl/Cmd+Shift+V row to the Paste section, bump status line and history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #1537: Ctrl/Cmd+Shift+V's V release never pastes a second time

On desktop the chord's key-down path pastes (text, or the copied formatting) but didn't mark the
paste as done, so releasing Shift before V left a plain Mod+V release that ran Paste again through
the clipboard-picture hook, inserting the text twice. The canvas's chord now marks the paste done;
the global-shortcut path (canvas unfocused, no release seen) doesn't, and a focus change clears
the mark so a lost release can't swallow a later Mod+V picture.
Docs: web text paste needs the browser to send its paired Paste event; with formatting copied that
event is dropped only within about a second of the key.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 09:59:47 +00:00

183 lines
5.7 KiB
Rust

use super::doc_state::MAX_UI_REQUESTS;
use super::prefs::Prefs;
use super::view::ViewState;
use super::{Arc, DocState, Document, ImeEditOutcome, Registry, Session, Value};
impl Session {
/// Queue a request for the front end. A headless session never drains the queue, so only
/// the newest [`MAX_UI_REQUESTS`] are kept.
pub fn push_ui_request(&mut self, req: Value) {
if self.ui_requests.len() >= MAX_UI_REQUESTS {
self.ui_requests.remove(0);
}
self.ui_requests.push(req);
}
/// Save the custom dictionary through [`Session::user_dict_path`], if the host wired one up,
/// with `removed` (words just taken out) left out of the merge with the file. A failed save
/// keeps the words in memory and never fails the command (#40), as does a file outside the
/// automation roots in force: it is read, then replaced beside itself (#3737).
pub(crate) fn persist_user_dictionary(&self, removed: &[String]) {
let Some(path) = self.user_dict_path.as_deref() else { return };
let name = path.to_string_lossy();
if let Err(e) = crate::file_access::check_read(&name)
.and_then(|()| crate::file_access::check_write(&name))
.and_then(|()| wordcraft_proof::save_user_dictionary(path, removed).map_err(|e| e.to_string()))
{
log::warn!("custom dictionary: save failed: {e}");
}
}
/// Start an editing session at the document beginning with empty history and
/// default view, preferences and a yellow highlighter independent of document undo.
pub fn new(doc: Document) -> Self {
Self::with_registry(doc, Arc::new(crate::cmd::registry()))
}
/// Initialise session defaults while sharing the immutable command registry with previews.
pub(super) fn with_registry(doc: Document, registry: Arc<Registry>) -> Self {
let DocState {
doc,
sel,
view,
pending,
path,
file_name,
dirty,
pending_move,
find,
goal_x,
page_hint,
new_header_parts,
hf_return,
history,
undo_evicted,
redo,
typing_open,
join_next,
equation_join_next,
ime_text_join,
join_anchor,
autocap,
rev,
document_id,
untitled,
made_rev,
ime_body_epoch,
cache,
layout,
typing,
originals,
md_source,
md_file,
picture_looks,
versions,
autosave,
bib_style,
merge,
math,
password,
#[cfg(not(target_arch = "wasm32"))]
recovery_slot,
also_selected,
column,
column_mode,
widened,
edit_marks,
go_back_step,
} = DocState::new(doc, 1, ViewState::default());
Session {
doc,
sel,
view,
pending,
last_highlight: wordcraft_doc::props::Highlight::Yellow,
path,
file_name,
user_dict_path: None,
dirty,
clipboard: None,
pending_move,
clipboard_text: String::new(),
clipboard_html: String::new(),
clipboard_rtf: String::new(),
clip_history: Default::default(),
find,
goal_x,
page_hint,
registry,
author: "WordCraft User".into(),
initials: String::new(),
painter: None,
copied_format: None,
status: String::new(),
new_header_parts,
hf_return,
review_style: None,
history,
undo_evicted,
redo,
typing_open,
join_next,
equation_join_next,
ime_text_join,
join_anchor,
autocap,
rev,
document_id,
untitled,
made_rev,
protect_facts: std::sync::Mutex::new(None),
ime_body_epoch,
ime_state_revision: None,
ime_state_seen: None,
ime_edit_outcome: ImeEditOutcome::default(),
#[cfg(any(test, feature = "test-support"))]
ime_state_exhausted: false,
pending_ime_application_change: false,
ime_origin: false,
cache,
layout,
typing,
originals,
md_source,
md_file,
picture_looks,
last_command: None,
recording: None,
macros: Default::default(),
versions,
building_blocks: Default::default(),
autosave,
bib_style,
merge,
ui_requests: Vec::new(),
math,
math_latex: false,
math_normal_text: false,
also_selected,
member: None,
prefs: Prefs::default(),
system_region: Default::default(),
keymap: crate::KeyMap::default(),
ribbon: crate::RibbonLayout::default(),
editing_lang: None,
read_aloud: Default::default(),
windows: Default::default(),
password,
#[cfg(not(target_arch = "wasm32"))]
recovery: None,
#[cfg(not(target_arch = "wasm32"))]
recovery_slot,
column,
column_mode,
widened,
edit_marks,
go_back_step,
others: Vec::new(),
order: vec![document_id],
untitled_count: 1,
}
}
}