summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-15 20:17:49 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-15 21:02:24 +0100
commit27a30fdc2af021142e1a641dc8e5352cb674741f (patch)
tree7f333622a7dfeb357bccdef125d04f47c82f7fe2 /Libraries
parenta3520bfdfd22dc5af998901e3d7c7207b8af5412 (diff)
downloadserenity-27a30fdc2af021142e1a641dc8e5352cb674741f.zip
GTextEditor: Allow moving the cursor span-wise with Ctrl+Left/Right
This allows you to move token by token when using HackStudio to edit a C++ file. Fixes #767.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/GTextEditor.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp
index f972fbac34..39983062d2 100644
--- a/Libraries/LibGUI/GTextEditor.cpp
+++ b/Libraries/LibGUI/GTextEditor.cpp
@@ -676,6 +676,24 @@ void GTextEditor::keydown_event(GKeyEvent& event)
return;
}
if (event.key() == KeyCode::Key_Left) {
+ if (event.ctrl() && document().has_spans()) {
+ // FIXME: Do something nice when the document has no spans.
+ for (int i = 0; i < document().spans().size(); ++i) {
+ if (!document().spans()[i].range.contains(m_cursor))
+ continue;
+ GTextPosition new_cursor = i == 0
+ ? GTextPosition(0, 0)
+ : document().spans()[i - 1].range.start();
+ toggle_selection_if_needed_for_event(event);
+ set_cursor(new_cursor);
+ if (event.shift() && m_selection.start().is_valid()) {
+ m_selection.set_end(m_cursor);
+ did_update_selection();
+ }
+ break;
+ }
+ return;
+ }
if (m_cursor.column() > 0) {
int new_column = m_cursor.column() - 1;
toggle_selection_if_needed_for_event(event);
@@ -697,6 +715,24 @@ void GTextEditor::keydown_event(GKeyEvent& event)
return;
}
if (event.key() == KeyCode::Key_Right) {
+ if (event.ctrl() && document().has_spans()) {
+ // FIXME: Do something nice when the document has no spans.
+ for (int i = 0; i < document().spans().size(); ++i) {
+ if (!document().spans()[i].range.contains(m_cursor))
+ continue;
+ GTextPosition new_cursor = i == (document().spans().size() - 1)
+ ? document().spans().last().range.end()
+ : document().spans()[i + 1].range.start();
+ toggle_selection_if_needed_for_event(event);
+ set_cursor(new_cursor);
+ if (event.shift() && m_selection.start().is_valid()) {
+ m_selection.set_end(m_cursor);
+ did_update_selection();
+ }
+ break;
+ }
+ return;
+ }
int new_line = m_cursor.line();
int new_column = m_cursor.column();
if (m_cursor.column() < current_line().length()) {