diff options
author | 2023-09-14 14:25:46 +0200 | |
---|---|---|
committer | 2023-09-14 14:25:46 +0200 | |
commit | edd591847599a3e47601646ce075cb5b71ea751b (patch) | |
tree | 37de29c5ee26efc35e1c530821e43f839909779b /graphics | |
parent | b24b94d82778733ddae1b824d0d7690afcec3056 (diff) | |
download | iced-edd591847599a3e47601646ce075cb5b71ea751b.tar.gz iced-edd591847599a3e47601646ce075cb5b71ea751b.tar.bz2 iced-edd591847599a3e47601646ce075cb5b71ea751b.zip |
Implement motion selection in `text::Editor`
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/src/text/editor.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/graphics/src/text/editor.rs b/graphics/src/text/editor.rs index d88bcd1d..c6b2abd5 100644 --- a/graphics/src/text/editor.rs +++ b/graphics/src/text/editor.rs @@ -254,7 +254,26 @@ impl editor::Editor for Editor { } // Selection events - Action::Select(_motion) => todo!(), + Action::Select(motion) => { + let cursor = editor.cursor(); + + if editor.select_opt().is_none() { + editor.set_select_opt(Some(cursor)); + } + + editor.action(font_system.raw(), motion_to_action(motion)); + + // Deselect if selection matches cursor position + if let Some(selection) = editor.select_opt() { + let cursor = editor.cursor(); + + if cursor.line == selection.line + && cursor.index == selection.index + { + editor.set_select_opt(None); + } + } + } Action::SelectWord => todo!(), Action::SelectLine => todo!(), |