From 471c28f91c489d40ae80561ce4d9629d2f152292 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sat, 7 May 2011 17:52:44 +0000 Subject: Fix #27319: Text editor "Find" does not locate words. Added new option to find panel of space text which toggles case-esensitive search. Additional changes: - Send NC_TEXT|NA_EDITED when removing markers in find_and_replace modifier this prevents "sticked" markers which disappears on first redraw when search text wasn't found - Do not show "Text wasn't found" error when text to be searched is contained in the end of buffer and it's selected. Replacing/marking used to happen, but this popup message was really annoying for this case. TODO: It's incorrect to use UI_GetThemeColor4ubv from this operator --- release/scripts/startup/bl_ui/space_text.py | 1 + source/blender/blenkernel/BKE_text.h | 2 +- source/blender/blenkernel/intern/text.c | 8 +++++--- source/blender/editors/space_text/text_ops.c | 17 +++++++++++++---- source/blender/makesdna/DNA_space_types.h | 1 + source/blender/makesrna/intern/rna_space.c | 5 +++++ 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_text.py b/release/scripts/startup/bl_ui/space_text.py index 3d3fc8499af..5b07e8dc37f 100644 --- a/release/scripts/startup/bl_ui/space_text.py +++ b/release/scripts/startup/bl_ui/space_text.py @@ -129,6 +129,7 @@ class TEXT_PT_find(bpy.types.Panel): layout.operator("text.mark_all") # settings + layout.prop(st, "use_match_case") row = layout.row() row.prop(st, "use_find_wrap", text="Wrap") row.prop(st, "use_find_all", text="All") diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 136ce416037..20e5bc27146 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -58,7 +58,7 @@ void write_text(struct Text *text, const char *str); 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 wrap); +int txt_find_string (struct Text *text, char *findstr, int wrap, int match_case); 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); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index ba5d4282416..512914e2c52 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1232,7 +1232,7 @@ char *txt_to_buf (Text *text) return buf; } -int txt_find_string(Text *text, char *findstr, int wrap) +int txt_find_string(Text *text, char *findstr, int wrap, int match_case) { TextLine *tl, *startl; char *s= NULL; @@ -1246,7 +1246,8 @@ int txt_find_string(Text *text, char *findstr, int wrap) oldsl= txt_get_span(text->lines.first, text->sell); tl= startl= text->sell; - s= strstr(&tl->line[text->selc], findstr); + if(match_case) s= strstr(&tl->line[text->selc], findstr); + else s= BLI_strcasestr(&tl->line[text->selc], findstr); while (!s) { tl= tl->next; if (!tl) { @@ -1256,7 +1257,8 @@ int txt_find_string(Text *text, char *findstr, int wrap) break; } - s= strstr(tl->line, findstr); + if(match_case) s= strstr(tl->line, findstr); + else s= BLI_strcasestr(tl->line, findstr); if (tl==startl) break; } diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index c0c928dcb24..e87719084ce 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -2841,8 +2841,14 @@ static int find_and_replace(bContext *C, wmOperator *op, short mode) flags ^= ST_FIND_WRAP; do { - if(first) + int proceed= 0; + + if(first) { + if(text->markers.first) + WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); + txt_clear_markers(text, TMARK_GRP_FINDALL, 0); + } first= 0; @@ -2850,7 +2856,10 @@ static int find_and_replace(bContext *C, wmOperator *op, short mode) if(mode!=TEXT_FIND && txt_has_sel(text)) { tmp= txt_sel_to_buf(text); - if(strcmp(st->findstr, tmp)==0) { + if(flags & ST_MATCH_CASE) proceed= strcmp(st->findstr, tmp)==0; + else proceed= BLI_strcasecmp(st->findstr, tmp)==0; + + if(proceed) { if(mode==TEXT_REPLACE) { txt_insert_buf(text, st->replacestr); if(text->curl && text->curl->format) { @@ -2880,7 +2889,7 @@ static int find_and_replace(bContext *C, wmOperator *op, short mode) } /* Find next */ - if(txt_find_string(text, st->findstr, flags & ST_FIND_WRAP)) { + if(txt_find_string(text, st->findstr, flags & ST_FIND_WRAP, flags & ST_MATCH_CASE)) { text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); } @@ -2897,7 +2906,7 @@ static int find_and_replace(bContext *C, wmOperator *op, short mode) first= 1; } else { - if(!found) BKE_reportf(op->reports, RPT_ERROR, "Text not found: %s", st->findstr); + if(!found && !proceed) BKE_reportf(op->reports, RPT_ERROR, "Text not found: %s", st->findstr); break; } found = 1; diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index 7cb0c9456db..e120cd14775 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -824,6 +824,7 @@ enum { #define ST_FIND_WRAP 0x0020 #define ST_FIND_ALL 0x0040 #define ST_SHOW_MARGIN 0x0080 +#define ST_MATCH_CASE 0x0100 /* stext->findstr/replacestr */ diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 75225f01598..59824d6a752 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -1825,6 +1825,11 @@ static void rna_def_space_text(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Find Wrap", "Search again from the start of the file when reaching the end"); RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL); + prop= RNA_def_property(srna, "use_match_case", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flags", ST_MATCH_CASE); + RNA_def_property_ui_text(prop, "Match case", "Search string is sensitive to uppercase and lowercase letters"); + RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL); + prop= RNA_def_property(srna, "find_text", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "findstr"); RNA_def_property_ui_text(prop, "Find Text", "Text to search for with the find tool"); -- cgit v1.2.3