fix backwards search (bug 1666)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8988 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2004-09-17 16:28:47 +00:00
parent 3f589b3511
commit 09b67226eb
8 changed files with 42 additions and 20 deletions

View File

@ -357,11 +357,8 @@ void BufferView::putSelectionAt(DocIterator const & cur,
if (length) { if (length) {
if (backwards) { if (backwards) {
cursor().pos() += length;
cursor().setSelection(cursor(), -length); cursor().setSelection(cursor(), -length);
DocIterator const it = cursor();
cursor().setCursor(cursor().anchor_);
cursor().selection() = true;
cursor().anchor_ = it;
} else } else
cursor().setSelection(cursor(), length); cursor().setSelection(cursor(), length);
} }

View File

@ -162,7 +162,11 @@ public:
LyXText * text() const; LyXText * text() const;
/// ///
void setCursor(ParIterator const & par, lyx::pos_type pos); void setCursor(ParIterator const & par, lyx::pos_type pos);
/// /* Sets the selection. When \c backwards == false, set anchor
* to \c cur and cursor to \c cur + \c length. When \c
* backwards == true, set anchor to \c cur and cursor to \c
* cur + \c length.
*/
void putSelectionAt(DocIterator const & cur, void putSelectionAt(DocIterator const & cur,
int length, bool backwards); int length, bool backwards);

View File

@ -1,3 +1,19 @@
2004-09-16 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
Fix bug #1666
* BufferView.C (putSelectionAt): change the semantics when
backwards == true: now, this just swaps cursor and anchor wrt the
forward case
* BufferView.h (putSelectionAt): add some documentation
* lyxfind.C (findBackwards): rewrite using while(). In particular,
make sure backwardChar is done at least once (to avoid getting
stuck)
(findNextChange): use putSelectionAt in the forward direction
(operator()): use Paragraph::isWord
2004-09-16 Lars Gullik Bjonnes <larsbj@gullik.net> 2004-09-16 Lars Gullik Bjonnes <larsbj@gullik.net>
* Spacing.C (set): c_str fix * Spacing.C (set): c_str fix

View File

@ -1,3 +1,8 @@
2004-09-14 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* ControlSpellchecker.C (check): do not set the selection
backwards, but translate it to the left instead.
2004-09-15 Georg Baum <Georg.Baum@post.rwth-aachen.de> 2004-09-15 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* ControlInclude.C (load): open nonlyx files via formats.edit() * ControlInclude.C (load): open nonlyx files via formats.edit()

View File

@ -213,7 +213,8 @@ void ControlSpellchecker::check()
} }
int const size = getWord().size(); int const size = getWord().size();
kernel().bufferview()->putSelectionAt(cur, size, true); cur.pos() -= size;
kernel().bufferview()->putSelectionAt(cur, size, false);
// set suggestions // set suggestions
if (res != SpellBase::OK && res != SpellBase::IGNORE) { if (res != SpellBase::OK && res != SpellBase::IGNORE) {

View File

@ -30,7 +30,6 @@
#include "frontends/Alert.h" #include "frontends/Alert.h"
#include "frontends/LyXView.h" #include "frontends/LyXView.h"
#include "support/textutils.h"
#include "support/tostr.h" #include "support/tostr.h"
#include <sstream> #include <sstream>
@ -86,10 +85,10 @@ public:
// if necessary, check whether string matches word // if necessary, check whether string matches word
if (mw) { if (mw) {
if (pos > 0 && IsLetterCharOrDigit(par.getChar(pos - 1))) if (pos > 0 && par.isWord(pos - 1))
return false; return false;
if (pos + lyx::pos_type(size) < parsize if (pos + lyx::pos_type(size) < parsize
&& IsLetterCharOrDigit(par.getChar(pos + size))); && par.isWord(pos + size));
return false; return false;
} }
@ -117,9 +116,11 @@ bool findForward(DocIterator & cur, MatchString const & match)
bool findBackwards(DocIterator & cur, MatchString const & match) bool findBackwards(DocIterator & cur, MatchString const & match)
{ {
for (; cur; cur.backwardChar()) while (cur) {
cur.backwardChar();
if (cur.inTexted() && match(cur.paragraph(), cur.pos())) if (cur.inTexted() && match(cur.paragraph(), cur.pos()))
return true; return true;
}
return false; return false;
} }
@ -344,10 +345,10 @@ bool findNextChange(BufferView * bv)
return false; return false;
Paragraph const & par = cur.paragraph(); Paragraph const & par = cur.paragraph();
pos_type pos = cur.pos(); const pos_type pos = cur.pos();
Change orig_change = par.lookupChangeFull(pos); Change orig_change = par.lookupChangeFull(pos);
pos_type parsize = par.size(); const pos_type parsize = par.size();
pos_type end = pos; pos_type end = pos;
for (; end != parsize; ++end) { for (; end != parsize; ++end) {
@ -361,7 +362,8 @@ bool findNextChange(BufferView * bv)
} }
} }
pos_type length = end - pos; pos_type length = end - pos;
bv->putSelectionAt(cur, length, true); bv->putSelectionAt(cur, length, false);
return true; return true;
} }

View File

@ -1,3 +1,7 @@
2004-09-10 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* textutils.h (IsLetterCharOrDigit): remove
2004-09-10 Jean-Marc Lasgouttes <lasgouttes@lyx.org> 2004-09-10 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* filetools.C (LibScriptSearch): quote the path of the script, in * filetools.C (LibScriptSearch): quote the path of the script, in

View File

@ -95,11 +95,4 @@ bool IsDigit(unsigned char ch)
} }
/// return true if the char is alphanumeric
inline
bool IsLetterCharOrDigit(unsigned char ch)
{
return IsLetterChar(ch) || IsDigit(ch);
}
#endif // TEXTUTILS_H #endif // TEXTUTILS_H