aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authormathias <mathias>2005-05-07 19:33:54 (GMT)
committermathias <mathias>2005-05-07 19:33:54 (GMT)
commit4ddda95f20280da40b0f9412d340119141f70d46 (patch)
treef623f1b023b3ee5b466f3c9044189b30cac2bef2 /src/FbTk
parent5763339f4c732e53e786c798fb4143d7af4b291f (diff)
downloadfluxbox_paul-4ddda95f20280da40b0f9412d340119141f70d46.zip
fluxbox_paul-4ddda95f20280da40b0f9412d340119141f70d46.tar.bz2
patch from vadim to fix the issues in input-areas he introduced with his last
patch
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/TextBox.cc60
1 files changed, 36 insertions, 24 deletions
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