Changeset 7eaeec1 in mainline for uspace/app/edit/edit.c
- Timestamp:
- 2012-08-20T21:27:38Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6a97f2e
- Parents:
- f3a37e28 (diff), dd13349 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
rf3a37e28 r7eaeec1 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. */ … … 140 144 static void delete_char_after(void); 141 145 static void caret_update(void); 142 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir); 143 static void caret_move_word_left(void); 144 static void caret_move_word_right(void); 145 static void caret_move_to_line(int row); 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); 146 151 static void caret_go_to_line_ask(void); 147 152 … … 149 154 static void selection_sel_all(void); 150 155 static void selection_sel_range(spt_t pa, spt_t pb); 151 static void selection_sel_prev_word(void);152 static void selection_sel_next_word(void);153 156 static void selection_get_points(spt_t *pa, spt_t *pb); 154 157 static void selection_delete(void); 155 158 static void selection_copy(void); 156 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); 157 164 158 165 static void pt_get_sof(spt_t *pt); … … 163 170 static bool pt_is_delimiter(spt_t *pt); 164 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 165 175 static int tag_cmp(tag_t const *a, tag_t const *b); 166 176 static int spt_cmp(spt_t const *a, spt_t const *b); … … 173 183 { 174 184 kbd_event_t ev; 175 coord_t coord;176 185 bool new_file; 177 178 spt_t pt; 186 int rc; 179 187 180 188 con = console_init(stdin, stdout); … … 189 197 190 198 /* Start with an empty sheet. */ 191 sheet_init(&doc.sh); 199 rc = sheet_create(&doc.sh); 200 if (rc != EOK) { 201 printf("Out of memory.\n"); 202 return -1; 203 } 192 204 193 205 /* Place caret at the beginning of file. */ 194 coord.row = coord.column = 1;195 sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt);196 sheet_place_tag( &doc.sh, &pt, &pane.caret_pos);197 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; 198 210 199 211 if (argc == 2) { … … 211 223 new_file = true; 212 224 225 /* Place selection start tag. */ 226 sheet_place_tag(doc.sh, &sof, &pane.sel_start); 227 213 228 /* Move to beginning of file. */ 214 caret_move(-ED_INFTY, -ED_INFTY, dir_before); 215 216 /* Place selection start tag. */ 217 tag_get_pt(&pane.caret_pos, &pt); 218 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 229 pt_get_sof(&sof); 230 caret_move(sof, true, true); 219 231 220 232 /* Initial display */ … … 364 376 static void key_handle_ctrl(kbd_event_t const *ev) 365 377 { 378 spt_t pt; 366 379 switch (ev->key) { 367 380 case KC_Q: … … 395 408 selection_sel_all(); 396 409 break; 397 case KC_W:398 if (selection_active())399 break;400 selection_sel_prev_word();401 selection_delete();402 break;403 410 case KC_RIGHT: 404 caret_move_word_right( );411 caret_move_word_right(false); 405 412 break; 406 413 case KC_LEFT: 407 caret_move_word_left( );414 caret_move_word_left(false); 408 415 break; 409 416 case KC_L: 410 417 caret_go_to_line_ask(); 411 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); 432 break; 412 433 default: 413 434 break; … … 417 438 static void key_handle_shift_ctrl(kbd_event_t const *ev) 418 439 { 440 spt_t pt; 419 441 switch(ev->key) { 420 442 case KC_LEFT: 421 selection_sel_prev_word();443 caret_move_word_left(true); 422 444 break; 423 445 case KC_RIGHT: 424 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); 425 458 break; 426 459 default: … … 429 462 } 430 463 431 static void key_handle_movement(unsigned int key, bool select) 432 { 433 spt_t pt; 434 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; 435 468 coord_t c_old, c_new; 436 469 bool had_sel; 437 470 438 471 /* Check if we had selection before. */ 439 tag_get_pt(&pane.caret_pos, &caret_pt); 440 tag_get_pt(&pane.sel_start, &pt); 441 had_sel = !spt_equal(&caret_pt, &pt); 442 443 switch (key) { 444 case KC_LEFT: 445 caret_move(0, -1, dir_before); 446 break; 447 case KC_RIGHT: 448 caret_move(0, 0, dir_after); 449 break; 450 case KC_UP: 451 caret_move(-1, 0, dir_before); 452 break; 453 case KC_DOWN: 454 caret_move(+1, 0, dir_before); 455 break; 456 case KC_HOME: 457 caret_move(0, -ED_INFTY, dir_before); 458 break; 459 case KC_END: 460 caret_move(0, +ED_INFTY, dir_before); 461 break; 462 case KC_PAGE_UP: 463 caret_move(-pane.rows, 0, dir_before); 464 break; 465 case KC_PAGE_DOWN: 466 caret_move(+pane.rows, 0, dir_before); 467 break; 468 default: 469 break; 470 } 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); 471 479 472 480 if (select == false) { 473 481 /* Move sel_start to the same point as caret. */ 474 sheet_remove_tag( &doc.sh, &pane.sel_start);475 tag_get_pt(&pane.caret_pos, &pt);476 sheet_place_tag(&doc.sh, &pt, &pane.sel_start);477 } 478 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); 479 487 if (select) { 480 tag_get_pt(&pane.caret_pos, &pt); 481 spt_get_coord(&caret_pt, &c_old); 482 spt_get_coord(&pt, &c_new); 488 spt_get_coord(&old_caret_pt, &c_old); 483 489 484 490 if (c_old.row == c_new.row) … … 490 496 /* Redraw because text was unselected. */ 491 497 pane.rflags |= REDRAW_TEXT; 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; 492 540 } 493 541 } … … 663 711 664 712 do { 665 sheet_copy_out( &doc.sh, &sp, epos, buf, BUF_SIZE, &bep);713 sheet_copy_out(doc.sh, &sp, epos, buf, BUF_SIZE, &bep); 666 714 bytes = str_size(buf); 667 715 … … 698 746 699 747 while (true) { 700 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, 701 749 &bep); 702 750 bytes = str_size(&buf[bpos]); … … 720 768 int sh_rows, rows; 721 769 722 sheet_get_num_rows( &doc.sh, &sh_rows);770 sheet_get_num_rows(doc.sh, &sh_rows); 723 771 rows = min(sh_rows - pane.sh_row + 1, pane.rows); 724 772 … … 790 838 rbc.row = pane.sh_row + i; 791 839 rbc.column = pane.sh_column; 792 sheet_get_cell_pt( &doc.sh, &rbc, dir_before, &rb);840 sheet_get_cell_pt(doc.sh, &rbc, dir_before, &rb); 793 841 794 842 /* Ending point for row display */ 795 843 rec.row = pane.sh_row + i; 796 844 rec.column = pane.sh_column + pane.columns; 797 sheet_get_cell_pt( &doc.sh, &rec, dir_before, &re);845 sheet_get_cell_pt(doc.sh, &rec, dir_before, &re); 798 846 799 847 /* Copy the text of the row to the buffer. */ 800 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); 801 849 802 850 /* Display text from the buffer. */ … … 867 915 spt_t caret_pt; 868 916 coord_t coord; 917 int last_row; 869 918 870 919 tag_get_pt(&pane.caret_pos, &caret_pt); 871 920 spt_get_coord(&caret_pt, &coord); 872 921 922 sheet_get_num_rows(doc.sh, &last_row); 923 873 924 const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>"; 874 925 875 926 console_set_pos(con, 0, scr_rows - 1); 876 927 console_set_style(con, STYLE_INVERTED); 877 int n = printf(" %d, %d : File '%s'. Ctrl-Q Quit Ctrl-S Save "878 "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); 879 930 880 931 int pos = scr_columns - 1 - n; … … 912 963 cbuf[offs] = '\0'; 913 964 914 (void) sheet_insert( &doc.sh, &pt, dir_before, cbuf);965 (void) sheet_insert(doc.sh, &pt, dir_before, cbuf); 915 966 916 967 pane.rflags |= REDRAW_ROW; … … 929 980 930 981 coord.column -= 1; 931 sheet_get_cell_pt( &doc.sh, &coord, dir_before, &sp);932 933 (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); 934 985 935 986 pane.rflags |= REDRAW_ROW; … … 947 998 spt_get_coord(&sp, &sc); 948 999 949 sheet_get_cell_pt( &doc.sh, &sc, dir_after, &ep);1000 sheet_get_cell_pt(doc.sh, &sc, dir_after, &ep); 950 1001 spt_get_coord(&ep, &ec); 951 1002 952 (void) sheet_delete( &doc.sh, &sp, &ep);1003 (void) sheet_delete(doc.sh, &sp, &ep); 953 1004 954 1005 pane.rflags |= REDRAW_ROW; … … 997 1048 } 998 1049 999 /** Change the caret position.1050 /** Relatively move caret position. 1000 1051 * 1001 1052 * Moves caret relatively to the current position. Looking at the first … … 1003 1054 * to a new character cell, and thus a new character. Then we either go to the 1004 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 1005 1058 */ 1006 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) 1007 1061 { 1008 1062 spt_t pt; … … 1022 1076 else { 1023 1077 coord.row--; 1024 sheet_get_row_width( &doc.sh, coord.row, &coord.column);1078 sheet_get_row_width(doc.sh, coord.row, &coord.column); 1025 1079 } 1026 1080 } 1027 1081 if (drow > 0) { 1028 sheet_get_num_rows( &doc.sh, &num_rows);1082 sheet_get_num_rows(doc.sh, &num_rows); 1029 1083 if (coord.row > num_rows) coord.row = num_rows; 1030 1084 } … … 1039 1093 * coordinates. The character can be wider than one cell (e.g. tab). 1040 1094 */ 1041 sheet_get_cell_pt(&doc.sh, &coord, align_dir, &pt); 1042 sheet_remove_tag(&doc.sh, &pane.caret_pos); 1043 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 1095 sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt); 1044 1096 1045 1097 /* For non-vertical movement set the new value for @c ideal_column. */ 1046 if (!pure_vertical) { 1047 spt_get_coord(&pt, &coord); 1048 pane.ideal_column = coord.column; 1049 } 1050 1051 caret_update(); 1052 } 1053 1054 static void caret_move_word_left(void) 1055 { 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 1056 1116 spt_t pt; 1057 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 { 1058 1125 do { 1059 caret_move(0, -1, dir_before); 1060 1061 tag_get_pt(&pane.caret_pos, &pt); 1062 1063 sheet_remove_tag(&doc.sh, &pane.sel_start); 1064 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 1065 } while (!pt_is_word_beginning(&pt)); 1066 1067 pane.rflags |= REDRAW_TEXT; 1068 } 1069 1070 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) 1071 1141 { 1072 1142 spt_t pt; 1073 1074 do { 1075 caret_move(0, 0, dir_after); 1076 1077 tag_get_pt(&pane.caret_pos, &pt); 1078 1079 sheet_remove_tag(&doc.sh, &pane.sel_start); 1080 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 1081 } while (!pt_is_word_beginning(&pt)); 1082 1083 pane.rflags |= REDRAW_TEXT; 1084 } 1085 1086 /** Change the caret position to a beginning of a given line 1087 */ 1088 static void caret_move_to_line(int row) 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) 1089 1149 { 1090 1150 spt_t pt; 1091 coord_t coord;1092 int num_rows;1093 1094 1151 tag_get_pt(&pane.caret_pos, &pt); 1095 spt_get_coord(&pt, &coord); 1096 coord.row = row; 1097 coord.column = 1; 1098 1099 /* Clamp coordinates. */ 1100 if (coord.row < 1) coord.row = 1; 1101 sheet_get_num_rows(&doc.sh, &num_rows); 1102 if (coord.row > num_rows) coord.row = num_rows; 1103 1104 /* 1105 * Select the point before the character at the designated 1106 * coordinates. The character can be wider than one cell (e.g. tab). 1107 */ 1108 sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt); 1109 sheet_remove_tag(&doc.sh, &pane.caret_pos); 1110 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 1111 1112 /* Set the new value for @c ideal_column. */ 1113 spt_get_coord(&pt, &coord); 1114 pane.ideal_column = coord.column; 1115 1116 caret_update(); 1152 spt_t word_right = pt_find_word_right(pt); 1153 caret_move(word_right, select, true); 1117 1154 } 1118 1155 … … 1131 1168 int line = strtol(sline, &endptr, 10); 1132 1169 if (*endptr != '\0') { 1170 free(sline); 1133 1171 status_display("Invalid number entered."); 1134 1172 return; 1135 1173 } 1136 1137 caret_move_to_line(line); 1138 } 1139 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); 1322 } 1140 1323 1141 1324 /** Check for non-empty selection. */ … … 1176 1359 1177 1360 if (rel < 0) 1178 sheet_delete( &doc.sh, &pa, &pb);1361 sheet_delete(doc.sh, &pa, &pb); 1179 1362 else 1180 sheet_delete( &doc.sh, &pb, &pa);1363 sheet_delete(doc.sh, &pb, &pa); 1181 1364 1182 1365 if (ca.row == cb.row) … … 1200 1383 static void selection_sel_range(spt_t pa, spt_t pb) 1201 1384 { 1202 sheet_remove_tag( &doc.sh, &pane.sel_start);1203 sheet_place_tag( &doc.sh, &pa, &pane.sel_start);1204 sheet_remove_tag( &doc.sh, &pane.caret_pos);1205 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); 1206 1389 1207 1390 pane.rflags |= REDRAW_TEXT; 1208 1391 caret_update(); 1209 }1210 1211 /** Add the previous word to the selection */1212 static void selection_sel_prev_word(void)1213 {1214 spt_t cpt, wpt, spt, ept;1215 1216 selection_get_points(&spt, &ept);1217 1218 tag_get_pt(&pane.caret_pos, &cpt);1219 caret_move_word_left();1220 tag_get_pt(&pane.caret_pos, &wpt);1221 1222 if (spt_cmp(&spt, &cpt) == 0)1223 selection_sel_range(ept, wpt);1224 else1225 selection_sel_range(spt, wpt);1226 }1227 1228 /** Add the next word to the selection */1229 static void selection_sel_next_word(void)1230 {1231 spt_t cpt, wpt, spt, ept;1232 1233 selection_get_points(&spt, &ept);1234 1235 tag_get_pt(&pane.caret_pos, &cpt);1236 caret_move_word_right();1237 tag_get_pt(&pane.caret_pos, &wpt);1238 1239 if (spt_cmp(&ept, &cpt) == 0)1240 selection_sel_range(spt, wpt);1241 else1242 selection_sel_range(ept, wpt);1243 1392 } 1244 1393 … … 1286 1435 1287 1436 coord.row = coord.column = 1; 1288 sheet_get_cell_pt( &doc.sh, &coord, dir_before, pt);1437 sheet_get_cell_pt(doc.sh, &coord, dir_before, pt); 1289 1438 } 1290 1439 … … 1295 1444 int num_rows; 1296 1445 1297 sheet_get_num_rows( &doc.sh, &num_rows);1446 sheet_get_num_rows(doc.sh, &num_rows); 1298 1447 coord.row = num_rows + 1; 1299 1448 coord.column = 1; 1300 1449 1301 sheet_get_cell_pt( &doc.sh, &coord, dir_after, pt);1450 sheet_get_cell_pt(doc.sh, &coord, dir_after, pt); 1302 1451 } 1303 1452 … … 1310 1459 coord.column = 1; 1311 1460 1312 sheet_get_cell_pt( &doc.sh, &coord, dir_before, spt);1461 sheet_get_cell_pt(doc.sh, &coord, dir_before, spt); 1313 1462 } 1314 1463 … … 1320 1469 1321 1470 spt_get_coord(cpt, &coord); 1322 sheet_get_row_width( &doc.sh, coord.row, &row_width);1471 sheet_get_row_width(doc.sh, coord.row, &row_width); 1323 1472 coord.column = row_width - 1; 1324 1473 1325 sheet_get_cell_pt( &doc.sh, &coord, dir_after, ept);1474 sheet_get_cell_pt(doc.sh, &coord, dir_after, ept); 1326 1475 } 1327 1476 … … 1349 1498 1350 1499 coord.column -= 1; 1351 sheet_get_cell_pt( &doc.sh, &coord, dir_before, &lp);1500 sheet_get_cell_pt(doc.sh, &coord, dir_before, &lp); 1352 1501 1353 1502 return pt_is_delimiter(&lp) … … 1371 1520 1372 1521 coord.column += 1; 1373 sheet_get_cell_pt( &doc.sh, &coord, dir_after, &rp);1522 sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp); 1374 1523 1375 1524 ch = range_get_str(pt, &rp); … … 1397 1546 1398 1547 coord.column += 1; 1399 sheet_get_cell_pt( &doc.sh, &coord, dir_after, &rp);1548 sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp); 1400 1549 1401 1550 ch = range_get_str(pt, &rp);
Note:
See TracChangeset
for help on using the changeset viewer.