diff options
author | crupest <crupest@outlook.com> | 2020-12-28 21:23:04 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-12-28 21:23:04 +0800 |
commit | fb280cc30e1012e18b47e43f783ddd4b33bf9d1c (patch) | |
tree | 75ccb1a6830604cc8b6483012b47dba772cebde9 /src/ui/controls | |
parent | 6523ba8e0f2830f3cd4434d8331882077be3f82c (diff) | |
download | cru-fb280cc30e1012e18b47e43f783ddd4b33bf9d1c.tar.gz cru-fb280cc30e1012e18b47e43f783ddd4b33bf9d1c.tar.bz2 cru-fb280cc30e1012e18b47e43f783ddd4b33bf9d1c.zip |
...
Diffstat (limited to 'src/ui/controls')
-rw-r--r-- | src/ui/controls/TextHostControlService.cpp | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index 4bfd6715..502f63f9 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -401,57 +401,69 @@ void TextHostControlService::SetUpShortcuts() { shortcut_hub_.RegisterShortcut(u"Left", KeyCode::Left, [this] { auto text = this->GetTextView(); - const auto caret = this->GetCaretPosition(); - gsl::index new_position; - Utf16PreviousCodePoint(text, caret, &new_position); - this->SetSelection(new_position); + auto caret = this->GetCaretPosition(); + Utf16PreviousCodePoint(text, caret, &caret); + this->SetSelection(caret); return true; }); + shortcut_hub_.RegisterShortcut(u"ShiftLeft", + {KeyCode::Left, KeyModifiers::shift}, [this] { + auto text = this->GetTextView(); + auto caret = this->GetCaretPosition(); + Utf16PreviousCodePoint(text, caret, &caret); + this->ChangeSelectionEnd(caret); + return true; + }); + shortcut_hub_.RegisterShortcut( - u"ShiftLeft", {KeyCode::Left, KeyModifiers::shift}, [this] { + u"CtrlLeft", {KeyCode::Left, KeyModifiers::ctrl}, [this] { auto text = this->GetTextView(); - auto selection = this->GetSelection(); - gsl::index new_position; - Utf16PreviousCodePoint(text, selection.GetEnd(), &new_position); - selection.ChangeEnd(new_position); - this->SetSelection(selection); + auto caret = this->GetCaretPosition(); + this->SetSelection(Utf16PreviousWord(text, caret)); return true; }); shortcut_hub_.RegisterShortcut( - u"CtrlLeft", {KeyCode::Left, KeyModifiers::ctrl}, [this] { + u"CtrlShiftLeft", + {KeyCode::Left, KeyModifiers::ctrl | KeyModifiers::shift}, [this] { auto text = this->GetTextView(); auto caret = this->GetCaretPosition(); - this->SetSelection(Utf16PreviousWord(text, caret)); + this->ChangeSelectionEnd(Utf16PreviousWord(text, caret)); return true; }); shortcut_hub_.RegisterShortcut(u"Right", KeyCode::Right, [this] { auto text = this->GetTextView(); - const auto caret = this->GetCaretPosition(); - gsl::index new_position; - Utf16NextCodePoint(text, caret, &new_position); - this->SetSelection(new_position); + auto caret = this->GetCaretPosition(); + Utf16NextCodePoint(text, caret, &caret); + this->SetSelection(caret); return true; }); + shortcut_hub_.RegisterShortcut(u"ShiftRight", + {KeyCode::Right, KeyModifiers::shift}, [this] { + auto text = this->GetTextView(); + auto caret = this->GetCaretPosition(); + Utf16NextCodePoint(text, caret, &caret); + this->ChangeSelectionEnd(caret); + return true; + }); + shortcut_hub_.RegisterShortcut( - u"ShiftRight", {KeyCode::Right, KeyModifiers::shift}, [this] { + u"CtrlRight", {KeyCode::Right, KeyModifiers::ctrl}, [this] { auto text = this->GetTextView(); - auto selection = this->GetSelection(); - gsl::index new_position; - Utf16NextCodePoint(text, selection.GetEnd(), &new_position); - selection.ChangeEnd(new_position); - this->SetSelection(selection); + auto caret = this->GetCaretPosition(); + this->SetSelection(Utf16NextWord(text, caret)); return true; }); shortcut_hub_.RegisterShortcut( - u"CtrlRight", {KeyCode::Right, KeyModifiers::ctrl}, [this] { + u"CtrlShiftRight", + {KeyCode::Right, KeyModifiers::ctrl | KeyModifiers::shift}, [this] { auto text = this->GetTextView(); auto caret = this->GetCaretPosition(); - this->SetSelection(Utf16NextWord(text, caret)); + this->ChangeSelectionEnd(Utf16NextWord(text, caret)); return true; }); } |