mirror of
https://github.com/storytold/wordcraft.git
synced 2026-10-19 02:10:15 -05:00
Co-authored-by: Brandon Thomas <echelon@gmail.com>
This commit is contained in:
1 parent
4fb9c2cb2a
commit
cad4138e7e
1 file changed
+22
-3
@@ -112,17 +112,29 @@ fn dispatch(app: &mut WordApp, key: Key, m: Modifiers) -> bool {
|
||||
let _ = app.run(spec.id, json!({}));
|
||||
return true;
|
||||
}
|
||||
// Shift extends caret movement.
|
||||
// Shift extends caret movement; Shift+Backspace still erases (#707).
|
||||
if m.shift
|
||||
&& let Some(spec) = app.session.keymap.resolve(®, &combo(m, name, false))
|
||||
&& spec.id.starts_with("caret.")
|
||||
&& let Some(params) = shift_variant_params(spec.id)
|
||||
{
|
||||
let _ = app.run(spec.id, json!({"extend": true}));
|
||||
let _ = app.run(spec.id, params);
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// How a command bound to a plain key runs when Shift is also held and nothing is bound to the
|
||||
/// shifted combo: caret moves extend the selection, Backspace erases as usual (#707).
|
||||
fn shift_variant_params(id: &str) -> Option<Value> {
|
||||
if id.starts_with("caret.") {
|
||||
Some(json!({"extend": true}))
|
||||
} else if id == "text.backspace" {
|
||||
Some(json!({}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// F1–F12: shortcuts on these work without the canvas focused.
|
||||
fn is_function_key(key: Key) -> bool {
|
||||
matches!(key, Key::F1 | Key::F2 | Key::F3 | Key::F4 | Key::F5 | Key::F6 | Key::F7 | Key::F8 | Key::F9 | Key::F10 | Key::F11 | Key::F12)
|
||||
@@ -322,6 +334,13 @@ pub fn global_shortcuts(app: &mut WordApp, ctx: &egui::Context) {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn shift_backspace_still_erases() {
|
||||
assert_eq!(shift_variant_params("text.backspace"), Some(json!({})));
|
||||
assert_eq!(shift_variant_params("caret.left"), Some(json!({"extend": true})));
|
||||
assert_eq!(shift_variant_params("text.delete"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_plain_paste_releases_paste_a_clipboard_picture() {
|
||||
let m = |command, shift, alt| egui::Modifiers { command, shift, alt, ..Default::default() };
|
||||
|
||||
Reference in new issue
Block a user