- if (text->selection.set())
- text->cursor = text->selection.end;
-
- text->clearSelection();
-
- return nextChange(bv, text, length);
+ if (!bv || ev.action != LFUN_WORD_REPLACE)
+ return;
+
+ // data is of the form
+ // "<search>
+ // <replace>
+ // <casesensitive> <matchword> <all> <forward>"
+ docstring search;
+ docstring rplc;
+ docstring howto = split(ev.argument(), search, '\n');
+ howto = split(howto, rplc, '\n');
+
+ bool casesensitive = parse_bool(howto);
+ bool matchword = parse_bool(howto);
+ bool all = parse_bool(howto);
+ bool forward = parse_bool(howto);
+
+ Buffer * buf = bv->buffer();
+
+ int const replace_count = all
+ ? replaceAll(bv, search, rplc, casesensitive, matchword)
+ : replace(bv, search, rplc, casesensitive, matchword, forward);
+
+ if (replace_count == 0) {
+ // emit message signal.
+ buf->message(_("String not found!"));
+ } else {
+ if (replace_count == 1) {
+ // emit message signal.
+ buf->message(_("String has been replaced."));
+ } else {
+ docstring str = convert<docstring>(replace_count);
+ str += _(" strings have been replaced.");
+ // emit message signal.
+ buf->message(str);
+ }
+ }