summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-07 16:49:04 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-07 16:49:21 +0100
commit43d56b6f3a45dd2f92f4fd7b1cf7a8bdf0cb57ba (patch)
tree65f48098d42fa4e1a304c22bb61d85bf2c460822 /LibGUI
parenta64b71fb3d47676981d7b58c5b356817960dc694 (diff)
downloadserenity-43d56b6f3a45dd2f92f4fd7b1cf7a8bdf0cb57ba.zip
GTextEditor: Support splitting lines at the cursor with the Return key.
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GTextEditor.cpp15
-rw-r--r--LibGUI/GTextEditor.h1
2 files changed, 15 insertions, 1 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp
index 720277347b..5e2b2f9dcb 100644
--- a/LibGUI/GTextEditor.cpp
+++ b/LibGUI/GTextEditor.cpp
@@ -240,10 +240,17 @@ void GTextEditor::insert_at_cursor(char ch)
if (at_tail || at_head) {
m_lines.insert(m_cursor.line() + (at_tail ? 1 : 0), make<Line>());
update_scrollbar_ranges();
- set_cursor(m_cursor.line() + 1, 0);
update();
+ set_cursor(m_cursor.line() + 1, 0);
return;
}
+ auto new_line = make<Line>();
+ new_line->append(current_line().characters() + m_cursor.column(), current_line().length() - m_cursor.column());
+ current_line().truncate(m_cursor.column());
+ m_lines.insert(m_cursor.line() + 1, move(new_line));
+ update_scrollbar_ranges();
+ update();
+ set_cursor(m_cursor.line() + 1, 0);
return;
}
current_line().insert(m_cursor.column(), ch);
@@ -414,3 +421,9 @@ void GTextEditor::Line::remove(int index)
m_text.remove(index);
}
}
+
+void GTextEditor::Line::truncate(int length)
+{
+ m_text.resize(length + 1);
+ m_text.last() = 0;
+}
diff --git a/LibGUI/GTextEditor.h b/LibGUI/GTextEditor.h
index 5964df624b..1c905512b2 100644
--- a/LibGUI/GTextEditor.h
+++ b/LibGUI/GTextEditor.h
@@ -73,6 +73,7 @@ private:
void insert(int index, char);
void remove(int index);
void append(const char*, int);
+ void truncate(int length);
private:
// NOTE: This vector is null terminated.