From 09b67226ebf250500f2d655a29382380f022a2f1 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 17 Sep 2004 16:28:47 +0000 Subject: [PATCH] fix backwards search (bug 1666) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8988 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 5 +---- src/BufferView.h | 6 +++++- src/ChangeLog | 16 ++++++++++++++++ src/frontends/controllers/ChangeLog | 5 +++++ src/frontends/controllers/ControlSpellchecker.C | 3 ++- src/lyxfind.C | 16 +++++++++------- src/support/ChangeLog | 4 ++++ src/support/textutils.h | 7 ------- 8 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 88f6ea2530..c8e1883b55 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -357,11 +357,8 @@ void BufferView::putSelectionAt(DocIterator const & cur, if (length) { if (backwards) { + cursor().pos() += length; cursor().setSelection(cursor(), -length); - DocIterator const it = cursor(); - cursor().setCursor(cursor().anchor_); - cursor().selection() = true; - cursor().anchor_ = it; } else cursor().setSelection(cursor(), length); } diff --git a/src/BufferView.h b/src/BufferView.h index e9a8101e6f..5ffe593d67 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -162,7 +162,11 @@ public: LyXText * text() const; /// 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, int length, bool backwards); diff --git a/src/ChangeLog b/src/ChangeLog index aba178940a..413d0da7b5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +2004-09-16 Jean-Marc Lasgouttes + + 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 * Spacing.C (set): c_str fix diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index ec3ffe14f3..e885e41678 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2004-09-14 Jean-Marc Lasgouttes + + * ControlSpellchecker.C (check): do not set the selection + backwards, but translate it to the left instead. + 2004-09-15 Georg Baum * ControlInclude.C (load): open nonlyx files via formats.edit() diff --git a/src/frontends/controllers/ControlSpellchecker.C b/src/frontends/controllers/ControlSpellchecker.C index 8e99872dbb..ffaf47cb4d 100644 --- a/src/frontends/controllers/ControlSpellchecker.C +++ b/src/frontends/controllers/ControlSpellchecker.C @@ -213,7 +213,8 @@ void ControlSpellchecker::check() } int const size = getWord().size(); - kernel().bufferview()->putSelectionAt(cur, size, true); + cur.pos() -= size; + kernel().bufferview()->putSelectionAt(cur, size, false); // set suggestions if (res != SpellBase::OK && res != SpellBase::IGNORE) { diff --git a/src/lyxfind.C b/src/lyxfind.C index 0c4c9e9eec..4509a1163b 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -30,7 +30,6 @@ #include "frontends/Alert.h" #include "frontends/LyXView.h" -#include "support/textutils.h" #include "support/tostr.h" #include @@ -86,10 +85,10 @@ public: // if necessary, check whether string matches word if (mw) { - if (pos > 0 && IsLetterCharOrDigit(par.getChar(pos - 1))) + if (pos > 0 && par.isWord(pos - 1)) return false; if (pos + lyx::pos_type(size) < parsize - && IsLetterCharOrDigit(par.getChar(pos + size))); + && par.isWord(pos + size)); return false; } @@ -117,9 +116,11 @@ bool findForward(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())) return true; + } return false; } @@ -344,10 +345,10 @@ bool findNextChange(BufferView * bv) return false; Paragraph const & par = cur.paragraph(); - pos_type pos = cur.pos(); + const pos_type pos = cur.pos(); Change orig_change = par.lookupChangeFull(pos); - pos_type parsize = par.size(); + const pos_type parsize = par.size(); pos_type end = pos; for (; end != parsize; ++end) { @@ -361,7 +362,8 @@ bool findNextChange(BufferView * bv) } } pos_type length = end - pos; - bv->putSelectionAt(cur, length, true); + bv->putSelectionAt(cur, length, false); + return true; } diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 9f180be253..83a80d3098 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,7 @@ +2004-09-10 Jean-Marc Lasgouttes + + * textutils.h (IsLetterCharOrDigit): remove + 2004-09-10 Jean-Marc Lasgouttes * filetools.C (LibScriptSearch): quote the path of the script, in diff --git a/src/support/textutils.h b/src/support/textutils.h index 4770642a06..f6e1cc2e67 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -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 -- 2.39.2