summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-26 13:57:51 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-26 14:02:39 +0200
commit4fa8acf6eae67583b36a9025a27c7ebd0c8cec43 (patch)
treeab32aca28358be4c10d48cc3326a6fd64ef419e9 /Libraries
parent532001f4c19527bc02c81706b6c49ec5f5afb191 (diff)
downloadserenity-4fa8acf6eae67583b36a9025a27c7ebd0c8cec43.zip
GTextEditor: The Home key should jump to the first non-space character
Press Home twice to get to column 0. This feels way more natural.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/GTextEditor.cpp15
-rw-r--r--Libraries/LibGUI/GTextEditor.h1
2 files changed, 15 insertions, 1 deletions
diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp
index 7a08125f5e..f4caf54fe7 100644
--- a/Libraries/LibGUI/GTextEditor.cpp
+++ b/Libraries/LibGUI/GTextEditor.cpp
@@ -568,8 +568,12 @@ void GTextEditor::keydown_event(GKeyEvent& event)
return;
}
if (!event.ctrl() && event.key() == KeyCode::Key_Home) {
+ int first_nonspace_column = current_line().first_non_whitespace_column();
toggle_selection_if_needed_for_event(event);
- set_cursor(m_cursor.line(), 0);
+ if (m_cursor.column() == first_nonspace_column)
+ set_cursor(m_cursor.line(), 0);
+ else
+ set_cursor(m_cursor.line(), first_nonspace_column);
if (event.shift() && m_selection.start().is_valid()) {
m_selection.set_end(m_cursor);
did_update_selection();
@@ -1447,6 +1451,15 @@ int GTextEditor::Line::visual_line_containing(int column) const
return visual_line_index;
}
+int GTextEditor::Line::first_non_whitespace_column() const
+{
+ for (int i = 0; i < length(); ++i) {
+ if (!isspace(m_text[i]))
+ return i;
+ }
+ return length();
+}
+
void GTextEditor::add_custom_context_menu_action(GAction& action)
{
m_custom_context_menu_actions.append(action);
diff --git a/Libraries/LibGUI/GTextEditor.h b/Libraries/LibGUI/GTextEditor.h
index 80e1cd5beb..f15437667f 100644
--- a/Libraries/LibGUI/GTextEditor.h
+++ b/Libraries/LibGUI/GTextEditor.h
@@ -233,6 +233,7 @@ private:
void clear();
void recompute_visual_lines();
int visual_line_containing(int column) const;
+ int first_non_whitespace_column() const;
template<typename Callback>
void for_each_visual_line(Callback) const;