mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
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
This commit is contained in:
parent
b8c470d55f
commit
b8e5440bef
@ -861,8 +861,8 @@ void LyXAction::init()
|
||||
* \li Action: Replace a string in the document.
|
||||
* \li Syntax: word-replace [<DATA>]
|
||||
* \li Params: <DATA>: data is of the form
|
||||
"<search> \n
|
||||
<replace> \n
|
||||
"<replace> \n
|
||||
<search> \n
|
||||
<casesensitive> <matchword> <all> <forward>"
|
||||
* \li Origin: Andre, Jan 7 2004
|
||||
* \endvar
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
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)
|
||||
// <casesensitive> <matchword> <all> <forward>"
|
||||
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);
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user