- if(text_search(text, searchstr, pos, backwards, cs, enable_regex ? ®ex : NULL, &begin, &end)) {
- note->text->setposition(note->text, end);
- note->text->setselection(note->text, begin, end);
- note->text->showposition(note->text, begin);
+ regmatch_t match[32];
+ if(text_search_match(text, searchstr, pos, backwards, cs, enable_regex ? ®ex : NULL, &begin, &end, match, 32)) {
+ if(!replace) {
+ note->text->setposition(note->text, end);
+ note->text->setselection(note->text, begin, end);
+ note->text->showposition(note->text, begin);
+ } else {
+ cxstring tpl_str = cx_str(ui_get(note->replace));
+ StringTemplate *tpl = string_template_compile(cxDefaultAllocator, tpl_str);
+ TplStringBuildData data;
+ data.match = match;
+ data.nmatch = 32;
+ data.text = text;
+ cxmutstr replacement = string_template_build_string(tpl, cxDefaultAllocator, get_group, &data);
+ note->text->replace(note->text, begin, end, replacement.ptr);
+ free(replacement.ptr);
+ string_template_free(tpl);
+ }