aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--src/FbTk/TextBox.cc60
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 @@
1(Format: Year/Month/Day) 1(Format: Year/Month/Day)
2Changes for 0.9.13 2Changes for 0.9.13
3*05/05/07: 3*05/05/07:
4 * Fix isses in patch from Vadim (thanx Vadim)
5 FbTk/TextBox.cc
4 * Remove default "gray" background (Simon) 6 * Remove default "gray" background (Simon)
5 FbTk/FbWindow.cc 7 FbTk/FbWindow.cc
6 * Fix titlebar transparency in some (tabbed) cases (Simon) 8 * Fix titlebar transparency in some (tabbed) cases (Simon)
@@ -11,7 +13,7 @@ Changes for 0.9.13
11 Styleresources: 13 Styleresources:
12 window.shade.pixmap, window.shade.unfocus.pixmap, window.shade.pressed.pixmap 14 window.shade.pixmap, window.shade.unfocus.pixmap, window.shade.pressed.pixmap
13 window.unshade.pixmap, window.unshade.unfocus.pixmap, window.unshade.pressed.pixmap 15 window.unshade.pixmap, window.unshade.unfocus.pixmap, window.unshade.pressed.pixmap
14 etc. 16 etc.
15 - MenuIcon - click on it provides the windowmenu, if the app 17 - MenuIcon - click on it provides the windowmenu, if the app
16 contains a pixmap (gvim, konqueror etc etc) the pixmap is displayed, a 18 contains a pixmap (gvim, konqueror etc etc) the pixmap is displayed, a
17 little menu otherwise. 19 little menu otherwise.
@@ -26,7 +28,7 @@ Changes for 0.9.13
26 Ewmh.hh/cc 28 Ewmh.hh/cc
27 * Fix potential segfault menu bug, thanks chenfeng (Simon) 29 * Fix potential segfault menu bug, thanks chenfeng (Simon)
28 Menu.cc 30 Menu.cc
29 * Added more KeyActions to TextBox (thanx to Vadim <suhanov_vadim@mail.ru> 31 * Added more KeyActions to TextBox (thanx to Vadim <suhanov_vadim at mail dot ru>
30 Control + LeftArrow -> Moves cursor to the left direction, up to next word. 32 Control + LeftArrow -> Moves cursor to the left direction, up to next word.
31 Control + RightArrow -> to the right direction. 33 Control + RightArrow -> to the right direction.
32 Control + BackSpace -> Removes everything from the cursor left side, up to next left word. 34 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) {
246 m_cursor_pos = 0; 246 m_cursor_pos = 0;
247 m_end_pos = 0; 247 m_end_pos = 0;
248 break; 248 break;
249 case XK_Left: 249 case XK_Left: {
250 if (m_cursor_pos && m_text.size()){ 250 int pos = findEmptySpaceLeft();
251 m_cursor_pos = findEmptySpaceLeft(); 251 if (pos < m_start_pos){
252 m_start_pos = pos;
253 m_cursor_pos = 0;
254 } else if (m_start_pos > 0) {
255 m_cursor_pos = pos - m_start_pos;
256 } else {
257 m_cursor_pos = pos;
258 }
252 adjustPos(); 259 adjustPos();
253 } 260 }
254 break; 261 break;
255 case XK_Right: 262 case XK_Right:
256 if (m_text.size() && m_cursor_pos < m_text.size()){ 263 if (m_text.size() && m_cursor_pos < m_text.size()){
257 m_cursor_pos = findEmptySpaceRight(); 264 int pos = findEmptySpaceRight() - m_start_pos;
265 if (m_start_pos + pos <= m_end_pos)
266 m_cursor_pos = pos;
267 else if (m_end_pos < text().size()) {
268 m_cursor_pos = pos;
269 m_end_pos = pos;
270 }
271
258 adjustPos(); 272 adjustPos();
273
259 } 274 }
260 break; 275 break;
261 276
262 case XK_BackSpace: { 277 case XK_BackSpace: {
263 if (!m_cursor_pos || !m_text.size())
264 break;
265
266 int pos = findEmptySpaceLeft(); 278 int pos = findEmptySpaceLeft();
267 279 m_text.erase(pos, m_cursor_pos - pos + m_start_pos);
268 m_text.erase(pos, m_cursor_pos - pos); 280
269 m_start_pos = 0; 281 if (pos < m_start_pos){
270 m_cursor_pos = pos; 282 m_start_pos = pos;
271 m_end_pos = m_text.size(); 283 m_cursor_pos = 0;
284 } else if (m_start_pos > 0) {
285 m_cursor_pos = pos - m_start_pos;
286 } else {
287 m_cursor_pos = pos;
288 }
272 adjustPos(); 289 adjustPos();
273 } 290 }
274 break; 291 break;
275 case XK_Delete: { 292 case XK_Delete: {
276
277 if (!m_text.size() || m_cursor_pos >= m_text.size()) 293 if (!m_text.size() || m_cursor_pos >= m_text.size())
278 break; 294 break;
279
280 int pos = findEmptySpaceRight(); 295 int pos = findEmptySpaceRight();
281 296 m_text.erase(m_cursor_pos + m_start_pos, pos - (m_cursor_pos + m_start_pos));
282 m_text.erase(m_cursor_pos, pos - m_cursor_pos);
283 m_start_pos = 0;
284 m_cursor_pos = m_cursor_pos;
285 m_end_pos = m_text.size();
286
287 adjustPos(); 297 adjustPos();
288 } 298 }
289 break; 299 break;
@@ -399,11 +409,12 @@ void TextBox::adjustStartPos() {
399int TextBox::findEmptySpaceLeft(){ 409int TextBox::findEmptySpaceLeft(){
400 410
401 // found the first left space symbol 411 // found the first left space symbol
402 int pos = m_text.rfind(' ', m_cursor_pos - 1); 412 int pos = m_text.rfind(' ', (m_start_pos + m_cursor_pos) > 0 ?
413 m_start_pos + m_cursor_pos - 1 : 0);
403 414
404 // do we have one more space symbol near? 415 // do we have one more space symbol near?
405 int next_pos = -1; 416 int next_pos = -1;
406 while ( pos > 0 && (next_pos = m_text.rfind(' ', pos - 1)) > -1 ){ 417 while (pos > 0 && (next_pos = m_text.rfind(' ', pos - 1)) > -1){
407 if (next_pos + 1 < pos) 418 if (next_pos + 1 < pos)
408 break; 419 break;
409 pos = next_pos; 420 pos = next_pos;
@@ -417,17 +428,18 @@ int TextBox::findEmptySpaceLeft(){
417int TextBox::findEmptySpaceRight(){ 428int TextBox::findEmptySpaceRight(){
418 429
419 // found the first right space symbol 430 // found the first right space symbol
420 int pos = m_text.find(' ', m_cursor_pos); 431 int pos = m_text.find(' ', m_start_pos + m_cursor_pos);
421 432
422 // do we have one more space symbol near? 433 // do we have one more space symbol near?
423 int next_pos = -1; 434 int next_pos = -1;
424 while (pos > -1 && pos < m_text.size() && (next_pos = m_text.find(' ', pos + 1)) > -1 ){ 435 while (pos > -1 && pos < m_text.size() && (next_pos = m_text.find(' ', pos + 1)) > -1 ){
436
425 if (next_pos - 1 > pos) 437 if (next_pos - 1 > pos)
426 break; 438 break;
427 pos = next_pos; 439 pos = next_pos;
428 } 440 }
429 if (pos < 0) 441 if (pos < 0)
430 pos = m_text.size(); 442 pos = m_text.size() - 1;
431 443
432 return pos + 1; // (+1) - sets cursor at the right. 444 return pos + 1; // (+1) - sets cursor at the right.
433 445