mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Move wrap check for simple search/replace to lyxfind
This gets rid of some dirty dispatch tricks and fixes wrap-around on replace and in the spellchecker Fixes: #10378
This commit is contained in:
parent
72cf7c8f1f
commit
c0a425a319
@ -1523,14 +1523,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
docstring const data =
|
||||
find2string(searched_string, true, false, fw);
|
||||
bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
|
||||
if (found) {
|
||||
if (found)
|
||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||
cur.dispatched();
|
||||
dispatched = true;
|
||||
} else {
|
||||
cur.undispatched();
|
||||
dispatched = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1542,14 +1536,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
|
||||
break;
|
||||
}
|
||||
if (lyxfind(this, req)) {
|
||||
if (lyxfind(this, req))
|
||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||
cur.dispatched();
|
||||
dispatched = true;
|
||||
} else {
|
||||
cur.undispatched();
|
||||
dispatched = false;
|
||||
}
|
||||
|
||||
d->search_request_cache_ = req;
|
||||
break;
|
||||
}
|
||||
@ -1571,11 +1560,6 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
if (lyxreplace(this, cmd, has_deleted)) {
|
||||
dr.forceBufferUpdate();
|
||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||
cur.dispatched();
|
||||
dispatched = true;
|
||||
} else {
|
||||
cur.undispatched();
|
||||
dispatched = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -120,49 +120,12 @@ void GuiSearch::replaceallClicked()
|
||||
}
|
||||
|
||||
|
||||
void GuiSearch::wrap_dispatch(const FuncRequest & func, bool forward)
|
||||
{
|
||||
dispatch(func);
|
||||
|
||||
BufferView * bv = const_cast<BufferView *>(bufferview());
|
||||
|
||||
if (!bv->cursor().result().dispatched()) {
|
||||
GuiView & lv = *const_cast<GuiView *>(&lyxview());
|
||||
DocIterator cur_orig(bv->cursor());
|
||||
docstring q;
|
||||
if (forward)
|
||||
q = _("End of file reached while searching forward.\n"
|
||||
"Continue searching from the beginning?");
|
||||
else
|
||||
q = _("Beginning of file reached while searching backward.\n"
|
||||
"Continue searching from the end?");
|
||||
int wrap_answer = frontend::Alert::prompt(_("Wrap search?"),
|
||||
q, 0, 1, _("&Yes"), _("&No"));
|
||||
if (wrap_answer == 0) {
|
||||
if (forward) {
|
||||
bv->cursor().clear();
|
||||
bv->cursor().push_back(CursorSlice(bv->buffer().inset()));
|
||||
} else {
|
||||
bv->cursor().setCursor(doc_iterator_end(&bv->buffer()));
|
||||
bv->cursor().backwardPos();
|
||||
}
|
||||
bv->clearSelection();
|
||||
dispatch(func);
|
||||
if (bv->cursor().result().dispatched())
|
||||
return;
|
||||
}
|
||||
bv->cursor().setCursor(cur_orig);
|
||||
lv.message(_("String not found."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GuiSearch::find(docstring const & search, bool casesensitive,
|
||||
bool matchword, bool forward)
|
||||
{
|
||||
docstring const data =
|
||||
find2string(search, casesensitive, matchword, forward);
|
||||
wrap_dispatch(FuncRequest(LFUN_WORD_FIND, data), forward);
|
||||
dispatch(FuncRequest(LFUN_WORD_FIND, data));
|
||||
}
|
||||
|
||||
|
||||
@ -173,7 +136,7 @@ void GuiSearch::replace(docstring const & search, docstring const & replace,
|
||||
docstring const data =
|
||||
replace2string(replace, search, casesensitive,
|
||||
matchword, all, forward);
|
||||
wrap_dispatch(FuncRequest(LFUN_WORD_REPLACE, data), forward);
|
||||
dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,9 +40,6 @@ private:
|
||||
void dispatchParams() {}
|
||||
bool isBufferDependent() const { return true; }
|
||||
|
||||
/// Dispatches repeatedly func with wrap around question
|
||||
void wrap_dispatch(const FuncRequest & func, bool forward);
|
||||
|
||||
/// Searches occurence of string
|
||||
void find(docstring const & search,
|
||||
bool casesensitive, bool matchword, bool forward);
|
||||
|
@ -346,7 +346,7 @@ void SpellcheckerWidget::Private::setSelection(
|
||||
int const size = end.pos() - from.pos();
|
||||
bv->putSelectionAt(from, size, false);
|
||||
}
|
||||
bv->processUpdateFlags(Update::Force | Update::FitCursor);
|
||||
bv->processUpdateFlags(Update::Force | Update::FitCursor);
|
||||
}
|
||||
|
||||
void SpellcheckerWidget::Private::forward()
|
||||
@ -490,6 +490,8 @@ void SpellcheckerWidget::on_replaceAllPB_clicked()
|
||||
LYXERR(Debug::GUI, "Replace all (" << replacement << ")");
|
||||
dispatch(FuncRequest(LFUN_WORD_REPLACE, datastring));
|
||||
d->forward();
|
||||
// replace all wraps around
|
||||
d->wrapAround(true);
|
||||
d->check(); // continue spellchecking
|
||||
d->canCheck();
|
||||
}
|
||||
|
@ -132,7 +132,8 @@ bool searchAllowed(docstring const & str)
|
||||
|
||||
|
||||
bool findOne(BufferView * bv, docstring const & searchstr,
|
||||
bool case_sens, bool whole, bool forward, bool find_del = true)
|
||||
bool case_sens, bool whole, bool forward,
|
||||
bool find_del = true, bool check_wrap = false)
|
||||
{
|
||||
if (!searchAllowed(searchstr))
|
||||
return false;
|
||||
@ -149,6 +150,32 @@ bool findOne(BufferView * bv, docstring const & searchstr,
|
||||
|
||||
if (match_len > 0)
|
||||
bv->putSelectionAt(cur, match_len, !forward);
|
||||
else if (check_wrap) {
|
||||
DocIterator cur_orig(bv->cursor());
|
||||
docstring q;
|
||||
if (forward)
|
||||
q = _("End of file reached while searching forward.\n"
|
||||
"Continue searching from the beginning?");
|
||||
else
|
||||
q = _("Beginning of file reached while searching backward.\n"
|
||||
"Continue searching from the end?");
|
||||
int wrap_answer = frontend::Alert::prompt(_("Wrap search?"),
|
||||
q, 0, 1, _("&Yes"), _("&No"));
|
||||
if (wrap_answer == 0) {
|
||||
if (forward) {
|
||||
bv->cursor().clear();
|
||||
bv->cursor().push_back(CursorSlice(bv->buffer().inset()));
|
||||
} else {
|
||||
bv->cursor().setCursor(doc_iterator_end(&bv->buffer()));
|
||||
bv->cursor().backwardPos();
|
||||
}
|
||||
bv->clearSelection();
|
||||
if (findOne(bv, searchstr, case_sens, whole, forward, find_del, false))
|
||||
return true;
|
||||
}
|
||||
bv->cursor().setCursor(cur_orig);
|
||||
return false;
|
||||
}
|
||||
|
||||
return match_len > 0;
|
||||
}
|
||||
@ -221,11 +248,12 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
|
||||
bool whole, bool forward, bool findnext)
|
||||
{
|
||||
Cursor & cur = bv->cursor();
|
||||
bool found = false;
|
||||
if (!cur.selection()) {
|
||||
// no selection, non-empty search string: find it
|
||||
if (!searchstr.empty()) {
|
||||
findOne(bv, searchstr, case_sens, whole, forward);
|
||||
return make_pair(true, 0);
|
||||
found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
|
||||
return make_pair(found, 0);
|
||||
}
|
||||
// empty search string
|
||||
if (!cur.inTexted())
|
||||
@ -253,8 +281,8 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
|
||||
// no selection or current selection is not search word:
|
||||
// just find the search word
|
||||
if (!have_selection || !match) {
|
||||
findOne(bv, searchstr, case_sens, whole, forward);
|
||||
return make_pair(true, 0);
|
||||
found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
|
||||
return make_pair(found, 0);
|
||||
}
|
||||
|
||||
// we're now actually ready to replace. if the buffer is
|
||||
@ -269,7 +297,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
|
||||
cur.pos() = cur.lastpos());
|
||||
}
|
||||
if (findnext)
|
||||
findOne(bv, searchstr, case_sens, whole, forward, false);
|
||||
findOne(bv, searchstr, case_sens, whole, forward, false, findnext);
|
||||
|
||||
return make_pair(true, 1);
|
||||
}
|
||||
@ -323,7 +351,7 @@ bool lyxfind(BufferView * bv, FuncRequest const & ev)
|
||||
bool matchword = parse_bool(howto);
|
||||
bool forward = parse_bool(howto);
|
||||
|
||||
return findOne(bv, search, casesensitive, matchword, forward);
|
||||
return findOne(bv, search, casesensitive, matchword, forward, true, true);
|
||||
}
|
||||
|
||||
|
||||
@ -380,7 +408,7 @@ bool lyxreplace(BufferView * bv,
|
||||
} 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))
|
||||
if (findOne(bv, search, casesensitive, matchword, forward, true, findnext))
|
||||
update = true;
|
||||
else
|
||||
bv->message(_("String not found."));
|
||||
|
Loading…
Reference in New Issue
Block a user