Fix missing null check from !115247 & simplify

- CTX_wm_region(C) must be NULL checked as it's not checked in the
  poll function.
- Add back the removed flag, note it's dirty.
- Replace ternary operators with min/max.
This commit is contained in:
Campbell Barton 2023-12-01 10:38:37 +11:00
parent 8aff65daf2
commit afa9a6904d
2 changed files with 9 additions and 11 deletions

View File

@ -69,20 +69,16 @@ static int text_text_search_exec(bContext *C, wmOperator * /*op*/)
SpaceText *st = CTX_wm_space_text(C);
if (region) {
ARegion *active_region = CTX_wm_region(C);
Text *text = st->text;
/* Use active text selection as search query, if selection is on a single line. */
if (active_region->regiontype == RGN_TYPE_WINDOW && text && text->curl == text->sell &&
text->curc != text->selc)
{
const char *sel_start = text->curl->line +
(text->curc < text->selc ? text->curc : text->selc);
const int sel_len = std::abs(text->curc - text->selc) + 1;
const int max_copy = sel_len < ST_MAX_FIND_STR ? sel_len : ST_MAX_FIND_STR;
BLI_strncpy(st->findstr, sel_start, max_copy);
if (text && (text->curl == text->sell) && (text->curc != text->selc)) {
const ARegion *active_region = CTX_wm_region(C);
if (active_region && active_region->regiontype == RGN_TYPE_WINDOW) {
const char *sel_start = text->curl->line + std::min(text->curc, text->selc);
const int sel_len = std::abs(text->curc - text->selc);
BLI_strncpy(st->findstr, sel_start, std::min(sel_len + 1, ST_MAX_FIND_STR));
}
}
bool draw = false;

View File

@ -1474,6 +1474,8 @@ typedef enum eSpaceText_Flags {
ST_SHOW_MARGIN = (1 << 7),
ST_MATCH_CASE = (1 << 8),
ST_FLAG_UNUSED_9 = (1 << 9), /* Dirty. */
} eSpaceText_Flags;
/* SpaceText.findstr/replacestr */