diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2019-04-28 17:51:47 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2019-04-28 17:51:47 +0200 |
commit | b0956915c9607c7ea1cfd19108c6889e7cf9fc79 (patch) | |
tree | 02e5c02d5ffb35cb640bef9b3639917834a99fca /scene/gui/text_edit.cpp | |
parent | 2931b4db5145d17da46caee1ccf4322939751707 (diff) |
macOS: make Command + Left go to first non-whitespace character
Instead of going to column 0. This matches the behaviour of other
popular IDEs.
Fixes #28462.
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r-- | scene/gui/text_edit.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 1f498ea16e..b5af27e16e 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2588,9 +2588,22 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { #ifdef APPLE_STYLE_KEYS if (k->get_command()) { - cursor_set_column(0); + // Start at first column (it's slightly faster that way) and look for the first non-whitespace character. + int new_cursor_pos = 0; + for (int i = 0; i < text[cursor.line].length(); ++i) { + if (!_is_whitespace(text[cursor.line][i])) { + new_cursor_pos = i; + break; + } + } + if (new_cursor_pos == cursor.column) { + // We're already at the first text character, so move to the very beginning of the line. + cursor_set_column(0); + } else { + // We're somewhere to the right of the first text character; move to the first one. + cursor_set_column(new_cursor_pos); + } } else if (k->get_alt()) { - #else if (k->get_alt()) { scancode_handled = false; |