mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:08:12 +00:00
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.
This commit is contained in:
parent
a3520bfdfd
commit
27a30fdc2a
1 changed files with 36 additions and 0 deletions
|
@ -676,6 +676,24 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.key() == KeyCode::Key_Left) {
|
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) {
|
if (m_cursor.column() > 0) {
|
||||||
int new_column = m_cursor.column() - 1;
|
int new_column = m_cursor.column() - 1;
|
||||||
toggle_selection_if_needed_for_event(event);
|
toggle_selection_if_needed_for_event(event);
|
||||||
|
@ -697,6 +715,24 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.key() == KeyCode::Key_Right) {
|
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_line = m_cursor.line();
|
||||||
int new_column = m_cursor.column();
|
int new_column = m_cursor.column();
|
||||||
if (m_cursor.column() < current_line().length()) {
|
if (m_cursor.column() < current_line().length()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue