mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-06 02:22:13 +00:00
Paste pictures: Mod+Shift+V (Paste Formatting) no longer pastes a clipboard picture
The key-release fallback that pastes the system clipboard's picture treated every Mod+V release as Paste. It now requires plain Mod+V or the Paste key (no Shift, no Alt), with a unit test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7e83021859
commit
306534ea01
1 file changed
+23
-1
@@ -133,6 +133,13 @@ fn equation_key(app: &mut WordApp, key: Key, m: Modifiers) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Whether releasing `key` with `modifiers` is the plain Paste shortcut (Mod+V or the Paste
|
||||
/// key) — not Mod+Shift+V (Paste Formatting) or Mod+Alt+V (Paste Special) — so a clipboard
|
||||
/// picture may be pasted on it (#45).
|
||||
fn is_paste_release(key: Key, modifiers: egui::Modifiers) -> bool {
|
||||
(modifiers.command || key == Key::Paste) && !modifiers.alt && !modifiers.shift
|
||||
}
|
||||
|
||||
/// Events for the focused canvas: text, editing keys, clipboard, IME. While keytips are showing
|
||||
/// every key belongs to them (letters pick badges, Escape cancels), so nothing here runs.
|
||||
pub fn canvas_events(app: &mut WordApp, ctx: &egui::Context) {
|
||||
@@ -152,7 +159,7 @@ pub fn canvas_events(app: &mut WordApp, ctx: &egui::Context) {
|
||||
// release; paste the clipboard's picture then (#45). A paste event before the release
|
||||
// means it was text. (The web reads pasted pictures itself.)
|
||||
if let egui::Event::Key { key: key @ (Key::V | Key::Paste), pressed: false, modifiers, .. } = &e {
|
||||
let paste_keys = (modifiers.command || *key == Key::Paste) && !modifiers.alt;
|
||||
let paste_keys = is_paste_release(*key, *modifiers);
|
||||
let pasted = std::mem::take(&mut app.canvas.pasted);
|
||||
if !pasted && paste_keys && app.session.math.is_none() && app.services.clipboard_picture.is_some() {
|
||||
let _ = app.run("edit.paste", json!({}));
|
||||
@@ -265,3 +272,18 @@ pub fn global_shortcuts(app: &mut WordApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn only_plain_paste_releases_paste_a_clipboard_picture() {
|
||||
let m = |command, shift, alt| egui::Modifiers { command, shift, alt, ..Default::default() };
|
||||
assert!(is_paste_release(Key::V, m(true, false, false)), "Mod+V");
|
||||
assert!(is_paste_release(Key::Paste, m(false, false, false)), "the Paste key");
|
||||
assert!(!is_paste_release(Key::V, m(true, true, false)), "Mod+Shift+V is Paste Formatting");
|
||||
assert!(!is_paste_release(Key::V, m(true, false, true)), "Mod+Alt+V is Paste Special");
|
||||
assert!(!is_paste_release(Key::V, m(false, false, false)), "a plain V");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user