aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-12-13 21:05:29 +0800
committercrupest <crupest@outlook.com>2021-12-13 21:05:29 +0800
commit419a09298abcba851313c2160cc00e24b48850fc (patch)
tree1a48d78a26c7ee3a293c36c959da6ac8cea4db03
parent21fccf43ec049569f690674840ca1a10420a40da (diff)
downloadcru-419a09298abcba851313c2160cc00e24b48850fc.tar.gz
cru-419a09298abcba851313c2160cc00e24b48850fc.tar.bz2
cru-419a09298abcba851313c2160cc00e24b48850fc.zip
...
-rw-r--r--include/cru/ui/controls/TextHostControlService.hpp8
-rw-r--r--src/ui/controls/TextHostControlService.cpp41
2 files changed, 30 insertions, 19 deletions
diff --git a/include/cru/ui/controls/TextHostControlService.hpp b/include/cru/ui/controls/TextHostControlService.hpp
index 1bdf0509..7c0fbcda 100644
--- a/include/cru/ui/controls/TextHostControlService.hpp
+++ b/include/cru/ui/controls/TextHostControlService.hpp
@@ -51,9 +51,11 @@ class TextControlMovePattern : public Object {
std::function<gsl::index(TextHostControlService* service, StringView text,
gsl::index current_position)>;
- TextControlMovePattern(helper::ShortcutKeyBind key_bind,
+ TextControlMovePattern(String name, helper::ShortcutKeyBind key_bind,
MoveFunction move_function)
- : key_bind_(key_bind), move_function_(move_function) {}
+ : name_(std::move(name)),
+ key_bind_(key_bind),
+ move_function_(move_function) {}
CRU_DEFAULT_COPY(TextControlMovePattern)
CRU_DEFAULT_MOVE(TextControlMovePattern)
@@ -61,6 +63,7 @@ class TextControlMovePattern : public Object {
~TextControlMovePattern() override = default;
public:
+ String GetName() const { return name_; }
helper::ShortcutKeyBind GetKeyBind() const { return key_bind_; }
gsl::index Move(TextHostControlService* service, StringView text,
gsl::index current_position) const {
@@ -68,6 +71,7 @@ class TextControlMovePattern : public Object {
}
private:
+ String name_;
helper::ShortcutKeyBind key_bind_;
MoveFunction move_function_;
};
diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp
index 3a67860d..bdb198d9 100644
--- a/src/ui/controls/TextHostControlService.cpp
+++ b/src/ui/controls/TextHostControlService.cpp
@@ -25,20 +25,21 @@
namespace cru::ui::controls {
TextControlMovePattern TextControlMovePattern::kLeft(
- helper::ShortcutKeyBind(platform::gui::KeyCode::Left),
+ u"Left", helper::ShortcutKeyBind(platform::gui::KeyCode::Left),
[](TextHostControlService* service, StringView text,
gsl::index current_position) {
Utf16PreviousCodePoint(text, current_position, &current_position);
return current_position;
});
TextControlMovePattern TextControlMovePattern::kRight(
- helper::ShortcutKeyBind(platform::gui::KeyCode::Right),
+ u"Right", helper::ShortcutKeyBind(platform::gui::KeyCode::Right),
[](TextHostControlService* service, StringView text,
gsl::index current_position) {
Utf16NextCodePoint(text, current_position, &current_position);
return current_position;
});
TextControlMovePattern TextControlMovePattern::kCtrlLeft(
+ u"Ctrl+Left(Previous Word)",
helper::ShortcutKeyBind(platform::gui::KeyCode::Left,
platform::gui::KeyModifiers::ctrl),
[](TextHostControlService* service, StringView text,
@@ -46,6 +47,7 @@ TextControlMovePattern TextControlMovePattern::kCtrlLeft(
return Utf16PreviousWord(text, current_position);
});
TextControlMovePattern TextControlMovePattern::kCtrlRight(
+ u"Ctrl+Right(Next Word)",
helper::ShortcutKeyBind(platform::gui::KeyCode::Right,
platform::gui::KeyModifiers::ctrl),
[](TextHostControlService* service, StringView text,
@@ -53,7 +55,7 @@ TextControlMovePattern TextControlMovePattern::kCtrlRight(
return Utf16NextWord(text, current_position);
});
TextControlMovePattern TextControlMovePattern::kUp(
- helper::ShortcutKeyBind(platform::gui::KeyCode::Up),
+ u"Up", helper::ShortcutKeyBind(platform::gui::KeyCode::Up),
[](TextHostControlService* service, StringView text,
gsl::index current_position) {
auto text_render_object = service->GetTextRenderObject();
@@ -63,7 +65,7 @@ TextControlMovePattern TextControlMovePattern::kUp(
return result.trailing ? result.position + 1 : result.position;
});
TextControlMovePattern TextControlMovePattern::kDown(
- helper::ShortcutKeyBind(platform::gui::KeyCode::Down),
+ u"Down", helper::ShortcutKeyBind(platform::gui::KeyCode::Down),
[](TextHostControlService* service, StringView text,
gsl::index current_position) {
auto text_render_object = service->GetTextRenderObject();
@@ -73,38 +75,40 @@ TextControlMovePattern TextControlMovePattern::kDown(
return result.trailing ? result.position + 1 : result.position;
});
TextControlMovePattern TextControlMovePattern::kHome(
- helper::ShortcutKeyBind(platform::gui::KeyCode::Home),
+ u"Home(Line Begin)", helper::ShortcutKeyBind(platform::gui::KeyCode::Home),
[](TextHostControlService* service, StringView text,
gsl::index current_position) {
return Utf16BackwardUntil(text, current_position,
[](char16_t c) { return c == u'\n'; });
});
TextControlMovePattern TextControlMovePattern::kEnd(
- helper::ShortcutKeyBind(platform::gui::KeyCode::End),
+ u"End(Line End)", helper::ShortcutKeyBind(platform::gui::KeyCode::End),
[](TextHostControlService* service, StringView text,
gsl::index current_position) {
return Utf16ForwardUntil(text, current_position,
[](char16_t c) { return c == u'\n'; });
});
TextControlMovePattern TextControlMovePattern::kCtrlHome(
+ u"Ctrl+Home(Document Begin)",
helper::ShortcutKeyBind(platform::gui::KeyCode::Home,
platform::gui::KeyModifiers::ctrl),
[](TextHostControlService* service, StringView text,
gsl::index current_position) { return 0; });
TextControlMovePattern TextControlMovePattern::kCtrlEnd(
+ u"Ctrl+End(Document End)",
helper::ShortcutKeyBind(platform::gui::KeyCode::End,
platform::gui::KeyModifiers::ctrl),
[](TextHostControlService* service, StringView text,
gsl::index current_position) { return text.size(); });
TextControlMovePattern TextControlMovePattern::kPageUp(
- helper::ShortcutKeyBind(platform::gui::KeyCode::PageUp),
+ u"PageUp", helper::ShortcutKeyBind(platform::gui::KeyCode::PageUp),
[](TextHostControlService* service, StringView text,
gsl::index current_position) {
// TODO: Implement this.
return current_position;
});
TextControlMovePattern TextControlMovePattern::kPageDown(
- helper::ShortcutKeyBind(platform::gui::KeyCode::PageDown),
+ u"PageDown", helper::ShortcutKeyBind(platform::gui::KeyCode::PageDown),
[](TextHostControlService* service, StringView text,
gsl::index current_position) {
// TODO: Implement this.
@@ -461,7 +465,8 @@ void TextHostControlService::MouseDownHandler(
}
}
-void TextHostControlService::MouseUpHandler(events::MouseButtonEventArgs& args) {
+void TextHostControlService::MouseUpHandler(
+ events::MouseButtonEventArgs& args) {
if (args.GetButton() == mouse_buttons::left && mouse_move_selecting_) {
this->control_->ReleaseMouse();
this->mouse_move_selecting_ = false;
@@ -591,16 +596,18 @@ void TextHostControlService::SetUpShortcuts() {
});
for (const auto& pattern : TextControlMovePattern::kDefaultPatterns) {
- shortcut_hub_.RegisterShortcut(u"", pattern.GetKeyBind(), [this, &pattern] {
- auto text = this->GetTextView();
- auto caret = this->GetCaretPosition();
- auto new_position = pattern.Move(this, text, caret);
- this->SetSelection(new_position);
- return true;
- });
+ auto name = pattern.GetName();
+ shortcut_hub_.RegisterShortcut(
+ u"Move " + name, pattern.GetKeyBind(), [this, &pattern] {
+ auto text = this->GetTextView();
+ auto caret = this->GetCaretPosition();
+ auto new_position = pattern.Move(this, text, caret);
+ this->SetSelection(new_position);
+ return true;
+ });
shortcut_hub_.RegisterShortcut(
- u"",
+ u"Move And Select " + name,
pattern.GetKeyBind().AddModifier(platform::gui::KeyModifiers::shift),
[this, &pattern] {
auto text = this->GetTextView();