From 4ddda95f20280da40b0f9412d340119141f70d46 Mon Sep 17 00:00:00 2001 From: mathias Date: Sat, 7 May 2005 19:33:54 +0000 Subject: patch from vadim to fix the issues in input-areas he introduced with his last patch --- ChangeLog | 6 ++++-- src/FbTk/TextBox.cc | 60 ++++++++++++++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80f2913..6aeeecc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ (Format: Year/Month/Day) Changes for 0.9.13 *05/05/07: + * Fix isses in patch from Vadim (thanx Vadim) + FbTk/TextBox.cc * Remove default "gray" background (Simon) FbTk/FbWindow.cc * Fix titlebar transparency in some (tabbed) cases (Simon) @@ -11,7 +13,7 @@ Changes for 0.9.13 Styleresources: window.shade.pixmap, window.shade.unfocus.pixmap, window.shade.pressed.pixmap window.unshade.pixmap, window.unshade.unfocus.pixmap, window.unshade.pressed.pixmap - etc. + etc. - MenuIcon - click on it provides the windowmenu, if the app contains a pixmap (gvim, konqueror etc etc) the pixmap is displayed, a little menu otherwise. @@ -26,7 +28,7 @@ Changes for 0.9.13 Ewmh.hh/cc * Fix potential segfault menu bug, thanks chenfeng (Simon) Menu.cc - * Added more KeyActions to TextBox (thanx to Vadim + * Added more KeyActions to TextBox (thanx to Vadim Control + LeftArrow -> Moves cursor to the left direction, up to next word. Control + RightArrow -> to the right direction. Control + BackSpace -> Removes everything from the cursor left side, up to next left word. diff --git a/src/FbTk/TextBox.cc b/src/FbTk/TextBox.cc index 8e54ec7..13417da 100644 --- a/src/FbTk/TextBox.cc +++ b/src/FbTk/TextBox.cc @@ -246,44 +246,54 @@ void TextBox::keyPressEvent(XKeyEvent &event) { m_cursor_pos = 0; m_end_pos = 0; break; - case XK_Left: - if (m_cursor_pos && m_text.size()){ - m_cursor_pos = findEmptySpaceLeft(); + case XK_Left: { + int pos = findEmptySpaceLeft(); + if (pos < m_start_pos){ + m_start_pos = pos; + m_cursor_pos = 0; + } else if (m_start_pos > 0) { + m_cursor_pos = pos - m_start_pos; + } else { + m_cursor_pos = pos; + } adjustPos(); } break; case XK_Right: if (m_text.size() && m_cursor_pos < m_text.size()){ - m_cursor_pos = findEmptySpaceRight(); + int pos = findEmptySpaceRight() - m_start_pos; + if (m_start_pos + pos <= m_end_pos) + m_cursor_pos = pos; + else if (m_end_pos < text().size()) { + m_cursor_pos = pos; + m_end_pos = pos; + } + adjustPos(); + } break; case XK_BackSpace: { - if (!m_cursor_pos || !m_text.size()) - break; - int pos = findEmptySpaceLeft(); - - m_text.erase(pos, m_cursor_pos - pos); - m_start_pos = 0; - m_cursor_pos = pos; - m_end_pos = m_text.size(); + m_text.erase(pos, m_cursor_pos - pos + m_start_pos); + + if (pos < m_start_pos){ + m_start_pos = pos; + m_cursor_pos = 0; + } else if (m_start_pos > 0) { + m_cursor_pos = pos - m_start_pos; + } else { + m_cursor_pos = pos; + } adjustPos(); } break; case XK_Delete: { - if (!m_text.size() || m_cursor_pos >= m_text.size()) break; - int pos = findEmptySpaceRight(); - - m_text.erase(m_cursor_pos, pos - m_cursor_pos); - m_start_pos = 0; - m_cursor_pos = m_cursor_pos; - m_end_pos = m_text.size(); - + m_text.erase(m_cursor_pos + m_start_pos, pos - (m_cursor_pos + m_start_pos)); adjustPos(); } break; @@ -399,11 +409,12 @@ void TextBox::adjustStartPos() { int TextBox::findEmptySpaceLeft(){ // found the first left space symbol - int pos = m_text.rfind(' ', m_cursor_pos - 1); + int pos = m_text.rfind(' ', (m_start_pos + m_cursor_pos) > 0 ? + m_start_pos + m_cursor_pos - 1 : 0); // do we have one more space symbol near? int next_pos = -1; - while ( pos > 0 && (next_pos = m_text.rfind(' ', pos - 1)) > -1 ){ + while (pos > 0 && (next_pos = m_text.rfind(' ', pos - 1)) > -1){ if (next_pos + 1 < pos) break; pos = next_pos; @@ -417,17 +428,18 @@ int TextBox::findEmptySpaceLeft(){ int TextBox::findEmptySpaceRight(){ // found the first right space symbol - int pos = m_text.find(' ', m_cursor_pos); + int pos = m_text.find(' ', m_start_pos + m_cursor_pos); // do we have one more space symbol near? int next_pos = -1; while (pos > -1 && pos < m_text.size() && (next_pos = m_text.find(' ', pos + 1)) > -1 ){ + if (next_pos - 1 > pos) break; pos = next_pos; } if (pos < 0) - pos = m_text.size(); + pos = m_text.size() - 1; return pos + 1; // (+1) - sets cursor at the right. -- cgit v0.11.2