mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Ignore tracked deletions in simple replace (#11194)
This commit is contained in:
parent
d87511308b
commit
1b2a56e2d2
@ -1653,20 +1653,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case LFUN_WORD_REPLACE: {
|
case LFUN_WORD_REPLACE: {
|
||||||
bool has_deleted = false;
|
if (lyxreplace(this, cmd)) {
|
||||||
if (cur.selection()) {
|
|
||||||
DocIterator beg = cur.selectionBegin();
|
|
||||||
DocIterator end = cur.selectionEnd();
|
|
||||||
if (beg.pit() == end.pit()) {
|
|
||||||
for (pos_type p = beg.pos() ; p < end.pos() ; ++p) {
|
|
||||||
if (!cur.inMathed() && cur.paragraph().isDeleted(p)) {
|
|
||||||
has_deleted = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lyxreplace(this, cmd, has_deleted)) {
|
|
||||||
dr.forceBufferUpdate();
|
dr.forceBufferUpdate();
|
||||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||||
}
|
}
|
||||||
|
@ -376,7 +376,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
|
|||||||
// This causes a minor bug as undo will restore this selection,
|
// This causes a minor bug as undo will restore this selection,
|
||||||
// which the user did not create (#8986).
|
// which the user did not create (#8986).
|
||||||
cur.innerText()->selectWord(cur, WHOLE_WORD);
|
cur.innerText()->selectWord(cur, WHOLE_WORD);
|
||||||
searchstr = cur.selectionAsString(false);
|
searchstr = cur.selectionAsString(false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we still don't have a search string, report the error
|
// if we still don't have a search string, report the error
|
||||||
@ -385,7 +385,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
|
|||||||
return make_pair(false, 0);
|
return make_pair(false, 0);
|
||||||
|
|
||||||
bool have_selection = cur.selection();
|
bool have_selection = cur.selection();
|
||||||
docstring const selected = cur.selectionAsString(false);
|
docstring const selected = cur.selectionAsString(false, true);
|
||||||
bool match =
|
bool match =
|
||||||
case_sens
|
case_sens
|
||||||
? searchstr == selected
|
? searchstr == selected
|
||||||
@ -468,8 +468,7 @@ bool lyxfind(BufferView * bv, FuncRequest const & ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool lyxreplace(BufferView * bv,
|
bool lyxreplace(BufferView * bv, FuncRequest const & ev)
|
||||||
FuncRequest const & ev, bool has_deleted)
|
|
||||||
{
|
{
|
||||||
if (!bv || ev.action() != LFUN_WORD_REPLACE)
|
if (!bv || ev.action() != LFUN_WORD_REPLACE)
|
||||||
return false;
|
return false;
|
||||||
@ -491,40 +490,31 @@ bool lyxreplace(BufferView * bv,
|
|||||||
|
|
||||||
bool update = false;
|
bool update = false;
|
||||||
|
|
||||||
if (!has_deleted) {
|
int replace_count = 0;
|
||||||
int replace_count = 0;
|
if (all) {
|
||||||
if (all) {
|
replace_count = replaceAll(bv, search, rplc, casesensitive, matchword);
|
||||||
replace_count = replaceAll(bv, search, rplc, casesensitive, matchword);
|
update = replace_count > 0;
|
||||||
update = replace_count > 0;
|
} else {
|
||||||
} else {
|
pair<bool, int> rv =
|
||||||
pair<bool, int> rv =
|
replaceOne(bv, search, rplc, casesensitive, matchword, forward, findnext);
|
||||||
replaceOne(bv, search, rplc, casesensitive, matchword, forward, findnext);
|
update = rv.first;
|
||||||
update = rv.first;
|
replace_count = rv.second;
|
||||||
replace_count = rv.second;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Buffer const & buf = bv->buffer();
|
Buffer const & buf = bv->buffer();
|
||||||
if (!update) {
|
if (!update) {
|
||||||
// emit message signal.
|
// emit message signal.
|
||||||
buf.message(_("String not found."));
|
buf.message(_("String not found."));
|
||||||
|
} else {
|
||||||
|
if (replace_count == 0) {
|
||||||
|
buf.message(_("String found."));
|
||||||
|
} else if (replace_count == 1) {
|
||||||
|
buf.message(_("String has been replaced."));
|
||||||
} else {
|
} else {
|
||||||
if (replace_count == 0) {
|
docstring const str =
|
||||||
buf.message(_("String found."));
|
bformat(_("%1$d strings have been replaced."), replace_count);
|
||||||
} else if (replace_count == 1) {
|
buf.message(str);
|
||||||
buf.message(_("String has been replaced."));
|
|
||||||
} else {
|
|
||||||
docstring const str =
|
|
||||||
bformat(_("%1$d strings have been replaced."), replace_count);
|
|
||||||
buf.message(str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (findnext) {
|
|
||||||
// if we have deleted characters, we do not replace at all, but
|
|
||||||
// rather search for the next occurence
|
|
||||||
if (findOne(bv, search, casesensitive, matchword, forward, true, findnext))
|
|
||||||
update = true;
|
|
||||||
else
|
|
||||||
bv->message(_("String not found."));
|
|
||||||
}
|
}
|
||||||
return update;
|
return update;
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,7 @@ bool lyxfind(BufferView * bv, FuncRequest const & ev);
|
|||||||
* The string is encoded by \c replace2string.
|
* The string is encoded by \c replace2string.
|
||||||
* \return whether we did anything
|
* \return whether we did anything
|
||||||
*/
|
*/
|
||||||
bool lyxreplace(BufferView * bv,
|
bool lyxreplace(BufferView * bv, FuncRequest const &);
|
||||||
FuncRequest const &, bool has_deleted = false);
|
|
||||||
|
|
||||||
/// find the next change in the buffer
|
/// find the next change in the buffer
|
||||||
bool findNextChange(BufferView * bv);
|
bool findNextChange(BufferView * bv);
|
||||||
|
Loading…
Reference in New Issue
Block a user