From b8e5440bef5cfa3b0beadc4ef9d71980e37f2214 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sat, 4 Jul 2009 23:02:27 +0000 Subject: [PATCH] LFUN_WORD_REPLACE: Invert replacement and searched strings in the FuncRequest argument. This is to allow replacement of current word even if it is not selected. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30360 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXAction.cpp | 4 ++-- src/frontends/qt4/GuiSearch.cpp | 2 +- src/frontends/qt4/GuiSpellchecker.cpp | 2 +- src/frontends/qt4/GuiThesaurus.cpp | 2 +- src/lyxfind.cpp | 30 +++++++++++++++++---------- src/lyxfind.h | 4 ++-- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 0d80f5e316..f4a7e31569 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -861,8 +861,8 @@ void LyXAction::init() * \li Action: Replace a string in the document. * \li Syntax: word-replace [] * \li Params: : data is of the form - " \n - \n + " \n + \n " * \li Origin: Andre, Jan 7 2004 * \endvar diff --git a/src/frontends/qt4/GuiSearch.cpp b/src/frontends/qt4/GuiSearch.cpp index 7a095d5ec2..a8f10e7c63 100644 --- a/src/frontends/qt4/GuiSearch.cpp +++ b/src/frontends/qt4/GuiSearch.cpp @@ -129,7 +129,7 @@ void GuiSearch::replace(docstring const & search, docstring const & replace, bool forward, bool all) { docstring const data = - replace2string(search, replace, casesensitive, + replace2string(replace, search, casesensitive, matchword, all, forward); dispatch(FuncRequest(LFUN_WORD_REPLACE, data)); } diff --git a/src/frontends/qt4/GuiSpellchecker.cpp b/src/frontends/qt4/GuiSpellchecker.cpp index aacac46dc9..73e1254ee1 100644 --- a/src/frontends/qt4/GuiSpellchecker.cpp +++ b/src/frontends/qt4/GuiSpellchecker.cpp @@ -176,8 +176,8 @@ void GuiSpellchecker::on_replacePB_clicked() void GuiSpellchecker::on_replaceAllPB_clicked() { docstring const data = replace2string( - qstring_to_ucs4(d->ui.wordED->text()), qstring_to_ucs4(d->ui.replaceCO->currentText()), + qstring_to_ucs4(d->ui.wordED->text()), true, true, true, true); dispatch(FuncRequest(LFUN_WORD_REPLACE, data)); } diff --git a/src/frontends/qt4/GuiThesaurus.cpp b/src/frontends/qt4/GuiThesaurus.cpp index 413be69e53..6d6269e6f5 100644 --- a/src/frontends/qt4/GuiThesaurus.cpp +++ b/src/frontends/qt4/GuiThesaurus.cpp @@ -247,7 +247,7 @@ void GuiThesaurus::replace(docstring const & newstr) * deletion/change ! */ docstring const data = - replace2string(text_, newstr, + replace2string(newstr, text_, true, // case sensitive true, // match word false, // all words diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index e3c237bf90..5c26645075 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -202,9 +202,17 @@ int replaceAll(BufferView * bv, } -bool stringSelected(BufferView * bv, docstring const & searchstr, +bool stringSelected(BufferView * bv, docstring & searchstr, bool cs, bool mw, bool fw) { + // if nothing selected and searched string is empty, this + // means that we want to search current word at cursor position. + if (!bv->cursor().selection() && searchstr.empty()) { + bv->cursor().innerText()->selectWord(bv->cursor(), WHOLE_WORD); + searchstr = bv->cursor().selectionAsString(false); + return true; + } + // if nothing selected or selection does not equal search // string search and select next occurance and return docstring const & str1 = searchstr; @@ -218,13 +226,13 @@ bool stringSelected(BufferView * bv, docstring const & searchstr, } -int replace(BufferView * bv, docstring const & searchstr, +int replace(BufferView * bv, docstring & searchstr, docstring const & replacestr, bool cs, bool mw, bool fw) { - if (!searchAllowed(bv, searchstr) || bv->buffer().isReadonly()) + if (!stringSelected(bv, searchstr, cs, mw, fw)) return 0; - if (!stringSelected(bv, searchstr, cs, mw, fw)) + if (!searchAllowed(bv, searchstr) || bv->buffer().isReadonly()) return 0; Cursor & cur = bv->cursor(); @@ -252,13 +260,13 @@ docstring const find2string(docstring const & search, } -docstring const replace2string(docstring const & search, docstring const & replace, - bool casesensitive, bool matchword, - bool all, bool forward) +docstring const replace2string(docstring const & replace, + docstring const & search, bool casesensitive, bool matchword, + bool all, bool forward) { odocstringstream ss; - ss << search << '\n' - << replace << '\n' + ss << replace << '\n' + << search << '\n' << int(casesensitive) << ' ' << int(matchword) << ' ' << int(all) << ' ' @@ -299,8 +307,8 @@ void replace(BufferView * bv, FuncRequest const & ev, bool has_deleted) // " docstring search; docstring rplc; - docstring howto = split(ev.argument(), search, '\n'); - howto = split(howto, rplc, '\n'); + docstring howto = split(ev.argument(), rplc, '\n'); + howto = split(howto, search, '\n'); bool casesensitive = parse_bool(howto); bool matchword = parse_bool(howto); diff --git a/src/lyxfind.h b/src/lyxfind.h index 9dc17df86b..57849d28f6 100644 --- a/src/lyxfind.h +++ b/src/lyxfind.h @@ -43,8 +43,8 @@ docstring const find2string(docstring const & search, * as a string that can be dispatched to the LyX core in a FuncRequest * wrapper. */ -docstring const replace2string(docstring const & search, - docstring const & replace, +docstring const replace2string(docstring const & replace, + docstring const & search, bool casesensitive, bool matchword, bool all,