Skip to content

Commit

Permalink
Add Ctrl + ArrowUp/Down hotkeys to textinput
Browse files Browse the repository at this point in the history
+ very minor refactoring (two unnecessary let bindings) in editable_text
  • Loading branch information
Valentin Kahl committed Jul 18, 2020
1 parent 7c70761 commit da1ca5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
6 changes: 2 additions & 4 deletions druid/src/text/editable_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ impl EditableText for String {
let mut offset = from;
let mut passed_alphanumeric = false;
for prev_grapheme in self.get(0..from)?.graphemes(true).rev() {
let is_alphanumeric = prev_grapheme.chars().next()?.is_alphanumeric();
if is_alphanumeric {
if prev_grapheme.chars().next()?.is_alphanumeric() {
passed_alphanumeric = true;
} else if passed_alphanumeric {
return Some(offset);
Expand All @@ -136,8 +135,7 @@ impl EditableText for String {
let mut offset = from;
let mut passed_alphanumeric = false;
for next_grapheme in self.get(from..)?.graphemes(true) {
let is_alphanumeric = next_grapheme.chars().next()?.is_alphanumeric();
if is_alphanumeric {
if next_grapheme.chars().next()?.is_alphanumeric() {
passed_alphanumeric = true;
} else if passed_alphanumeric {
return Some(offset);
Expand Down
26 changes: 18 additions & 8 deletions druid/src/text/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ impl TextInput for BasicTextInput {
k_e if (HotKey::new(SysMods::CmdShift, KbKey::ArrowRight)).matches(k_e) => {
EditAction::ModifySelection(Movement::RightWord)
}
// Select to home (Shift+Home)
k_e if (HotKey::new(SysMods::Shift, KbKey::Home)).matches(k_e) => {
// Select to home (Shift+Home || Shift+ArrowUp || Shift+Ctrl+ArrowUp || Shift+Cmd+ArrowUp)
k_e if (HotKey::new(SysMods::Shift, KbKey::Home)).matches(k_e)
|| (HotKey::new(SysMods::Shift, KbKey::ArrowUp)).matches(k_e)
|| (HotKey::new(SysMods::CmdShift, KbKey::ArrowUp)).matches(k_e) =>
{
EditAction::ModifySelection(Movement::LeftOfLine)
}
// Select to end (Shift+End)
k_e if (HotKey::new(SysMods::Shift, KbKey::End)).matches(k_e) => {
// Select to end (Shift+End || Shift+ArrowDown || Shift+Ctrl+ArrowDown || Shift+Cmd+ArrowDown)
k_e if (HotKey::new(SysMods::Shift, KbKey::End)).matches(k_e)
|| (HotKey::new(SysMods::Shift, KbKey::ArrowDown)).matches(k_e)
|| (HotKey::new(SysMods::CmdShift, KbKey::ArrowDown)).matches(k_e) =>
{
EditAction::ModifySelection(Movement::RightOfLine)
}
// Select left (Shift+ArrowLeft)
Expand Down Expand Up @@ -120,12 +126,16 @@ impl TextInput for BasicTextInput {
k_e if (HotKey::new(None, KbKey::Backspace)).matches(k_e) => EditAction::Backspace,
// Delete
k_e if (HotKey::new(None, KbKey::Delete)).matches(k_e) => EditAction::Delete,
// Home
k_e if (HotKey::new(None, KbKey::Home)).matches(k_e) => {
// Move to home (Home || Ctrl+ArrowUp || Cmd+ArrowUp)
k_e if (HotKey::new(None, KbKey::Home)).matches(k_e)
|| (HotKey::new(SysMods::Cmd, KbKey::ArrowUp)).matches(k_e) =>
{
EditAction::Move(Movement::LeftOfLine)
}
// End
k_e if (HotKey::new(None, KbKey::End)).matches(k_e) => {
// Move to end (End || Ctrl+ArrowDown || Cmd+ArrowDown)
k_e if (HotKey::new(None, KbKey::End)).matches(k_e)
|| (HotKey::new(SysMods::Cmd, KbKey::ArrowDown)).matches(k_e) =>
{
EditAction::Move(Movement::RightOfLine)
}
// Actual typing
Expand Down

0 comments on commit da1ca5b

Please sign in to comment.