From fb4dfdf189bcd91eda67fa350ab1daf98f2bf1c8 Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Sat, 9 Jan 2010 12:39:29 +0000 Subject: [PATCH] Implemented "whose words" option of the Advanced F&R feature. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32905 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/ui/FindAndReplaceUi.ui | 115 ++++++----------------- src/lyxfind.cpp | 25 ++++- 2 files changed, 54 insertions(+), 86 deletions(-) diff --git a/src/frontends/qt4/ui/FindAndReplaceUi.ui b/src/frontends/qt4/ui/FindAndReplaceUi.ui index 686d39e44c..1d36e167f1 100644 --- a/src/frontends/qt4/ui/FindAndReplaceUi.ui +++ b/src/frontends/qt4/ui/FindAndReplaceUi.ui @@ -1,3 +1,4 @@ + FindAndReplaceUi @@ -10,9 +11,7 @@ - - 1 - 7 + 0 0 @@ -60,9 +59,7 @@ - - 7 - 7 + 0 0 @@ -84,9 +81,7 @@ - - 5 - 7 + 0 0 @@ -104,9 +99,7 @@ - - 7 - 7 + 0 0 @@ -130,9 +123,7 @@ - - 7 - 7 + 0 0 @@ -189,9 +180,7 @@ - - 7 - 7 + 0 0 @@ -205,9 +194,7 @@ true - - 7 - 1 + 1 0 @@ -226,9 +213,7 @@ true - - 7 - 1 + 1 0 @@ -247,9 +232,7 @@ false - - 7 - 1 + 0 0 @@ -262,9 +245,7 @@ - - 7 - 1 + 1 0 @@ -280,9 +261,7 @@ - - 7 - 1 + 1 0 @@ -304,9 +283,7 @@ - - 7 - 7 + 0 0 @@ -324,9 +301,7 @@ - - 7 - 7 + 0 0 @@ -389,9 +364,7 @@ - - 7 - 7 + 0 0 @@ -402,9 +375,7 @@ - - 7 - 1 + 0 0 @@ -423,9 +394,7 @@ true - - 7 - 1 + 0 0 @@ -471,9 +440,7 @@ true - - 7 - 1 + 0 0 @@ -495,9 +462,7 @@ true - - 7 - 1 + 0 0 @@ -516,12 +481,10 @@ - false + true - - 7 - 1 + 0 0 @@ -544,9 +507,7 @@ - - 7 - 7 + 0 0 @@ -572,9 +533,7 @@ true - - 7 - 1 + 0 0 @@ -610,9 +569,7 @@ false - - 1 - 1 + 0 0 @@ -634,9 +591,7 @@ true - - 1 - 1 + 0 0 @@ -658,9 +613,7 @@ true - - 1 - 1 + 0 0 @@ -679,9 +632,7 @@ true - - 1 - 1 + 0 0 @@ -700,9 +651,7 @@ false - - 1 - 1 + 0 0 @@ -721,9 +670,7 @@ false - - 7 - 1 + 0 0 @@ -739,9 +686,7 @@ true - - 7 - 1 + 0 0 diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index bf99caf33f..bfa88ff658 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -635,6 +635,9 @@ public: FindAndReplaceOptions const & opt; private: + /// Auxiliary find method (does not account for opt.matchword) + int findAux(DocIterator const & cur, int len = -1, bool at_begin = true) const; + /** Normalize a stringified or latexified LyX paragraph. ** ** Normalize means: @@ -722,7 +725,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & } -int MatchStringAdv::operator()(DocIterator const & cur, int len, bool at_begin) const +int MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_begin) const { docstring docstr = stringifyFromForSearch(opt, cur, len); LYXERR(Debug::FIND, "Matching against '" << lyx::to_utf8(docstr) << "'"); @@ -765,6 +768,26 @@ int MatchStringAdv::operator()(DocIterator const & cur, int len, bool at_begin) } +int MatchStringAdv::operator()(DocIterator const & cur, int len, bool at_begin) const +{ + int res = findAux(cur, len, at_begin); + if (res == 0 || !at_begin || !opt.matchword || !cur.inTexted()) + return res; + Paragraph const & par = cur.paragraph(); + bool ws_left = cur.pos() > 0 ? + par.isWordSeparator(cur.pos() - 1) : true; + bool ws_right = cur.pos() + res < par.size() ? + par.isWordSeparator(cur.pos() + res) : true; + LYXERR(Debug::FIND, + "cur.pos()=" << cur.pos() << ", res=" << res + << ", separ: " << ws_left << ", " << ws_right + << endl); + if (ws_left && ws_right) + return res; + return 0; +} + + string MatchStringAdv::normalize(docstring const & s) const { string t; -- 2.39.5