Changes in / [e5d4294:8c73012] in mainline
- Location:
- uspace/app/edit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
re5d4294 r8c73012 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 used77 * for maintaining the same column during vertical movement.78 */79 int ideal_column;80 74 } pane_t; 81 75 … … 136 130 137 131 pane.rows = scr_rows - 1; 138 pane.columns = scr_columns;139 132 pane.sh_row = 1; 140 pane.sh_column = 1;141 133 142 134 /* Start with an empty sheet. */ … … 147 139 sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt); 148 140 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 149 pane.ideal_column = coord.column;150 141 151 142 if (argc == 2) { … … 215 206 case KC_ENTER: 216 207 insert_char('\n'); 208 pane.rflags |= REDRAW_TEXT; 217 209 caret_update(); 218 210 break; … … 243 235 case KC_BACKSPACE: 244 236 delete_char_before(); 237 pane.rflags |= REDRAW_TEXT; 245 238 caret_update(); 246 239 break; 247 240 case KC_DELETE: 248 241 delete_char_after(); 242 pane.rflags |= REDRAW_TEXT; 249 243 caret_update(); 250 244 break; … … 252 246 if (ev->c >= 32 || ev->c == '\t') { 253 247 insert_char(ev->c); 248 pane.rflags |= REDRAW_ROW; 254 249 caret_update(); 255 250 } … … 407 402 static void pane_row_range_display(int r0, int r1) 408 403 { 404 int width; 409 405 int i, j, fill; 410 406 spt_t rb, re, dep; … … 419 415 console_goto(con, 0, 0); 420 416 for (i = r0; i < r1; ++i) { 421 /* Starting point for row display */ 422 rbc.row = pane.sh_row + i; 423 rbc.column = pane.sh_column; 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; 424 421 sheet_get_cell_pt(&doc.sh, &rbc, dir_before, &rb); 425 422 426 /* Ending point for row display */ 427 rec.row = pane.sh_row + i; 428 rec.column = pane.sh_column + pane.columns; 423 /* Determine row ending point. */ 424 rec.row = pane.sh_row + i; rec.column = width + 1; 429 425 sheet_get_cell_pt(&doc.sh, &rec, dir_before, &re); 430 426 … … 498 494 499 495 spt_get_coord(&caret_pt, &coord); 500 console_goto(con, coord.column - pane.sh_column, 501 coord.row - pane.sh_row); 496 console_goto(con, coord.column - 1, coord.row - pane.sh_row); 502 497 } 503 498 … … 516 511 517 512 (void) sheet_insert(&doc.sh, &pt, dir_before, cbuf); 518 519 pane.rflags |= REDRAW_ROW;520 if (c == '\n')521 pane.rflags |= REDRAW_TEXT;522 513 } 523 514 … … 535 526 536 527 (void) sheet_delete(&doc.sh, &sp, &ep); 537 538 pane.rflags |= REDRAW_ROW;539 if (coord.column < 1)540 pane.rflags |= REDRAW_TEXT;541 528 } 542 529 … … 545 532 { 546 533 spt_t sp, ep; 547 coord_t sc, ec;534 coord_t coord; 548 535 549 536 tag_get_pt(&pane.caret_pos, &sp); 550 spt_get_coord(&sp, &sc); 551 552 sheet_get_cell_pt(&doc.sh, &sc, dir_after, &ep); 553 spt_get_coord(&ep, &ec); 537 spt_get_coord(&sp, &coord); 538 539 sheet_get_cell_pt(&doc.sh, &coord, dir_after, &ep); 554 540 555 541 (void) sheet_delete(&doc.sh, &sp, &ep); 556 557 pane.rflags |= REDRAW_ROW;558 if (ec.row != sc.row)559 pane.rflags |= REDRAW_TEXT;560 542 } 561 543 … … 573 555 spt_get_coord(&pt, &coord); 574 556 575 /* Scroll pane vertically. */557 /* Scroll pane as necessary. */ 576 558 577 559 if (coord.row < pane.sh_row) { … … 579 561 pane.rflags |= REDRAW_TEXT; 580 562 } 581 582 563 if (coord.row > pane.sh_row + pane.rows - 1) { 583 564 pane.sh_row = coord.row - pane.rows + 1; … … 585 566 } 586 567 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 599 568 pane.rflags |= (REDRAW_CARET | REDRAW_STATUS); 569 600 570 } 601 571 … … 612 582 coord_t coord; 613 583 int num_rows; 614 bool pure_vertical;615 584 616 585 tag_get_pt(&pane.caret_pos, &pt); … … 625 594 if (coord.row > num_rows) coord.row = num_rows; 626 595 } 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;632 596 633 597 /* … … 639 603 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 640 604 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 647 605 caret_update(); 648 606 } -
uspace/app/edit/sheet.c
re5d4294 r8c73012 54 54 #include <adt/list.h> 55 55 #include <align.h> 56 #include <macros.h>57 56 58 57 #include "sheet.h" 59 58 60 59 enum { 61 TAB_WIDTH = 8, 62 63 /** Initial of dat buffer in bytes */ 64 INITIAL_SIZE = 32 60 TAB_WIDTH = 8 65 61 }; 66 62 … … 68 64 int sheet_init(sheet_t *sh) 69 65 { 70 sh->dbuf_size = INITIAL_SIZE;66 sh->dbuf_size = 65536; 71 67 sh->text_size = 0; 72 68 … … 99 95 link_t *link; 100 96 tag_t *tag; 101 char *newp;102 97 103 98 sz = str_size(str); 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 } 99 if (sh->text_size + sz > sh->dbuf_size) 100 return ELIMIT; 113 101 114 102 ipp = sh->data + pos->b_off; 115 103 116 /* Copy data. */117 104 memmove(ipp + sz, ipp, sh->text_size - pos->b_off); 118 105 memcpy(ipp, str, sz); 119 106 sh->text_size += sz; 120 107 121 /* Adjust tags .*/108 /* Adjust tags */ 122 109 123 110 link = sh->tags_head.next; … … 152 139 link_t *link; 153 140 tag_t *tag; 154 char *newp;155 size_t shrink_size;156 141 157 142 spp = sh->data + spos->b_off; … … 161 146 sh->text_size -= sz; 162 147 163 /* Adjust tags .*/148 /* Adjust tags */ 164 149 link = sh->tags_head.next; 165 150 while (link != &sh->tags_head) { … … 173 158 link = link->next; 174 159 } 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 160 190 161 return EOK; 191 162 }
Note:
See TracChangeset
for help on using the changeset viewer.