Changeset 8312577 in mainline
- Timestamp:
- 2012-08-17T11:44:43Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1d5a540
- Parents:
- 2f136e4
- Location:
- uspace/app/edit
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r2f136e4 r8312577 87 87 88 88 char *previous_search; 89 bool previous_search_reverse; 89 90 } pane_t; 90 91 … … 159 160 static void insert_clipboard_data(void); 160 161 161 static void search( void);162 static void search_ forward(char *pattern);162 static void search(char *pattern, bool reverse); 163 static void search_prompt(bool reverse); 163 164 static void search_repeat(void); 164 165 … … 417 418 break; 418 419 case KC_F: 419 search ();420 search_prompt(false); 420 421 break; 421 422 case KC_N: … … 435 436 case KC_RIGHT: 436 437 caret_move_word_right(true); 438 break; 439 case KC_F: 440 search_prompt(true); 437 441 break; 438 442 default: … … 1161 1165 } 1162 1166 1167 static int search_spt_reverse_producer(void *data, wchar_t *ret) 1168 { 1169 assert(data != NULL); 1170 assert(ret != NULL); 1171 spt_t *spt = data; 1172 *ret = spt_prev_char(*spt, spt); 1173 return EOK; 1174 } 1175 1163 1176 static int search_spt_mark(void *data, void **mark) 1164 1177 { … … 1186 1199 }; 1187 1200 1201 static search_ops_t search_spt_reverse_ops = { 1202 .equals = char_exact_equals, 1203 .producer = search_spt_reverse_producer, 1204 .mark = search_spt_mark, 1205 .mark_free = search_spt_mark_free, 1206 }; 1207 1188 1208 /** Ask for line and go to it. */ 1189 static void search (void)1209 static void search_prompt(bool reverse) 1190 1210 { 1191 1211 char *pattern; 1212 1213 const char *prompt_text = "Find next"; 1214 if (reverse) 1215 prompt_text = "Find previous"; 1192 1216 1193 1217 const char *default_value = ""; … … 1195 1219 default_value = pane.previous_search; 1196 1220 1197 pattern = prompt( "Search for", default_value);1221 pattern = prompt(prompt_text, default_value); 1198 1222 if (pattern == NULL) { 1199 1223 status_display("Search cancelled."); … … 1204 1228 free(pane.previous_search); 1205 1229 pane.previous_search = pattern; 1206 1207 search_forward(pattern); 1230 pane.previous_search_reverse = reverse; 1231 1232 search(pattern, reverse); 1208 1233 } 1209 1234 … … 1215 1240 } 1216 1241 1217 search _forward(pane.previous_search);1218 } 1219 1220 static void search _forward(char *pattern)1242 search(pane.previous_search, pane.previous_search_reverse); 1243 } 1244 1245 static void search(char *pattern, bool reverse) 1221 1246 { 1222 1247 status_display("Searching..."); … … 1225 1250 tag_get_pt(&pane.caret_pos, &sp); 1226 1251 1227 /* Start searching on the position after caret */ 1228 spt_next_char(sp, &sp); 1252 /* Start searching on the position before/after caret */ 1253 if (!reverse) { 1254 spt_next_char(sp, &sp); 1255 } 1256 else { 1257 spt_prev_char(sp, &sp); 1258 } 1229 1259 producer_pos = sp; 1230 1260 1231 search_t *search = search_init(pattern, &producer_pos, search_spt_ops); 1261 search_ops_t ops = search_spt_ops; 1262 if (reverse) 1263 ops = search_spt_reverse_ops; 1264 1265 search_t *search = search_init(pattern, &producer_pos, ops, reverse); 1232 1266 if (search == NULL) { 1233 1267 status_display("Failed initializing search."); … … 1249 1283 while (match.length > 0) { 1250 1284 match.length--; 1251 spt_prev_char(*end, end); 1285 if (reverse) { 1286 spt_next_char(*end, end); 1287 } 1288 else { 1289 spt_prev_char(*end, end); 1290 } 1252 1291 } 1253 1292 caret_move(*end, true, true); -
uspace/app/edit/search.c
r2f136e4 r8312577 41 41 #include "search_impl.h" 42 42 43 search_t *search_init(const char *pattern, void *client_data, search_ops_t ops) 43 search_t *search_init(const char *pattern, void *client_data, search_ops_t ops, 44 bool reverse) 44 45 { 45 46 search_t *search = calloc(1, sizeof(search_t)); … … 47 48 return NULL; 48 49 49 search->pattern= str_to_awstr(pattern);50 if ( search->pattern== NULL) {50 wchar_t *p = str_to_awstr(pattern); 51 if (p == NULL) { 51 52 free(search); 52 53 return NULL; 53 54 } 54 55 56 search->pattern_length = wstr_length(p); 57 58 if (reverse) { 59 /* Reverse the pattern */ 60 size_t pos, half; 61 half = search->pattern_length / 2; 62 for (pos = 0; pos < half; pos++) { 63 wchar_t tmp = p[pos]; 64 p[pos] = p[search->pattern_length - pos - 1]; 65 p[search->pattern_length - pos - 1] = tmp; 66 } 67 } 68 69 search->pattern = p; 70 55 71 search->client_data = client_data; 56 72 search->ops = ops; 57 search->pattern_length = wstr_length(search->pattern);58 73 search->back_table = calloc(search->pattern_length, sizeof(ssize_t)); 59 74 if (search->back_table == NULL) { -
uspace/app/edit/search.h
r2f136e4 r8312577 59 59 60 60 extern bool char_exact_equals(const wchar_t, const wchar_t); 61 extern search_t *search_init(const char *, void *, search_ops_t );61 extern search_t *search_init(const char *, void *, search_ops_t, bool); 62 62 extern int search_next_match(search_t *, match_t *); 63 63 extern void search_fini(search_t *);
Note:
See TracChangeset
for help on using the changeset viewer.