From 5eed97b56b9a90a493e57061b8cf75d49f8d5d33 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Sat, 29 Jan 2011 12:28:02 +0000 Subject: [PATCH] restore the correct behavior of suppression of misspelled marker for word at cursor position - the change r37340 broke it git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37363 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Paragraph.cpp | 7 +++++-- src/Paragraph.h | 6 ++++-- src/Text3.cpp | 18 +++++++++--------- src/rowpainter.cpp | 2 ++ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index b8db16590c..08b143b364 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -3763,9 +3763,12 @@ void Paragraph::spellCheck() const } -bool Paragraph::isMisspelled(pos_type pos) const +bool Paragraph::isMisspelled(pos_type pos, bool check_boundary) const { - return SpellChecker::misspelled(d->speller_state_.getState(pos)); + bool result = SpellChecker::misspelled(d->speller_state_.getState(pos)); + if (!result && check_boundary && pos > 0 && isWordSeparator(pos)) + result = SpellChecker::misspelled(d->speller_state_.getState(pos - 1)); + return result; } diff --git a/src/Paragraph.h b/src/Paragraph.h index ed8d7f4027..9ab52ed01b 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -456,8 +456,10 @@ public: bool check_learned = false) const; /// Spell checker status at position \p pos. - /// \return true if pointed position is misspelled. - bool isMisspelled(pos_type pos) const; + /// If \p check_boundary is true the status of position immediately + /// before \p pos is tested too if it is at word boundary. + /// \return true if one of the tested positions is misspelled. + bool isMisspelled(pos_type pos, bool check_boundary = false) const; /// \return true if both positions are inside the same /// spell range - i.e. the same word. diff --git a/src/Text3.cpp b/src/Text3.cpp index 5079522bb4..dad691b6d1 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -467,9 +467,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) cur.noScreenUpdate(); LASSERT(cur.text() == this, /**/); - CursorSlice oldTopSlice = cur.top(); - bool oldBoundary = cur.boundary(); - bool sel = cur.selection(); + CursorSlice const oldTopSlice = cur.top(); + bool const oldBoundary = cur.boundary(); + bool const oldSelection = cur.selection(); // Signals that, even if needsUpdate == false, an update of the // cursor paragraph is required bool singleParUpdate = lyxaction.funcHasFlag(cmd.action(), @@ -477,9 +477,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) // Signals that a full-screen update is required bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action(), LyXAction::NoUpdate) || singleParUpdate); - int const last_pid = cur.paragraph().id(); - pos_type const last_pos = cur.pos(); - bool const last_misspelled = lyxrc.spellcheck_continuously && cur.paragraph().isMisspelled(cur.pos()); + bool const last_misspelled = lyxrc.spellcheck_continuously + && cur.paragraph().isMisspelled(cur.pos(), true); FuncCode const act = cmd.action(); switch (act) { @@ -2184,9 +2183,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) if (!cur.inTexted()) { // move from regular text to math needsUpdate = last_misspelled; - } else if (cur.paragraph().id() != last_pid || cur.pos() != last_pos) { + } else if (oldTopSlice != cur.top() || oldBoundary != cur.boundary()) { // move inside regular text - needsUpdate = last_misspelled || cur.paragraph().isMisspelled(cur.pos()); + needsUpdate = last_misspelled + || cur.paragraph().isMisspelled(cur.pos(), true); } } @@ -2212,7 +2212,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) if (!needsUpdate && &oldTopSlice.inset() == &cur.inset() && oldTopSlice.idx() == cur.idx() - && !sel // sel is a backup of cur.selection() at the beginning of the function. + && !oldSelection // oldSelection is a backup of cur.selection() at the beginning of the function. && !cur.selection()) // FIXME: it would be better if we could just do this // diff --git a/src/rowpainter.cpp b/src/rowpainter.cpp index 5ea2ffc875..5d0bcb6b28 100644 --- a/src/rowpainter.cpp +++ b/src/rowpainter.cpp @@ -421,6 +421,8 @@ void RowPainter::paintFromPos(pos_type & vpos, bool changed) pos_type cpos = cur.pos(); if (cpos > 0 && cpos == par_.size() && !par_.isWordSeparator(cpos-1)) --cpos; + else if (cpos > 0 && par_.isWordSeparator(cpos)) + --cpos; current_word = par_.isSameSpellRange(pos, cpos) ; } if (!current_word) -- 2.39.5