Changes in uspace/app/edit/edit.c [8f6bffdd:dd13349] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r8f6bffdd rdd13349 1 1 /* 2 2 * Copyright (c) 2009 Jiri Svoboda 3 * Copyright (c) 2012 Martin Sucha 3 4 * All rights reserved. 4 5 * … … 49 50 50 51 #include "sheet.h" 52 #include "search.h" 51 53 52 54 enum redraw_flags { … … 83 85 */ 84 86 int ideal_column; 87 88 char *previous_search; 89 bool previous_search_reverse; 85 90 } pane_t; 86 91 … … 91 96 typedef struct { 92 97 char *file_name; 93 sheet_t sh;98 sheet_t *sh; 94 99 } doc_t; 95 100 … … 106 111 #define BUF_SIZE 64 107 112 #define TAB_WIDTH 8 108 #define ED_INFTY 65536109 113 110 114 /** Maximum filename length that can be entered. */ … … 126 130 static int file_save_range(char const *fname, spt_t const *spos, 127 131 spt_t const *epos); 128 static char *filename_prompt(char const *prompt, char const *init_value);129 132 static char *range_get_str(spt_t const *spos, spt_t const *epos); 133 134 static char *prompt(char const *prompt, char const *init_value); 130 135 131 136 static void pane_text_display(void); … … 139 144 static void delete_char_after(void); 140 145 static void caret_update(void); 141 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir); 142 static void caret_move_word_left(void); 143 static void caret_move_word_right(void); 146 static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir, bool select); 147 static void caret_move_absolute(int row, int column, enum dir_spec align_dir, bool select); 148 static void caret_move(spt_t spt, bool select, bool update_ideal_column); 149 static void caret_move_word_left(bool select); 150 static void caret_move_word_right(bool select); 151 static void caret_go_to_line_ask(void); 144 152 145 153 static bool selection_active(void); 146 154 static void selection_sel_all(void); 147 155 static void selection_sel_range(spt_t pa, spt_t pb); 148 static void selection_sel_prev_word(void);149 static void selection_sel_next_word(void);150 156 static void selection_get_points(spt_t *pa, spt_t *pb); 151 157 static void selection_delete(void); 152 158 static void selection_copy(void); 153 159 static void insert_clipboard_data(void); 160 161 static void search(char *pattern, bool reverse); 162 static void search_prompt(bool reverse); 163 static void search_repeat(void); 154 164 155 165 static void pt_get_sof(spt_t *pt); … … 160 170 static bool pt_is_delimiter(spt_t *pt); 161 171 static bool pt_is_punctuation(spt_t *pt); 172 static spt_t pt_find_word_left(spt_t spt); 173 static spt_t pt_find_word_left(spt_t spt); 174 162 175 static int tag_cmp(tag_t const *a, tag_t const *b); 163 176 static int spt_cmp(spt_t const *a, spt_t const *b); … … 170 183 { 171 184 kbd_event_t ev; 172 coord_t coord;173 185 bool new_file; 174 175 spt_t pt; 186 int rc; 176 187 177 188 con = console_init(stdin, stdout); … … 186 197 187 198 /* Start with an empty sheet. */ 188 sheet_init(&doc.sh); 199 rc = sheet_create(&doc.sh); 200 if (rc != EOK) { 201 printf("Out of memory.\n"); 202 return -1; 203 } 189 204 190 205 /* Place caret at the beginning of file. */ 191 coord.row = coord.column = 1;192 sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt);193 sheet_place_tag( &doc.sh, &pt, &pane.caret_pos);194 pane.ideal_column = coord.column;206 spt_t sof; 207 pt_get_sof(&sof); 208 sheet_place_tag(doc.sh, &sof, &pane.caret_pos); 209 pane.ideal_column = 1; 195 210 196 211 if (argc == 2) { … … 208 223 new_file = true; 209 224 225 /* Place selection start tag. */ 226 sheet_place_tag(doc.sh, &sof, &pane.sel_start); 227 210 228 /* Move to beginning of file. */ 211 caret_move(-ED_INFTY, -ED_INFTY, dir_before); 212 213 /* Place selection start tag. */ 214 tag_get_pt(&pane.caret_pos, &pt); 215 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 229 pt_get_sof(&sof); 230 caret_move(sof, true, true); 216 231 217 232 /* Initial display */ … … 361 376 static void key_handle_ctrl(kbd_event_t const *ev) 362 377 { 378 spt_t pt; 363 379 switch (ev->key) { 364 380 case KC_Q: … … 392 408 selection_sel_all(); 393 409 break; 394 case KC_W:395 if (selection_active())396 break;397 selection_sel_prev_word();398 selection_delete();399 break;400 410 case KC_RIGHT: 401 caret_move_word_right( );411 caret_move_word_right(false); 402 412 break; 403 413 case KC_LEFT: 404 caret_move_word_left(); 414 caret_move_word_left(false); 415 break; 416 case KC_L: 417 caret_go_to_line_ask(); 418 break; 419 case KC_F: 420 search_prompt(false); 421 break; 422 case KC_N: 423 search_repeat(); 424 break; 425 case KC_HOME: 426 pt_get_sof(&pt); 427 caret_move(pt, false, true); 428 break; 429 case KC_END: 430 pt_get_eof(&pt); 431 caret_move(pt, false, true); 405 432 break; 406 433 default: … … 411 438 static void key_handle_shift_ctrl(kbd_event_t const *ev) 412 439 { 440 spt_t pt; 413 441 switch(ev->key) { 414 442 case KC_LEFT: 415 selection_sel_prev_word();443 caret_move_word_left(true); 416 444 break; 417 445 case KC_RIGHT: 418 selection_sel_next_word(); 446 caret_move_word_right(true); 447 break; 448 case KC_F: 449 search_prompt(true); 450 break; 451 case KC_HOME: 452 pt_get_sof(&pt); 453 caret_move(pt, true, true); 454 break; 455 case KC_END: 456 pt_get_eof(&pt); 457 caret_move(pt, true, true); 419 458 break; 420 459 default: … … 423 462 } 424 463 425 static void key_handle_movement(unsigned int key, bool select) 426 { 427 spt_t pt; 428 spt_t caret_pt;464 /** Move caret while preserving or resetting selection. */ 465 static void caret_move(spt_t new_caret_pt, bool select, bool update_ideal_column) 466 { 467 spt_t old_caret_pt, old_sel_pt; 429 468 coord_t c_old, c_new; 430 469 bool had_sel; 431 470 432 471 /* Check if we had selection before. */ 433 tag_get_pt(&pane.caret_pos, &caret_pt); 434 tag_get_pt(&pane.sel_start, &pt); 435 had_sel = !spt_equal(&caret_pt, &pt); 436 437 switch (key) { 438 case KC_LEFT: 439 caret_move(0, -1, dir_before); 440 break; 441 case KC_RIGHT: 442 caret_move(0, 0, dir_after); 443 break; 444 case KC_UP: 445 caret_move(-1, 0, dir_before); 446 break; 447 case KC_DOWN: 448 caret_move(+1, 0, dir_before); 449 break; 450 case KC_HOME: 451 caret_move(0, -ED_INFTY, dir_before); 452 break; 453 case KC_END: 454 caret_move(0, +ED_INFTY, dir_before); 455 break; 456 case KC_PAGE_UP: 457 caret_move(-pane.rows, 0, dir_before); 458 break; 459 case KC_PAGE_DOWN: 460 caret_move(+pane.rows, 0, dir_before); 461 break; 462 default: 463 break; 464 } 472 tag_get_pt(&pane.caret_pos, &old_caret_pt); 473 tag_get_pt(&pane.sel_start, &old_sel_pt); 474 had_sel = !spt_equal(&old_caret_pt, &old_sel_pt); 475 476 /* Place tag of the caret */ 477 sheet_remove_tag(doc.sh, &pane.caret_pos); 478 sheet_place_tag(doc.sh, &new_caret_pt, &pane.caret_pos); 465 479 466 480 if (select == false) { 467 481 /* Move sel_start to the same point as caret. */ 468 sheet_remove_tag( &doc.sh, &pane.sel_start);469 tag_get_pt(&pane.caret_pos, &pt);470 sheet_place_tag(&doc.sh, &pt, &pane.sel_start);471 } 472 482 sheet_remove_tag(doc.sh, &pane.sel_start); 483 sheet_place_tag(doc.sh, &new_caret_pt, &pane.sel_start); 484 } 485 486 spt_get_coord(&new_caret_pt, &c_new); 473 487 if (select) { 474 tag_get_pt(&pane.caret_pos, &pt); 475 spt_get_coord(&caret_pt, &c_old); 476 spt_get_coord(&pt, &c_new); 488 spt_get_coord(&old_caret_pt, &c_old); 477 489 478 490 if (c_old.row == c_new.row) … … 485 497 pane.rflags |= REDRAW_TEXT; 486 498 } 499 500 if (update_ideal_column) 501 pane.ideal_column = c_new.column; 502 503 caret_update(); 504 } 505 506 static void key_handle_movement(unsigned int key, bool select) 507 { 508 spt_t pt; 509 switch (key) { 510 case KC_LEFT: 511 caret_move_relative(0, -1, dir_before, select); 512 break; 513 case KC_RIGHT: 514 caret_move_relative(0, 0, dir_after, select); 515 break; 516 case KC_UP: 517 caret_move_relative(-1, 0, dir_before, select); 518 break; 519 case KC_DOWN: 520 caret_move_relative(+1, 0, dir_before, select); 521 break; 522 case KC_HOME: 523 tag_get_pt(&pane.caret_pos, &pt); 524 pt_get_sol(&pt, &pt); 525 caret_move(pt, select, true); 526 break; 527 case KC_END: 528 tag_get_pt(&pane.caret_pos, &pt); 529 pt_get_eol(&pt, &pt); 530 caret_move(pt, select, true); 531 break; 532 case KC_PAGE_UP: 533 caret_move_relative(-pane.rows, 0, dir_before, select); 534 break; 535 case KC_PAGE_DOWN: 536 caret_move_relative(+pane.rows, 0, dir_before, select); 537 break; 538 default: 539 break; 540 } 487 541 } 488 542 … … 520 574 char *fname; 521 575 522 fname = filename_prompt("Save As", old_fname);576 fname = prompt("Save As", old_fname); 523 577 if (fname == NULL) { 524 578 status_display("Save cancelled."); … … 535 589 } 536 590 537 /** Ask for a file name. */538 static char * filename_prompt(char const *prompt, char const *init_value)591 /** Ask for a string. */ 592 static char *prompt(char const *prompt, char const *init_value) 539 593 { 540 594 kbd_event_t ev; … … 657 711 658 712 do { 659 sheet_copy_out( &doc.sh, &sp, epos, buf, BUF_SIZE, &bep);713 sheet_copy_out(doc.sh, &sp, epos, buf, BUF_SIZE, &bep); 660 714 bytes = str_size(buf); 661 715 … … 692 746 693 747 while (true) { 694 sheet_copy_out( &doc.sh, &sp, epos, &buf[bpos], buf_size - bpos,748 sheet_copy_out(doc.sh, &sp, epos, &buf[bpos], buf_size - bpos, 695 749 &bep); 696 750 bytes = str_size(&buf[bpos]); … … 714 768 int sh_rows, rows; 715 769 716 sheet_get_num_rows( &doc.sh, &sh_rows);770 sheet_get_num_rows(doc.sh, &sh_rows); 717 771 rows = min(sh_rows - pane.sh_row + 1, pane.rows); 718 772 … … 784 838 rbc.row = pane.sh_row + i; 785 839 rbc.column = pane.sh_column; 786 sheet_get_cell_pt( &doc.sh, &rbc, dir_before, &rb);840 sheet_get_cell_pt(doc.sh, &rbc, dir_before, &rb); 787 841 788 842 /* Ending point for row display */ 789 843 rec.row = pane.sh_row + i; 790 844 rec.column = pane.sh_column + pane.columns; 791 sheet_get_cell_pt( &doc.sh, &rec, dir_before, &re);845 sheet_get_cell_pt(doc.sh, &rec, dir_before, &re); 792 846 793 847 /* Copy the text of the row to the buffer. */ 794 sheet_copy_out( &doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep);848 sheet_copy_out(doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep); 795 849 796 850 /* Display text from the buffer. */ … … 842 896 /* Fill until the end of display area. */ 843 897 844 if ( str_length(row_buf) < (unsigned)scr_columns)845 fill = scr_columns - str_length(row_buf);898 if ((unsigned)s_column - 1 < scr_columns) 899 fill = scr_columns - (s_column - 1); 846 900 else 847 901 fill = 0; … … 861 915 spt_t caret_pt; 862 916 coord_t coord; 917 int last_row; 863 918 864 919 tag_get_pt(&pane.caret_pos, &caret_pt); 865 920 spt_get_coord(&caret_pt, &coord); 866 921 922 sheet_get_num_rows(doc.sh, &last_row); 923 867 924 const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>"; 868 925 869 926 console_set_pos(con, 0, scr_rows - 1); 870 927 console_set_style(con, STYLE_INVERTED); 871 int n = printf(" %d, %d : File '%s'. Ctrl-Q Quit Ctrl-S Save "872 "Ctrl-E Save As", coord.row, coord.column, fname);928 int n = printf(" %d, %d (%d): File '%s'. Ctrl-Q Quit Ctrl-S Save " 929 "Ctrl-E Save As", coord.row, coord.column, last_row, fname); 873 930 874 931 int pos = scr_columns - 1 - n; … … 906 963 cbuf[offs] = '\0'; 907 964 908 (void) sheet_insert( &doc.sh, &pt, dir_before, cbuf);965 (void) sheet_insert(doc.sh, &pt, dir_before, cbuf); 909 966 910 967 pane.rflags |= REDRAW_ROW; … … 923 980 924 981 coord.column -= 1; 925 sheet_get_cell_pt( &doc.sh, &coord, dir_before, &sp);926 927 (void) sheet_delete( &doc.sh, &sp, &ep);982 sheet_get_cell_pt(doc.sh, &coord, dir_before, &sp); 983 984 (void) sheet_delete(doc.sh, &sp, &ep); 928 985 929 986 pane.rflags |= REDRAW_ROW; … … 941 998 spt_get_coord(&sp, &sc); 942 999 943 sheet_get_cell_pt( &doc.sh, &sc, dir_after, &ep);1000 sheet_get_cell_pt(doc.sh, &sc, dir_after, &ep); 944 1001 spt_get_coord(&ep, &ec); 945 1002 946 (void) sheet_delete( &doc.sh, &sp, &ep);1003 (void) sheet_delete(doc.sh, &sp, &ep); 947 1004 948 1005 pane.rflags |= REDRAW_ROW; … … 991 1048 } 992 1049 993 /** Change the caret position.1050 /** Relatively move caret position. 994 1051 * 995 1052 * Moves caret relatively to the current position. Looking at the first … … 997 1054 * to a new character cell, and thus a new character. Then we either go to the 998 1055 * point before the the character or after it, depending on @a align_dir. 1056 * 1057 * @param select true if the selection tag should stay where it is 999 1058 */ 1000 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir) 1059 static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir, 1060 bool select) 1001 1061 { 1002 1062 spt_t pt; … … 1016 1076 else { 1017 1077 coord.row--; 1018 sheet_get_row_width( &doc.sh, coord.row, &coord.column);1078 sheet_get_row_width(doc.sh, coord.row, &coord.column); 1019 1079 } 1020 1080 } 1021 1081 if (drow > 0) { 1022 sheet_get_num_rows( &doc.sh, &num_rows);1082 sheet_get_num_rows(doc.sh, &num_rows); 1023 1083 if (coord.row > num_rows) coord.row = num_rows; 1024 1084 } … … 1033 1093 * coordinates. The character can be wider than one cell (e.g. tab). 1034 1094 */ 1035 sheet_get_cell_pt(&doc.sh, &coord, align_dir, &pt); 1036 sheet_remove_tag(&doc.sh, &pane.caret_pos); 1037 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 1095 sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt); 1038 1096 1039 1097 /* For non-vertical movement set the new value for @c ideal_column. */ 1040 if (!pure_vertical) { 1041 spt_get_coord(&pt, &coord); 1042 pane.ideal_column = coord.column; 1043 } 1044 1045 caret_update(); 1046 } 1047 1048 static void caret_move_word_left(void) 1049 { 1098 caret_move(pt, select, !pure_vertical); 1099 } 1100 1101 /** Absolutely move caret position. 1102 * 1103 * Moves caret to a specified position. We get to a new character cell, and 1104 * thus a new character. Then we either go to the point before the the character 1105 * or after it, depending on @a align_dir. 1106 * 1107 * @param select true if the selection tag should stay where it is 1108 */ 1109 static void caret_move_absolute(int row, int column, enum dir_spec align_dir, 1110 bool select) 1111 { 1112 coord_t coord; 1113 coord.row = row; 1114 coord.column = column; 1115 1050 1116 spt_t pt; 1051 1117 sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt); 1118 1119 caret_move(pt, select, true); 1120 } 1121 1122 /** Find beginning of a word to the left of spt */ 1123 static spt_t pt_find_word_left(spt_t spt) 1124 { 1052 1125 do { 1053 caret_move(0, -1, dir_before); 1054 1055 tag_get_pt(&pane.caret_pos, &pt); 1056 1057 sheet_remove_tag(&doc.sh, &pane.sel_start); 1058 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 1059 } while (!pt_is_word_beginning(&pt)); 1060 1061 pane.rflags |= REDRAW_TEXT; 1062 } 1063 1064 static void caret_move_word_right(void) 1126 spt_prev_char(spt, &spt); 1127 } while (!pt_is_word_beginning(&spt)); 1128 return spt; 1129 } 1130 1131 /** Find beginning of a word to the right of spt */ 1132 static spt_t pt_find_word_right(spt_t spt) 1133 { 1134 do { 1135 spt_next_char(spt, &spt); 1136 } while (!pt_is_word_beginning(&spt)); 1137 return spt; 1138 } 1139 1140 static void caret_move_word_left(bool select) 1065 1141 { 1066 1142 spt_t pt; 1067 1068 do { 1069 caret_move(0, 0, dir_after); 1070 1071 tag_get_pt(&pane.caret_pos, &pt); 1072 1073 sheet_remove_tag(&doc.sh, &pane.sel_start); 1074 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 1075 } while (!pt_is_word_beginning(&pt)); 1076 1077 pane.rflags |= REDRAW_TEXT; 1143 tag_get_pt(&pane.caret_pos, &pt); 1144 spt_t word_left = pt_find_word_left(pt); 1145 caret_move(word_left, select, true); 1146 } 1147 1148 static void caret_move_word_right(bool select) 1149 { 1150 spt_t pt; 1151 tag_get_pt(&pane.caret_pos, &pt); 1152 spt_t word_right = pt_find_word_right(pt); 1153 caret_move(word_right, select, true); 1154 } 1155 1156 /** Ask for line and go to it. */ 1157 static void caret_go_to_line_ask(void) 1158 { 1159 char *sline; 1160 1161 sline = prompt("Go to line", ""); 1162 if (sline == NULL) { 1163 status_display("Go to line cancelled."); 1164 return; 1165 } 1166 1167 char *endptr; 1168 int line = strtol(sline, &endptr, 10); 1169 if (*endptr != '\0') { 1170 free(sline); 1171 status_display("Invalid number entered."); 1172 return; 1173 } 1174 free(sline); 1175 1176 caret_move_absolute(line, pane.ideal_column, dir_before, false); 1177 } 1178 1179 /* Search operations */ 1180 static int search_spt_producer(void *data, wchar_t *ret) 1181 { 1182 assert(data != NULL); 1183 assert(ret != NULL); 1184 spt_t *spt = data; 1185 *ret = spt_next_char(*spt, spt); 1186 return EOK; 1187 } 1188 1189 static int search_spt_reverse_producer(void *data, wchar_t *ret) 1190 { 1191 assert(data != NULL); 1192 assert(ret != NULL); 1193 spt_t *spt = data; 1194 *ret = spt_prev_char(*spt, spt); 1195 return EOK; 1196 } 1197 1198 static int search_spt_mark(void *data, void **mark) 1199 { 1200 assert(data != NULL); 1201 assert(mark != NULL); 1202 spt_t *spt = data; 1203 spt_t *new = calloc(1, sizeof(spt_t)); 1204 *mark = new; 1205 if (new == NULL) 1206 return ENOMEM; 1207 *new = *spt; 1208 return EOK; 1209 } 1210 1211 static void search_spt_mark_free(void *data) 1212 { 1213 free(data); 1214 } 1215 1216 static search_ops_t search_spt_ops = { 1217 .equals = char_exact_equals, 1218 .producer = search_spt_producer, 1219 .mark = search_spt_mark, 1220 .mark_free = search_spt_mark_free, 1221 }; 1222 1223 static search_ops_t search_spt_reverse_ops = { 1224 .equals = char_exact_equals, 1225 .producer = search_spt_reverse_producer, 1226 .mark = search_spt_mark, 1227 .mark_free = search_spt_mark_free, 1228 }; 1229 1230 /** Ask for line and go to it. */ 1231 static void search_prompt(bool reverse) 1232 { 1233 char *pattern; 1234 1235 const char *prompt_text = "Find next"; 1236 if (reverse) 1237 prompt_text = "Find previous"; 1238 1239 const char *default_value = ""; 1240 if (pane.previous_search) 1241 default_value = pane.previous_search; 1242 1243 pattern = prompt(prompt_text, default_value); 1244 if (pattern == NULL) { 1245 status_display("Search cancelled."); 1246 return; 1247 } 1248 1249 if (pane.previous_search) 1250 free(pane.previous_search); 1251 pane.previous_search = pattern; 1252 pane.previous_search_reverse = reverse; 1253 1254 search(pattern, reverse); 1255 } 1256 1257 static void search_repeat(void) 1258 { 1259 if (pane.previous_search == NULL) { 1260 status_display("No previous search to repeat."); 1261 return; 1262 } 1263 1264 search(pane.previous_search, pane.previous_search_reverse); 1265 } 1266 1267 static void search(char *pattern, bool reverse) 1268 { 1269 status_display("Searching..."); 1270 1271 spt_t sp, producer_pos; 1272 tag_get_pt(&pane.caret_pos, &sp); 1273 1274 /* Start searching on the position before/after caret */ 1275 if (!reverse) { 1276 spt_next_char(sp, &sp); 1277 } 1278 else { 1279 spt_prev_char(sp, &sp); 1280 } 1281 producer_pos = sp; 1282 1283 search_ops_t ops = search_spt_ops; 1284 if (reverse) 1285 ops = search_spt_reverse_ops; 1286 1287 search_t *search = search_init(pattern, &producer_pos, ops, reverse); 1288 if (search == NULL) { 1289 status_display("Failed initializing search."); 1290 return; 1291 } 1292 1293 match_t match; 1294 int rc = search_next_match(search, &match); 1295 if (rc != EOK) { 1296 status_display("Failed searching."); 1297 search_fini(search); 1298 } 1299 1300 if (match.end) { 1301 status_display("Match found."); 1302 assert(match.end != NULL); 1303 spt_t *end = match.end; 1304 caret_move(*end, false, true); 1305 while (match.length > 0) { 1306 match.length--; 1307 if (reverse) { 1308 spt_next_char(*end, end); 1309 } 1310 else { 1311 spt_prev_char(*end, end); 1312 } 1313 } 1314 caret_move(*end, true, true); 1315 free(end); 1316 } 1317 else { 1318 status_display("Not found."); 1319 } 1320 1321 search_fini(search); 1078 1322 } 1079 1323 … … 1115 1359 1116 1360 if (rel < 0) 1117 sheet_delete( &doc.sh, &pa, &pb);1361 sheet_delete(doc.sh, &pa, &pb); 1118 1362 else 1119 sheet_delete( &doc.sh, &pb, &pa);1363 sheet_delete(doc.sh, &pb, &pa); 1120 1364 1121 1365 if (ca.row == cb.row) … … 1139 1383 static void selection_sel_range(spt_t pa, spt_t pb) 1140 1384 { 1141 sheet_remove_tag( &doc.sh, &pane.sel_start);1142 sheet_place_tag( &doc.sh, &pa, &pane.sel_start);1143 sheet_remove_tag( &doc.sh, &pane.caret_pos);1144 sheet_place_tag( &doc.sh, &pb, &pane.caret_pos);1385 sheet_remove_tag(doc.sh, &pane.sel_start); 1386 sheet_place_tag(doc.sh, &pa, &pane.sel_start); 1387 sheet_remove_tag(doc.sh, &pane.caret_pos); 1388 sheet_place_tag(doc.sh, &pb, &pane.caret_pos); 1145 1389 1146 1390 pane.rflags |= REDRAW_TEXT; 1147 1391 caret_update(); 1148 }1149 1150 /** Add the previous word to the selection */1151 static void selection_sel_prev_word(void)1152 {1153 spt_t cpt, wpt, spt, ept;1154 1155 selection_get_points(&spt, &ept);1156 1157 tag_get_pt(&pane.caret_pos, &cpt);1158 caret_move_word_left();1159 tag_get_pt(&pane.caret_pos, &wpt);1160 1161 if (spt_cmp(&spt, &cpt) == 0)1162 selection_sel_range(ept, wpt);1163 else1164 selection_sel_range(spt, wpt);1165 }1166 1167 /** Add the next word to the selection */1168 static void selection_sel_next_word(void)1169 {1170 spt_t cpt, wpt, spt, ept;1171 1172 selection_get_points(&spt, &ept);1173 1174 tag_get_pt(&pane.caret_pos, &cpt);1175 caret_move_word_right();1176 tag_get_pt(&pane.caret_pos, &wpt);1177 1178 if (spt_cmp(&ept, &cpt) == 0)1179 selection_sel_range(spt, wpt);1180 else1181 selection_sel_range(ept, wpt);1182 1392 } 1183 1393 … … 1225 1435 1226 1436 coord.row = coord.column = 1; 1227 sheet_get_cell_pt( &doc.sh, &coord, dir_before, pt);1437 sheet_get_cell_pt(doc.sh, &coord, dir_before, pt); 1228 1438 } 1229 1439 … … 1234 1444 int num_rows; 1235 1445 1236 sheet_get_num_rows( &doc.sh, &num_rows);1446 sheet_get_num_rows(doc.sh, &num_rows); 1237 1447 coord.row = num_rows + 1; 1238 1448 coord.column = 1; 1239 1449 1240 sheet_get_cell_pt( &doc.sh, &coord, dir_after, pt);1450 sheet_get_cell_pt(doc.sh, &coord, dir_after, pt); 1241 1451 } 1242 1452 … … 1249 1459 coord.column = 1; 1250 1460 1251 sheet_get_cell_pt( &doc.sh, &coord, dir_before, spt);1461 sheet_get_cell_pt(doc.sh, &coord, dir_before, spt); 1252 1462 } 1253 1463 … … 1259 1469 1260 1470 spt_get_coord(cpt, &coord); 1261 sheet_get_row_width( &doc.sh, coord.row, &row_width);1471 sheet_get_row_width(doc.sh, coord.row, &row_width); 1262 1472 coord.column = row_width - 1; 1263 1473 1264 sheet_get_cell_pt( &doc.sh, &coord, dir_after, ept);1474 sheet_get_cell_pt(doc.sh, &coord, dir_after, ept); 1265 1475 } 1266 1476 … … 1288 1498 1289 1499 coord.column -= 1; 1290 sheet_get_cell_pt( &doc.sh, &coord, dir_before, &lp);1500 sheet_get_cell_pt(doc.sh, &coord, dir_before, &lp); 1291 1501 1292 1502 return pt_is_delimiter(&lp) … … 1310 1520 1311 1521 coord.column += 1; 1312 sheet_get_cell_pt( &doc.sh, &coord, dir_after, &rp);1522 sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp); 1313 1523 1314 1524 ch = range_get_str(pt, &rp); … … 1336 1546 1337 1547 coord.column += 1; 1338 sheet_get_cell_pt( &doc.sh, &coord, dir_after, &rp);1548 sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp); 1339 1549 1340 1550 ch = range_get_str(pt, &rp);
Note:
See TracChangeset
for help on using the changeset viewer.