diff options
Diffstat (limited to 'src/FbTk/TextBox.cc')
-rw-r--r-- | src/FbTk/TextBox.cc | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/FbTk/TextBox.cc b/src/FbTk/TextBox.cc index a912775..7c91621 100644 --- a/src/FbTk/TextBox.cc +++ b/src/FbTk/TextBox.cc | |||
@@ -247,21 +247,25 @@ void TextBox::keyPressEvent(XKeyEvent &event) { | |||
247 | m_end_pos = 0; | 247 | m_end_pos = 0; |
248 | break; | 248 | break; |
249 | case XK_Left: { | 249 | case XK_Left: { |
250 | int pos = findEmptySpaceLeft(); | 250 | unsigned int pos = findEmptySpaceLeft(); |
251 | if (pos < m_start_pos){ | 251 | if (pos < m_start_pos){ |
252 | m_start_pos = pos; | 252 | m_start_pos = pos; |
253 | m_cursor_pos = 0; | 253 | m_cursor_pos = 0; |
254 | } else if (m_start_pos > 0) { | 254 | } else if (m_start_pos > 0) { |
255 | m_cursor_pos = pos - m_start_pos; | 255 | m_cursor_pos = pos - m_start_pos; |
256 | } else { | 256 | } else { |
257 | m_cursor_pos = pos; | 257 | m_cursor_pos = pos; |
258 | } | ||
259 | adjustPos(); | ||
260 | } | 258 | } |
259 | adjustPos(); | ||
260 | } | ||
261 | break; | 261 | break; |
262 | case XK_Right: | 262 | case XK_Right: |
263 | if (m_text.size() && m_cursor_pos < m_text.size()){ | 263 | if (m_text.size() && m_cursor_pos < m_text.size()){ |
264 | int pos = findEmptySpaceRight() - m_start_pos; | 264 | unsigned int pos = findEmptySpaceRight(); |
265 | if (pos > m_start_pos) | ||
266 | pos -= m_start_pos; | ||
267 | else | ||
268 | pos = 0; | ||
265 | if (m_start_pos + pos <= m_end_pos) | 269 | if (m_start_pos + pos <= m_end_pos) |
266 | m_cursor_pos = pos; | 270 | m_cursor_pos = pos; |
267 | else if (m_end_pos < text().size()) { | 271 | else if (m_end_pos < text().size()) { |
@@ -275,7 +279,7 @@ void TextBox::keyPressEvent(XKeyEvent &event) { | |||
275 | break; | 279 | break; |
276 | 280 | ||
277 | case XK_BackSpace: { | 281 | case XK_BackSpace: { |
278 | int pos = findEmptySpaceLeft(); | 282 | unsigned int pos = findEmptySpaceLeft(); |
279 | m_text.erase(pos, m_cursor_pos - pos + m_start_pos); | 283 | m_text.erase(pos, m_cursor_pos - pos + m_start_pos); |
280 | 284 | ||
281 | if (pos < m_start_pos){ | 285 | if (pos < m_start_pos){ |
@@ -292,7 +296,7 @@ void TextBox::keyPressEvent(XKeyEvent &event) { | |||
292 | case XK_Delete: { | 296 | case XK_Delete: { |
293 | if (!m_text.size() || m_cursor_pos >= m_text.size()) | 297 | if (!m_text.size() || m_cursor_pos >= m_text.size()) |
294 | break; | 298 | break; |
295 | int pos = findEmptySpaceRight(); | 299 | unsigned int pos = findEmptySpaceRight(); |
296 | m_text.erase(m_cursor_pos + m_start_pos, pos - (m_cursor_pos + m_start_pos)); | 300 | m_text.erase(m_cursor_pos + m_start_pos, pos - (m_cursor_pos + m_start_pos)); |
297 | adjustPos(); | 301 | adjustPos(); |
298 | } | 302 | } |
@@ -406,7 +410,7 @@ void TextBox::adjustStartPos() { | |||
406 | m_start_pos = start_pos; | 410 | m_start_pos = start_pos; |
407 | } | 411 | } |
408 | 412 | ||
409 | int TextBox::findEmptySpaceLeft(){ | 413 | unsigned int TextBox::findEmptySpaceLeft(){ |
410 | 414 | ||
411 | // found the first left space symbol | 415 | // found the first left space symbol |
412 | int pos = m_text.rfind(' ', (m_start_pos + m_cursor_pos) > 0 ? | 416 | int pos = m_text.rfind(' ', (m_start_pos + m_cursor_pos) > 0 ? |
@@ -425,14 +429,14 @@ int TextBox::findEmptySpaceLeft(){ | |||
425 | return pos; | 429 | return pos; |
426 | 430 | ||
427 | } | 431 | } |
428 | int TextBox::findEmptySpaceRight(){ | 432 | unsigned int TextBox::findEmptySpaceRight(){ |
429 | 433 | ||
430 | // found the first right space symbol | 434 | // found the first right space symbol |
431 | int pos = m_text.find(' ', m_start_pos + m_cursor_pos); | 435 | int pos = m_text.find(' ', m_start_pos + m_cursor_pos); |
432 | 436 | ||
433 | // do we have one more space symbol near? | 437 | // do we have one more space symbol near? |
434 | int next_pos = -1; | 438 | int next_pos = -1; |
435 | while (pos > -1 && pos < m_text.size() && (next_pos = m_text.find(' ', pos + 1)) > -1 ){ | 439 | while (pos > -1 && pos < static_cast<signed>(m_text.size()) && (next_pos = m_text.find(' ', pos + 1)) > -1 ){ |
436 | 440 | ||
437 | if (next_pos - 1 > pos) | 441 | if (next_pos - 1 > pos) |
438 | break; | 442 | break; |