Changes in uspace/app/edit/edit.c [3052ff4:743e17b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r3052ff4 r743e17b 72 72 /** Current position of the caret */ 73 73 tag_t caret_pos; 74 75 /** 76 * Ideal column where the caret should try to get. This is used 77 * for maintaining the same column during vertical movement. 78 */ 79 int ideal_column; 74 80 } pane_t; 75 81 … … 88 94 static pane_t pane; 89 95 90 static i pcarg_t scr_rows, scr_columns;96 static int scr_rows, scr_columns; 91 97 92 98 #define ROW_BUF_SIZE 4096 … … 130 136 131 137 pane.rows = scr_rows - 1; 138 pane.columns = scr_columns; 132 139 pane.sh_row = 1; 140 pane.sh_column = 1; 133 141 134 142 /* Start with an empty sheet. */ … … 139 147 sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt); 140 148 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 149 pane.ideal_column = coord.column; 141 150 142 151 if (argc == 2) { … … 206 215 case KC_ENTER: 207 216 insert_char('\n'); 208 pane.rflags |= REDRAW_TEXT;209 217 caret_update(); 210 218 break; … … 235 243 case KC_BACKSPACE: 236 244 delete_char_before(); 237 pane.rflags |= REDRAW_TEXT;238 245 caret_update(); 239 246 break; 240 247 case KC_DELETE: 241 248 delete_char_after(); 242 pane.rflags |= REDRAW_TEXT;243 249 caret_update(); 244 250 break; … … 246 252 if (ev->c >= 32 || ev->c == '\t') { 247 253 insert_char(ev->c); 248 pane.rflags |= REDRAW_ROW;249 254 caret_update(); 250 255 } … … 362 367 { 363 368 int sh_rows, rows; 364 int i; 365 unsigned j; 369 int i, j; 366 370 367 371 sheet_get_num_rows(&doc.sh, &sh_rows); … … 403 407 static void pane_row_range_display(int r0, int r1) 404 408 { 405 int width;406 409 int i, j, fill; 407 410 spt_t rb, re, dep; … … 416 419 console_goto(con, 0, 0); 417 420 for (i = r0; i < r1; ++i) { 418 sheet_get_row_width(&doc.sh, pane.sh_row + i, &width); 419 420 /* Determine row starting point. */ 421 rbc.row = pane.sh_row + i; rbc.column = 1; 421 /* Starting point for row display */ 422 rbc.row = pane.sh_row + i; 423 rbc.column = pane.sh_column; 422 424 sheet_get_cell_pt(&doc.sh, &rbc, dir_before, &rb); 423 425 424 /* Determine row ending point. */ 425 rec.row = pane.sh_row + i; rec.column = width + 1; 426 /* Ending point for row display */ 427 rec.row = pane.sh_row + i; 428 rec.column = pane.sh_column + pane.columns; 426 429 sheet_get_cell_pt(&doc.sh, &rec, dir_before, &re); 427 430 … … 452 455 /* Fill until the end of display area. */ 453 456 454 if (str_length(row_buf) < scr_columns)457 if (str_length(row_buf) < (unsigned) scr_columns) 455 458 fill = scr_columns - str_length(row_buf); 456 459 else … … 495 498 496 499 spt_get_coord(&caret_pt, &coord); 497 console_goto(con, coord.column - 1, coord.row - pane.sh_row); 500 console_goto(con, coord.column - pane.sh_column, 501 coord.row - pane.sh_row); 498 502 } 499 503 … … 512 516 513 517 (void) sheet_insert(&doc.sh, &pt, dir_before, cbuf); 518 519 pane.rflags |= REDRAW_ROW; 520 if (c == '\n') 521 pane.rflags |= REDRAW_TEXT; 514 522 } 515 523 … … 527 535 528 536 (void) sheet_delete(&doc.sh, &sp, &ep); 537 538 pane.rflags |= REDRAW_ROW; 539 if (coord.column < 1) 540 pane.rflags |= REDRAW_TEXT; 529 541 } 530 542 … … 533 545 { 534 546 spt_t sp, ep; 535 coord_t coord;547 coord_t sc, ec; 536 548 537 549 tag_get_pt(&pane.caret_pos, &sp); 538 spt_get_coord(&sp, &coord); 539 540 sheet_get_cell_pt(&doc.sh, &coord, dir_after, &ep); 550 spt_get_coord(&sp, &sc); 551 552 sheet_get_cell_pt(&doc.sh, &sc, dir_after, &ep); 553 spt_get_coord(&ep, &ec); 541 554 542 555 (void) sheet_delete(&doc.sh, &sp, &ep); 556 557 pane.rflags |= REDRAW_ROW; 558 if (ec.row != sc.row) 559 pane.rflags |= REDRAW_TEXT; 543 560 } 544 561 … … 556 573 spt_get_coord(&pt, &coord); 557 574 558 /* Scroll pane as necessary. */575 /* Scroll pane vertically. */ 559 576 560 577 if (coord.row < pane.sh_row) { … … 562 579 pane.rflags |= REDRAW_TEXT; 563 580 } 581 564 582 if (coord.row > pane.sh_row + pane.rows - 1) { 565 583 pane.sh_row = coord.row - pane.rows + 1; … … 567 585 } 568 586 587 /* Scroll pane horizontally. */ 588 589 if (coord.column < pane.sh_column) { 590 pane.sh_column = coord.column; 591 pane.rflags |= REDRAW_TEXT; 592 } 593 594 if (coord.column > pane.sh_column + pane.columns - 1) { 595 pane.sh_column = coord.column - pane.columns + 1; 596 pane.rflags |= REDRAW_TEXT; 597 } 598 569 599 pane.rflags |= (REDRAW_CARET | REDRAW_STATUS); 570 571 600 } 572 601 … … 583 612 coord_t coord; 584 613 int num_rows; 614 bool pure_vertical; 585 615 586 616 tag_get_pt(&pane.caret_pos, &pt); … … 595 625 if (coord.row > num_rows) coord.row = num_rows; 596 626 } 627 628 /* For purely vertical movement try attaining @c ideal_column. */ 629 pure_vertical = (dcolumn == 0 && align_dir == dir_before); 630 if (pure_vertical) 631 coord.column = pane.ideal_column; 597 632 598 633 /* … … 604 639 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 605 640 641 /* For non-vertical movement set the new value for @c ideal_column. */ 642 if (!pure_vertical) { 643 spt_get_coord(&pt, &coord); 644 pane.ideal_column = coord.column; 645 } 646 606 647 caret_update(); 607 648 }
Note:
See TracChangeset
for help on using the changeset viewer.