Skip to content

Commit

Permalink
Improve simulate_input (#1786)
Browse files Browse the repository at this point in the history
Various common operations were not implemented.
Page up and down now correlate with page up and down movement. Home and
End now either move to the start and end of the line or to the start and
the end of the document respectively based on whether control is held.
  • Loading branch information
CryZe authored May 20, 2021
1 parent 8587c9f commit 7afd02d
Showing 1 changed file with 62 additions and 4 deletions.
66 changes: 62 additions & 4 deletions druid-shell/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,23 @@ pub fn simulate_input<H: WinHandler + ?Sized>(
input_handler.set_selection(Selection::caret(new_caret_index));
}
KbKey::ArrowLeft => {
let movement = Movement::Grapheme(Direction::Left);
let movement = if event.mods.ctrl() {
Movement::Word(Direction::Left)
} else {
Movement::Grapheme(Direction::Left)
};
if event.mods.shift() {
input_handler.handle_action(Action::MoveSelecting(movement));
} else {
input_handler.handle_action(Action::Move(movement));
}
}
KbKey::ArrowRight => {
let movement = Movement::Grapheme(Direction::Right);
let movement = if event.mods.ctrl() {
Movement::Word(Direction::Right)
} else {
Movement::Grapheme(Direction::Right)
};
if event.mods.shift() {
input_handler.handle_action(Action::MoveSelecting(movement));
} else {
Expand All @@ -509,10 +517,20 @@ pub fn simulate_input<H: WinHandler + ?Sized>(
}
}
KbKey::Backspace => {
input_handler.handle_action(Action::Delete(Movement::Grapheme(Direction::Upstream)));
let movement = if event.mods.ctrl() {
Movement::Word(Direction::Upstream)
} else {
Movement::Grapheme(Direction::Upstream)
};
input_handler.handle_action(Action::Delete(movement));
}
KbKey::Delete => {
input_handler.handle_action(Action::Delete(Movement::Grapheme(Direction::Downstream)));
let movement = if event.mods.ctrl() {
Movement::Word(Direction::Downstream)
} else {
Movement::Grapheme(Direction::Downstream)
};
input_handler.handle_action(Action::Delete(movement));
}
KbKey::Enter => {
// I'm sorry windows, you'll get IME soon.
Expand All @@ -531,6 +549,46 @@ pub fn simulate_input<H: WinHandler + ?Sized>(
};
input_handler.handle_action(action);
}
KbKey::Home => {
let movement = if event.mods.ctrl() {
Movement::Vertical(VerticalMovement::DocumentStart)
} else {
Movement::Line(Direction::Upstream)
};
if event.mods.shift() {
input_handler.handle_action(Action::MoveSelecting(movement));
} else {
input_handler.handle_action(Action::Move(movement));
}
}
KbKey::End => {
let movement = if event.mods.ctrl() {
Movement::Vertical(VerticalMovement::DocumentEnd)
} else {
Movement::Line(Direction::Downstream)
};
if event.mods.shift() {
input_handler.handle_action(Action::MoveSelecting(movement));
} else {
input_handler.handle_action(Action::Move(movement));
}
}
KbKey::PageUp => {
let movement = Movement::Vertical(VerticalMovement::PageUp);
if event.mods.shift() {
input_handler.handle_action(Action::MoveSelecting(movement));
} else {
input_handler.handle_action(Action::Move(movement));
}
}
KbKey::PageDown => {
let movement = Movement::Vertical(VerticalMovement::PageDown);
if event.mods.shift() {
input_handler.handle_action(Action::MoveSelecting(movement));
} else {
input_handler.handle_action(Action::Move(movement));
}
}
_ => {
handler.release_input_lock(token);
return false;
Expand Down

0 comments on commit 7afd02d

Please sign in to comment.