aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/TextBox.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/FbTk/TextBox.cc b/src/FbTk/TextBox.cc
index dcd51a7..a83347d 100644
--- a/src/FbTk/TextBox.cc
+++ b/src/FbTk/TextBox.cc
@@ -123,6 +123,18 @@ void TextBox::cursorEnd() {
123void TextBox::cursorForward() { 123void TextBox::cursorForward() {
124 StringRange r = charRange(m_start_pos + cursorPosition()); 124 StringRange r = charRange(m_start_pos + cursorPosition());
125 const std::string::size_type s = r.end - r.begin + 1; 125 const std::string::size_type s = r.end - r.begin + 1;
126
127 if (hasSelection()) {
128 int start = std::max(m_start_pos, std::min(m_start_pos + m_cursor_pos, m_select_pos));
129 int select_length = std::max(m_start_pos + m_cursor_pos, m_select_pos) - start;
130 if (select_length > static_cast<signed>(m_end_pos - m_start_pos)) {
131 // shift range
132 m_start_pos += s;
133 m_end_pos += s;
134 adjustPos();
135 }
136 }
137
126 if (r.end < m_end_pos) 138 if (r.end < m_end_pos)
127 m_cursor_pos = r.end + 1 - m_start_pos; 139 m_cursor_pos = r.end + 1 - m_start_pos;
128 else if (m_end_pos < text().size()) { 140 else if (m_end_pos < text().size()) {
@@ -133,9 +145,22 @@ void TextBox::cursorForward() {
133} 145}
134 146
135void TextBox::cursorBackward() { 147void TextBox::cursorBackward() {
148
149 StringRange r = charRange(m_start_pos + cursorPosition() - 1);
150 const std::string::size_type s = r.end - r.begin + 1;
151
152 if (hasSelection()) {
153 int end = std::max(m_end_pos, std::min(m_end_pos - m_cursor_pos, m_select_pos));
154 int select_length = end - std::min(m_end_pos - m_cursor_pos, m_select_pos);
155 if (select_length > static_cast<signed>(m_end_pos - m_start_pos)) {
156 // shift range
157 m_start_pos -= s;
158 m_end_pos -= s;
159 adjustPos();
160 }
161 }
162
136 if (m_start_pos || cursorPosition()) { 163 if (m_start_pos || cursorPosition()) {
137 StringRange r = charRange(m_start_pos + cursorPosition() - 1);
138 const std::string::size_type s = r.end - r.begin + 1;
139 if (cursorPosition()) 164 if (cursorPosition())
140 m_cursor_pos = r.begin - m_start_pos; 165 m_cursor_pos = r.begin - m_start_pos;
141 else if (m_start_pos) { 166 else if (m_start_pos) {