Move cursor motions to new Motion enum, move handling to Buffer

This commit is contained in:
Jeremy Soller 2023-12-15 09:13:14 -07:00
parent 6528e9f804
commit 018a2e9d2a
10 changed files with 567 additions and 505 deletions

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
use cosmic_text::{
Action, Attrs, Buffer, Edit, Family, FontSystem, Metrics, SwashCache, SyntaxEditor,
Action, Attrs, Buffer, Edit, Family, FontSystem, Metrics, Motion, SwashCache, SyntaxEditor,
SyntaxSystem,
};
use orbclient::{EventOption, Renderer, Window, WindowFlag};
@ -147,14 +147,26 @@ fn main() {
match event.to_option() {
EventOption::Key(event) => match event.scancode {
orbclient::K_CTRL => ctrl_pressed = event.pressed,
orbclient::K_LEFT if event.pressed => editor.action(Action::Left),
orbclient::K_RIGHT if event.pressed => editor.action(Action::Right),
orbclient::K_UP if event.pressed => editor.action(Action::Up),
orbclient::K_DOWN if event.pressed => editor.action(Action::Down),
orbclient::K_HOME if event.pressed => editor.action(Action::Home),
orbclient::K_END if event.pressed => editor.action(Action::End),
orbclient::K_PGUP if event.pressed => editor.action(Action::PageUp),
orbclient::K_PGDN if event.pressed => editor.action(Action::PageDown),
orbclient::K_LEFT if event.pressed => {
editor.action(Action::Motion(Motion::Left))
}
orbclient::K_RIGHT if event.pressed => {
editor.action(Action::Motion(Motion::Right))
}
orbclient::K_UP if event.pressed => editor.action(Action::Motion(Motion::Up)),
orbclient::K_DOWN if event.pressed => {
editor.action(Action::Motion(Motion::Down))
}
orbclient::K_HOME if event.pressed => {
editor.action(Action::Motion(Motion::Home))
}
orbclient::K_END if event.pressed => editor.action(Action::Motion(Motion::End)),
orbclient::K_PGUP if event.pressed => {
editor.action(Action::Motion(Motion::PageUp))
}
orbclient::K_PGDN if event.pressed => {
editor.action(Action::Motion(Motion::PageDown))
}
orbclient::K_ESC if event.pressed => editor.action(Action::Escape),
orbclient::K_ENTER if event.pressed => editor.action(Action::Enter),
orbclient::K_BKSP if event.pressed => editor.action(Action::Backspace),