Changes in / [8c73012:e5d4294] in mainline
- Location:
- uspace/app/edit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r8c73012 re5d4294 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 … … 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 } … … 402 407 static void pane_row_range_display(int r0, int r1) 403 408 { 404 int width;405 409 int i, j, fill; 406 410 spt_t rb, re, dep; … … 415 419 console_goto(con, 0, 0); 416 420 for (i = r0; i < r1; ++i) { 417 sheet_get_row_width(&doc.sh, pane.sh_row + i, &width); 418 419 /* Determine row starting point. */ 420 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; 421 424 sheet_get_cell_pt(&doc.sh, &rbc, dir_before, &rb); 422 425 423 /* Determine row ending point. */ 424 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; 425 429 sheet_get_cell_pt(&doc.sh, &rec, dir_before, &re); 426 430 … … 494 498 495 499 spt_get_coord(&caret_pt, &coord); 496 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); 497 502 } 498 503 … … 511 516 512 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; 513 522 } 514 523 … … 526 535 527 536 (void) sheet_delete(&doc.sh, &sp, &ep); 537 538 pane.rflags |= REDRAW_ROW; 539 if (coord.column < 1) 540 pane.rflags |= REDRAW_TEXT; 528 541 } 529 542 … … 532 545 { 533 546 spt_t sp, ep; 534 coord_t coord;547 coord_t sc, ec; 535 548 536 549 tag_get_pt(&pane.caret_pos, &sp); 537 spt_get_coord(&sp, &coord); 538 539 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); 540 554 541 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; 542 560 } 543 561 … … 555 573 spt_get_coord(&pt, &coord); 556 574 557 /* Scroll pane as necessary. */575 /* Scroll pane vertically. */ 558 576 559 577 if (coord.row < pane.sh_row) { … … 561 579 pane.rflags |= REDRAW_TEXT; 562 580 } 581 563 582 if (coord.row > pane.sh_row + pane.rows - 1) { 564 583 pane.sh_row = coord.row - pane.rows + 1; … … 566 585 } 567 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 568 599 pane.rflags |= (REDRAW_CARET | REDRAW_STATUS); 569 570 600 } 571 601 … … 582 612 coord_t coord; 583 613 int num_rows; 614 bool pure_vertical; 584 615 585 616 tag_get_pt(&pane.caret_pos, &pt); … … 594 625 if (coord.row > num_rows) coord.row = num_rows; 595 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; 596 632 597 633 /* … … 603 639 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 604 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 605 647 caret_update(); 606 648 } -
uspace/app/edit/sheet.c
r8c73012 re5d4294 54 54 #include <adt/list.h> 55 55 #include <align.h> 56 #include <macros.h> 56 57 57 58 #include "sheet.h" 58 59 59 60 enum { 60 TAB_WIDTH = 8 61 TAB_WIDTH = 8, 62 63 /** Initial of dat buffer in bytes */ 64 INITIAL_SIZE = 32 61 65 }; 62 66 … … 64 68 int sheet_init(sheet_t *sh) 65 69 { 66 sh->dbuf_size = 65536;70 sh->dbuf_size = INITIAL_SIZE; 67 71 sh->text_size = 0; 68 72 … … 95 99 link_t *link; 96 100 tag_t *tag; 101 char *newp; 97 102 98 103 sz = str_size(str); 99 if (sh->text_size + sz > sh->dbuf_size) 100 return ELIMIT; 104 if (sh->text_size + sz > sh->dbuf_size) { 105 /* Enlarge data buffer. */ 106 newp = realloc(sh->data, sh->dbuf_size * 2); 107 if (newp == NULL) 108 return ELIMIT; 109 110 sh->data = newp; 111 sh->dbuf_size = sh->dbuf_size * 2; 112 } 101 113 102 114 ipp = sh->data + pos->b_off; 103 115 116 /* Copy data. */ 104 117 memmove(ipp + sz, ipp, sh->text_size - pos->b_off); 105 118 memcpy(ipp, str, sz); 106 119 sh->text_size += sz; 107 120 108 /* Adjust tags */121 /* Adjust tags. */ 109 122 110 123 link = sh->tags_head.next; … … 139 152 link_t *link; 140 153 tag_t *tag; 154 char *newp; 155 size_t shrink_size; 141 156 142 157 spp = sh->data + spos->b_off; … … 146 161 sh->text_size -= sz; 147 162 148 /* Adjust tags */163 /* Adjust tags. */ 149 164 link = sh->tags_head.next; 150 165 while (link != &sh->tags_head) { … … 158 173 link = link->next; 159 174 } 160 175 176 /* See if we should free up some memory. */ 177 shrink_size = max(sh->dbuf_size / 4, INITIAL_SIZE); 178 if (sh->text_size <= shrink_size && sh->dbuf_size > INITIAL_SIZE) { 179 /* Shrink data buffer. */ 180 newp = realloc(sh->data, shrink_size); 181 if (newp == NULL) { 182 /* Failed to shrink buffer... no matter. */ 183 return EOK; 184 } 185 186 sh->data = newp; 187 sh->dbuf_size = shrink_size; 188 } 189 161 190 return EOK; 162 191 }
Note:
See TracChangeset
for help on using the changeset viewer.