Changes in uspace/app/edit/edit.c [dd13349:b8b742e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
rdd13349 rb8b742e 1 1 /* 2 2 * Copyright (c) 2009 Jiri Svoboda 3 * Copyright (c) 2012 Martin Sucha4 3 * All rights reserved. 5 4 * … … 50 49 51 50 #include "sheet.h" 52 #include "search.h"53 51 54 52 enum redraw_flags { … … 85 83 */ 86 84 int ideal_column; 87 88 char *previous_search;89 bool previous_search_reverse;90 85 } pane_t; 91 86 … … 96 91 typedef struct { 97 92 char *file_name; 98 sheet_t *sh;93 sheet_t sh; 99 94 } doc_t; 100 95 … … 111 106 #define BUF_SIZE 64 112 107 #define TAB_WIDTH 8 108 #define ED_INFTY 65536 113 109 114 110 /** Maximum filename length that can be entered. */ … … 144 140 static void delete_char_after(void); 145 141 static void caret_update(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); 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); 151 146 static void caret_go_to_line_ask(void); 152 147 … … 154 149 static void selection_sel_all(void); 155 150 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); 156 153 static void selection_get_points(spt_t *pa, spt_t *pb); 157 154 static void selection_delete(void); 158 155 static void selection_copy(void); 159 156 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);164 157 165 158 static void pt_get_sof(spt_t *pt); … … 170 163 static bool pt_is_delimiter(spt_t *pt); 171 164 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 175 165 static int tag_cmp(tag_t const *a, tag_t const *b); 176 166 static int spt_cmp(spt_t const *a, spt_t const *b); … … 183 173 { 184 174 kbd_event_t ev; 175 coord_t coord; 185 176 bool new_file; 186 int rc; 177 178 spt_t pt; 187 179 188 180 con = console_init(stdin, stdout); … … 197 189 198 190 /* Start with an empty sheet. */ 199 rc = sheet_create(&doc.sh); 200 if (rc != EOK) { 201 printf("Out of memory.\n"); 202 return -1; 203 } 191 sheet_init(&doc.sh); 204 192 205 193 /* Place caret at the beginning of file. */ 206 spt_t sof;207 pt_get_sof(&sof);208 sheet_place_tag( doc.sh, &sof, &pane.caret_pos);209 pane.ideal_column = 1;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; 210 198 211 199 if (argc == 2) { … … 223 211 new_file = true; 224 212 213 /* Move to beginning of file. */ 214 caret_move(-ED_INFTY, -ED_INFTY, dir_before); 215 225 216 /* Place selection start tag. */ 226 sheet_place_tag(doc.sh, &sof, &pane.sel_start); 227 228 /* Move to beginning of file. */ 229 pt_get_sof(&sof); 230 caret_move(sof, true, true); 217 tag_get_pt(&pane.caret_pos, &pt); 218 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 231 219 232 220 /* Initial display */ … … 376 364 static void key_handle_ctrl(kbd_event_t const *ev) 377 365 { 378 spt_t pt;379 366 switch (ev->key) { 380 367 case KC_Q: … … 408 395 selection_sel_all(); 409 396 break; 397 case KC_W: 398 if (selection_active()) 399 break; 400 selection_sel_prev_word(); 401 selection_delete(); 402 break; 410 403 case KC_RIGHT: 411 caret_move_word_right( false);404 caret_move_word_right(); 412 405 break; 413 406 case KC_LEFT: 414 caret_move_word_left( false);407 caret_move_word_left(); 415 408 break; 416 409 case KC_L: 417 410 caret_go_to_line_ask(); 418 411 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;433 412 default: 434 413 break; … … 438 417 static void key_handle_shift_ctrl(kbd_event_t const *ev) 439 418 { 440 spt_t pt;441 419 switch(ev->key) { 442 420 case KC_LEFT: 443 caret_move_word_left(true);421 selection_sel_prev_word(); 444 422 break; 445 423 case KC_RIGHT: 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); 424 selection_sel_next_word(); 458 425 break; 459 426 default: … … 462 429 } 463 430 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;431 static void key_handle_movement(unsigned int key, bool select) 432 { 433 spt_t pt; 434 spt_t caret_pt; 468 435 coord_t c_old, c_new; 469 436 bool had_sel; 470 437 471 438 /* Check if we had selection before. */ 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); 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 } 479 471 480 472 if (select == false) { 481 473 /* Move sel_start to the same point as caret. */ 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); 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 487 479 if (select) { 488 spt_get_coord(&old_caret_pt, &c_old); 480 tag_get_pt(&pane.caret_pos, &pt); 481 spt_get_coord(&caret_pt, &c_old); 482 spt_get_coord(&pt, &c_new); 489 483 490 484 if (c_old.row == c_new.row) … … 496 490 /* Redraw because text was unselected. */ 497 491 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;540 492 } 541 493 } … … 711 663 712 664 do { 713 sheet_copy_out( doc.sh, &sp, epos, buf, BUF_SIZE, &bep);665 sheet_copy_out(&doc.sh, &sp, epos, buf, BUF_SIZE, &bep); 714 666 bytes = str_size(buf); 715 667 … … 746 698 747 699 while (true) { 748 sheet_copy_out( doc.sh, &sp, epos, &buf[bpos], buf_size - bpos,700 sheet_copy_out(&doc.sh, &sp, epos, &buf[bpos], buf_size - bpos, 749 701 &bep); 750 702 bytes = str_size(&buf[bpos]); … … 768 720 int sh_rows, rows; 769 721 770 sheet_get_num_rows( doc.sh, &sh_rows);722 sheet_get_num_rows(&doc.sh, &sh_rows); 771 723 rows = min(sh_rows - pane.sh_row + 1, pane.rows); 772 724 … … 838 790 rbc.row = pane.sh_row + i; 839 791 rbc.column = pane.sh_column; 840 sheet_get_cell_pt( doc.sh, &rbc, dir_before, &rb);792 sheet_get_cell_pt(&doc.sh, &rbc, dir_before, &rb); 841 793 842 794 /* Ending point for row display */ 843 795 rec.row = pane.sh_row + i; 844 796 rec.column = pane.sh_column + pane.columns; 845 sheet_get_cell_pt( doc.sh, &rec, dir_before, &re);797 sheet_get_cell_pt(&doc.sh, &rec, dir_before, &re); 846 798 847 799 /* Copy the text of the row to the buffer. */ 848 sheet_copy_out( doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep);800 sheet_copy_out(&doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep); 849 801 850 802 /* Display text from the buffer. */ … … 915 867 spt_t caret_pt; 916 868 coord_t coord; 917 int last_row;918 869 919 870 tag_get_pt(&pane.caret_pos, &caret_pt); 920 871 spt_get_coord(&caret_pt, &coord); 921 872 922 sheet_get_num_rows(doc.sh, &last_row);923 924 873 const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>"; 925 874 926 875 console_set_pos(con, 0, scr_rows - 1); 927 876 console_set_style(con, STYLE_INVERTED); 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);877 int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit Ctrl-S Save " 878 "Ctrl-E Save As", coord.row, coord.column, fname); 930 879 931 880 int pos = scr_columns - 1 - n; … … 963 912 cbuf[offs] = '\0'; 964 913 965 (void) sheet_insert( doc.sh, &pt, dir_before, cbuf);914 (void) sheet_insert(&doc.sh, &pt, dir_before, cbuf); 966 915 967 916 pane.rflags |= REDRAW_ROW; … … 980 929 981 930 coord.column -= 1; 982 sheet_get_cell_pt( doc.sh, &coord, dir_before, &sp);983 984 (void) sheet_delete( doc.sh, &sp, &ep);931 sheet_get_cell_pt(&doc.sh, &coord, dir_before, &sp); 932 933 (void) sheet_delete(&doc.sh, &sp, &ep); 985 934 986 935 pane.rflags |= REDRAW_ROW; … … 998 947 spt_get_coord(&sp, &sc); 999 948 1000 sheet_get_cell_pt( doc.sh, &sc, dir_after, &ep);949 sheet_get_cell_pt(&doc.sh, &sc, dir_after, &ep); 1001 950 spt_get_coord(&ep, &ec); 1002 951 1003 (void) sheet_delete( doc.sh, &sp, &ep);952 (void) sheet_delete(&doc.sh, &sp, &ep); 1004 953 1005 954 pane.rflags |= REDRAW_ROW; … … 1048 997 } 1049 998 1050 /** Relatively move caret position.999 /** Change the caret position. 1051 1000 * 1052 1001 * Moves caret relatively to the current position. Looking at the first … … 1054 1003 * to a new character cell, and thus a new character. Then we either go to the 1055 1004 * 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 is1058 1005 */ 1059 static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir, 1060 bool select) 1006 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir) 1061 1007 { 1062 1008 spt_t pt; … … 1076 1022 else { 1077 1023 coord.row--; 1078 sheet_get_row_width( doc.sh, coord.row, &coord.column);1024 sheet_get_row_width(&doc.sh, coord.row, &coord.column); 1079 1025 } 1080 1026 } 1081 1027 if (drow > 0) { 1082 sheet_get_num_rows( doc.sh, &num_rows);1028 sheet_get_num_rows(&doc.sh, &num_rows); 1083 1029 if (coord.row > num_rows) coord.row = num_rows; 1084 1030 } … … 1093 1039 * coordinates. The character can be wider than one cell (e.g. tab). 1094 1040 */ 1095 sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt); 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); 1096 1044 1097 1045 /* For non-vertical movement set the new value for @c ideal_column. */ 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 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 { 1056 spt_t pt; 1057 1058 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) 1071 { 1072 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 1108 1087 */ 1109 static void caret_move_ absolute(int row, int column, enum dir_spec align_dir,1110 bool select) 1111 { 1088 static void caret_move_to_line(int row) 1089 { 1090 spt_t pt; 1112 1091 coord_t coord; 1092 int num_rows; 1093 1094 tag_get_pt(&pane.caret_pos, &pt); 1095 spt_get_coord(&pt, &coord); 1113 1096 coord.row = row; 1114 coord.column = column; 1115 1116 spt_t pt; 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 { 1125 do { 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) 1141 { 1142 spt_t pt; 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); 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(); 1154 1117 } 1155 1118 … … 1168 1131 int line = strtol(sline, &endptr, 10); 1169 1132 if (*endptr != '\0') { 1170 free(sline);1171 1133 status_display("Invalid number entered."); 1172 1134 return; 1173 1135 } 1174 free(sline);1175 1136 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 } 1137 caret_move_to_line(line); 1138 } 1139 1323 1140 1324 1141 /** Check for non-empty selection. */ … … 1359 1176 1360 1177 if (rel < 0) 1361 sheet_delete( doc.sh, &pa, &pb);1178 sheet_delete(&doc.sh, &pa, &pb); 1362 1179 else 1363 sheet_delete( doc.sh, &pb, &pa);1180 sheet_delete(&doc.sh, &pb, &pa); 1364 1181 1365 1182 if (ca.row == cb.row) … … 1383 1200 static void selection_sel_range(spt_t pa, spt_t pb) 1384 1201 { 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);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); 1389 1206 1390 1207 pane.rflags |= REDRAW_TEXT; 1391 1208 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 else 1225 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 else 1242 selection_sel_range(ept, wpt); 1392 1243 } 1393 1244 … … 1435 1286 1436 1287 coord.row = coord.column = 1; 1437 sheet_get_cell_pt( doc.sh, &coord, dir_before, pt);1288 sheet_get_cell_pt(&doc.sh, &coord, dir_before, pt); 1438 1289 } 1439 1290 … … 1444 1295 int num_rows; 1445 1296 1446 sheet_get_num_rows( doc.sh, &num_rows);1297 sheet_get_num_rows(&doc.sh, &num_rows); 1447 1298 coord.row = num_rows + 1; 1448 1299 coord.column = 1; 1449 1300 1450 sheet_get_cell_pt( doc.sh, &coord, dir_after, pt);1301 sheet_get_cell_pt(&doc.sh, &coord, dir_after, pt); 1451 1302 } 1452 1303 … … 1459 1310 coord.column = 1; 1460 1311 1461 sheet_get_cell_pt( doc.sh, &coord, dir_before, spt);1312 sheet_get_cell_pt(&doc.sh, &coord, dir_before, spt); 1462 1313 } 1463 1314 … … 1469 1320 1470 1321 spt_get_coord(cpt, &coord); 1471 sheet_get_row_width( doc.sh, coord.row, &row_width);1322 sheet_get_row_width(&doc.sh, coord.row, &row_width); 1472 1323 coord.column = row_width - 1; 1473 1324 1474 sheet_get_cell_pt( doc.sh, &coord, dir_after, ept);1325 sheet_get_cell_pt(&doc.sh, &coord, dir_after, ept); 1475 1326 } 1476 1327 … … 1498 1349 1499 1350 coord.column -= 1; 1500 sheet_get_cell_pt( doc.sh, &coord, dir_before, &lp);1351 sheet_get_cell_pt(&doc.sh, &coord, dir_before, &lp); 1501 1352 1502 1353 return pt_is_delimiter(&lp) … … 1520 1371 1521 1372 coord.column += 1; 1522 sheet_get_cell_pt( doc.sh, &coord, dir_after, &rp);1373 sheet_get_cell_pt(&doc.sh, &coord, dir_after, &rp); 1523 1374 1524 1375 ch = range_get_str(pt, &rp); … … 1546 1397 1547 1398 coord.column += 1; 1548 sheet_get_cell_pt( doc.sh, &coord, dir_after, &rp);1399 sheet_get_cell_pt(&doc.sh, &coord, dir_after, &rp); 1549 1400 1550 1401 ch = range_get_str(pt, &rp);
Note:
See TracChangeset
for help on using the changeset viewer.