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
This commit is contained in:
Sergey Sharybin 2011-05-07 17:52:44 +00:00
parent e239085f70
commit 471c28f91c
6 changed files with 26 additions and 8 deletions

@ -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")

@ -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);

@ -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;
}

@ -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;

@ -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 */

@ -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");