From fb280cc30e1012e18b47e43f783ddd4b33bf9d1c Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 28 Dec 2020 21:23:04 +0800 Subject: ... --- src/ui/controls/TextHostControlService.cpp | 60 ++++++++++++++++++------------ 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'src/ui/controls') 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; }); } -- cgit v1.2.3