mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-12 19:38:18 +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
447254eb59
commit
5c4fa40849
@ -1509,14 +1509,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
|||||||
docstring const data =
|
docstring const data =
|
||||||
find2string(searched_string, true, false, fw);
|
find2string(searched_string, true, false, fw);
|
||||||
bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
|
bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
|
||||||
if (found) {
|
if (found)
|
||||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||||
cur.dispatched();
|
|
||||||
dispatched = true;
|
|
||||||
} else {
|
|
||||||
cur.undispatched();
|
|
||||||
dispatched = false;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1528,14 +1522,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
|||||||
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
|
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (lyxfind(this, req)) {
|
if (lyxfind(this, req))
|
||||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||||
cur.dispatched();
|
|
||||||
dispatched = true;
|
|
||||||
} else {
|
|
||||||
cur.undispatched();
|
|
||||||
dispatched = false;
|
|
||||||
}
|
|
||||||
d->search_request_cache_ = req;
|
d->search_request_cache_ = req;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1557,11 +1546,6 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
|||||||
if (lyxreplace(this, cmd, has_deleted)) {
|
if (lyxreplace(this, cmd, has_deleted)) {
|
||||||
dr.forceBufferUpdate();
|
dr.forceBufferUpdate();
|
||||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||||
cur.dispatched();
|
|
||||||
dispatched = true;
|
|
||||||
} else {
|
|
||||||
cur.undispatched();
|
|
||||||
dispatched = false;
|
|
||||||
}
|
}
|
||||||
break;
|
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,
|
void GuiSearch::find(docstring const & search, bool casesensitive,
|
||||||
bool matchword, bool forward)
|
bool matchword, bool forward)
|
||||||
{
|
{
|
||||||
docstring const data =
|
docstring const data =
|
||||||
find2string(search, casesensitive, matchword, forward);
|
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 =
|
docstring const data =
|
||||||
replace2string(replace, search, casesensitive,
|
replace2string(replace, search, casesensitive,
|
||||||
matchword, all, forward);
|
matchword, all, forward);
|
||||||
wrap_dispatch(FuncRequest(LFUN_WORD_REPLACE, data), forward);
|
dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,9 +40,6 @@ private:
|
|||||||
void dispatchParams() {}
|
void dispatchParams() {}
|
||||||
bool isBufferDependent() const { return true; }
|
bool isBufferDependent() const { return true; }
|
||||||
|
|
||||||
/// Dispatches repeatedly func with wrap around question
|
|
||||||
void wrap_dispatch(const FuncRequest & func, bool forward);
|
|
||||||
|
|
||||||
/// Searches occurence of string
|
/// Searches occurence of string
|
||||||
void find(docstring const & search,
|
void find(docstring const & search,
|
||||||
bool casesensitive, bool matchword, bool forward);
|
bool casesensitive, bool matchword, bool forward);
|
||||||
|
@ -346,7 +346,7 @@ void SpellcheckerWidget::Private::setSelection(
|
|||||||
int const size = end.pos() - from.pos();
|
int const size = end.pos() - from.pos();
|
||||||
bv->putSelectionAt(from, size, false);
|
bv->putSelectionAt(from, size, false);
|
||||||
}
|
}
|
||||||
bv->processUpdateFlags(Update::Force | Update::FitCursor);
|
bv->processUpdateFlags(Update::Force | Update::FitCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpellcheckerWidget::Private::forward()
|
void SpellcheckerWidget::Private::forward()
|
||||||
@ -490,6 +490,8 @@ void SpellcheckerWidget::on_replaceAllPB_clicked()
|
|||||||
LYXERR(Debug::GUI, "Replace all (" << replacement << ")");
|
LYXERR(Debug::GUI, "Replace all (" << replacement << ")");
|
||||||
dispatch(FuncRequest(LFUN_WORD_REPLACE, datastring));
|
dispatch(FuncRequest(LFUN_WORD_REPLACE, datastring));
|
||||||
d->forward();
|
d->forward();
|
||||||
|
// replace all wraps around
|
||||||
|
d->wrapAround(true);
|
||||||
d->check(); // continue spellchecking
|
d->check(); // continue spellchecking
|
||||||
d->canCheck();
|
d->canCheck();
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,8 @@ bool searchAllowed(docstring const & str)
|
|||||||
|
|
||||||
|
|
||||||
bool findOne(BufferView * bv, docstring const & searchstr,
|
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))
|
if (!searchAllowed(searchstr))
|
||||||
return false;
|
return false;
|
||||||
@ -149,6 +150,32 @@ bool findOne(BufferView * bv, docstring const & searchstr,
|
|||||||
|
|
||||||
if (match_len > 0)
|
if (match_len > 0)
|
||||||
bv->putSelectionAt(cur, match_len, !forward);
|
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;
|
return match_len > 0;
|
||||||
}
|
}
|
||||||
@ -221,11 +248,12 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
|
|||||||
bool whole, bool forward, bool findnext)
|
bool whole, bool forward, bool findnext)
|
||||||
{
|
{
|
||||||
Cursor & cur = bv->cursor();
|
Cursor & cur = bv->cursor();
|
||||||
|
bool found = false;
|
||||||
if (!cur.selection()) {
|
if (!cur.selection()) {
|
||||||
// no selection, non-empty search string: find it
|
// no selection, non-empty search string: find it
|
||||||
if (!searchstr.empty()) {
|
if (!searchstr.empty()) {
|
||||||
findOne(bv, searchstr, case_sens, whole, forward);
|
found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
|
||||||
return make_pair(true, 0);
|
return make_pair(found, 0);
|
||||||
}
|
}
|
||||||
// empty search string
|
// empty search string
|
||||||
if (!cur.inTexted())
|
if (!cur.inTexted())
|
||||||
@ -253,8 +281,8 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
|
|||||||
// no selection or current selection is not search word:
|
// no selection or current selection is not search word:
|
||||||
// just find the search word
|
// just find the search word
|
||||||
if (!have_selection || !match) {
|
if (!have_selection || !match) {
|
||||||
findOne(bv, searchstr, case_sens, whole, forward);
|
found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
|
||||||
return make_pair(true, 0);
|
return make_pair(found, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we're now actually ready to replace. if the buffer is
|
// 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());
|
cur.pos() = cur.lastpos());
|
||||||
}
|
}
|
||||||
if (findnext)
|
if (findnext)
|
||||||
findOne(bv, searchstr, case_sens, whole, forward, false);
|
findOne(bv, searchstr, case_sens, whole, forward, false, findnext);
|
||||||
|
|
||||||
return make_pair(true, 1);
|
return make_pair(true, 1);
|
||||||
}
|
}
|
||||||
@ -323,7 +351,7 @@ bool lyxfind(BufferView * bv, FuncRequest const & ev)
|
|||||||
bool matchword = parse_bool(howto);
|
bool matchword = parse_bool(howto);
|
||||||
bool forward = 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) {
|
} else if (findnext) {
|
||||||
// if we have deleted characters, we do not replace at all, but
|
// if we have deleted characters, we do not replace at all, but
|
||||||
// rather search for the next occurence
|
// rather search for the next occurence
|
||||||
if (findOne(bv, search, casesensitive, matchword, forward))
|
if (findOne(bv, search, casesensitive, matchword, forward, true, findnext))
|
||||||
update = true;
|
update = true;
|
||||||
else
|
else
|
||||||
bv->message(_("String not found."));
|
bv->message(_("String not found."));
|
||||||
|
@ -56,6 +56,8 @@ What's new
|
|||||||
|
|
||||||
* USER INTERFACE
|
* USER INTERFACE
|
||||||
|
|
||||||
|
- Fix wrap-around on (simple) replace and in the spellchecker (bug 10378).
|
||||||
|
|
||||||
- Fix logic of OK/Apply buttons in cross-references dialog (bug 10376).
|
- Fix logic of OK/Apply buttons in cross-references dialog (bug 10376).
|
||||||
|
|
||||||
- Fix display of Examples and Sub-Examples labels in linguistics module.
|
- Fix display of Examples and Sub-Examples labels in linguistics module.
|
||||||
|
Loading…
Reference in New Issue
Block a user