diff options
author | Ian Thompson <quornian@googlemail.com> | 2008-07-23 23:35:13 +0400 |
---|---|---|
committer | Ian Thompson <quornian@googlemail.com> | 2008-07-23 23:35:13 +0400 |
commit | 3b70337f7f247f8f394992c57c835b65fee25c03 (patch) | |
tree | fbcb5c5fb47619dc98fa402a95907e2fada9ae79 /source/blender/blenkernel | |
parent | 16ebff308e5813117a49c4bd5a45617103a66d93 (diff) |
Improvements to text find (and replace):
- Added GUI panel
- Selected text is copied to "find" field
- Option to search "all texts"
- Option to replace text
- Alt+F finds, Ctrl+Alt+F finds again (without UI)
- Alt+H replaces (UI), Ctrl+Alt+H replaces again (and undo works)
- Fixed: Find didn't push undos so cursor position was wrong
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 23 |
2 files changed, 23 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 10223589859..abdf32c8ea5 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -52,7 +52,7 @@ void txt_free_cut_buffer (void); char* txt_to_buf (struct Text *text); void txt_clean_text (struct Text *text); void txt_order_cursors (struct Text *text); -int txt_find_string (struct Text *text, char *findstr); +int txt_find_string (struct Text *text, char *findstr, int wrap); int txt_has_sel (struct Text *text); int txt_get_span (struct TextLine *from, struct TextLine *to); void txt_move_up (struct Text *text, short sel); @@ -87,7 +87,7 @@ void txt_backspace_char (struct Text *text); void txt_backspace_word (struct Text *text); int txt_add_char (struct Text *text, char add); int txt_replace_char (struct Text *text, char add); -void txt_find_panel (struct SpaceText *st, int again); +void txt_find_panel (struct SpaceText *st, int again, int flags); void run_python_script (struct SpaceText *st); int jumptoline_interactive (struct SpaceText *st); void txt_export_to_object (struct Text *text); @@ -141,6 +141,11 @@ void txt_paste_clipboard (struct Text *text); #define UNDO_COMMENT 034 #define UNDO_UNCOMMENT 035 +/* Find and replace flags */ +#define TXT_FIND_REPLACE 0x01 +#define TXT_FIND_ALLTEXTS 0x02 +#define TXT_FIND_WRAP 0x04 + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 5c1ec1b4008..4291150f443 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1080,22 +1080,31 @@ char *txt_to_buf (Text *text) return buf; } -int txt_find_string(Text *text, char *findstr) +int txt_find_string(Text *text, char *findstr, int wrap) { TextLine *tl, *startl; char *s= NULL; + int oldcl, oldsl, oldcc, oldsc; if (!text || !text->curl || !text->sell) return 0; txt_order_cursors(text); + oldcl= txt_get_span(text->lines.first, text->curl); + oldsl= txt_get_span(text->lines.first, text->sell); tl= startl= text->sell; + oldcc= text->curc; + oldsc= text->selc; s= strstr(&tl->line[text->selc], findstr); while (!s) { tl= tl->next; - if (!tl) - tl= text->lines.first; + if (!tl) { + if (wrap) + tl= text->lines.first; + else + break; + } s= strstr(tl->line, findstr); if (tl==startl) @@ -1103,10 +1112,10 @@ int txt_find_string(Text *text, char *findstr) } if (s) { - text->curl= text->sell= tl; - text->curc= (int) (s-tl->line); - text->selc= text->curc + strlen(findstr); - + int newl= txt_get_span(text->lines.first, tl); + int newc= (int)(s-tl->line); + txt_move_to(text, newl, newc, 0); + txt_move_to(text, newl, newc + strlen(findstr), 1); return 1; } else return 0; |