Implement motion selection in text::Editor

This commit is contained in:
Héctor Ramón Jiménez 2023-09-14 14:25:46 +02:00
parent b24b94d827
commit edd5918475
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -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!(),