fix for #7081: the painting of misspelled marker is suppressed for the word at cursor position

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36990 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stephan Witt 2010-12-22 07:29:16 +00:00
parent 1f44b8a5c0
commit fab1507221
4 changed files with 58 additions and 4 deletions

View File

@ -173,6 +173,18 @@ public:
return result;
}
FontSpan const & getRange(pos_type pos) const
{
RangesIterator et = ranges_.end();
RangesIterator it = ranges_.begin();
for (; it != et; ++it) {
if(it->inside(pos)) {
return it->range();
}
}
return empty_;
}
bool needsRefresh() const {
return needs_refresh_;
}
@ -215,6 +227,8 @@ private:
bool needs_refresh_;
/// spell state cache version number
SpellChecker::ChangeNumber current_change_number_;
/// empty span to indicate mismatch for getRange()
FontSpan empty_;
void eraseCoveredRanges(FontSpan const fp)
@ -2825,6 +2839,13 @@ bool Paragraph::isWordSeparator(pos_type pos) const
}
bool Paragraph::isSameSpellRange(pos_type pos1, pos_type pos2) const
{
return pos1 == pos2
|| d->speller_state_.getRange(pos1) == d->speller_state_.getRange(pos2);
}
bool Paragraph::isChar(pos_type pos) const
{
if (Inset const * inset = getInset(pos))

View File

@ -452,6 +452,11 @@ public:
/// \return true if pointed position is misspelled.
bool isMisspelled(pos_type pos) const;
/// \return true if both positions are inside the same
/// spell range - i.e. the same word.
/// use it for positions inside misspelled range only.
bool isSameSpellRange(pos_type pos1, pos_type pos2) const;
/// spell check of whole paragraph
/// remember results until call of requestSpellCheck()
void spellCheck() const;

View File

@ -477,7 +477,10 @@ 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());
FuncCode const act = cmd.action();
switch (act) {
@ -2171,6 +2174,18 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
if (lyxrc.spellcheck_continuously && !needsUpdate) {
// Check for misspelled text
// The redraw is useful because of the painting of
// misspelled markers depends on the cursor position.
// Trigger a redraw for cursor moves inside misspelled text.
if (cur.paragraph().id() == last_pid && cur.pos() != last_pos) {
needsUpdate |= last_misspelled || cur.paragraph().isMisspelled(cur.pos());
} else if (cur.paragraph().id() != last_pid) {
needsUpdate |= last_misspelled || cur.paragraph().isMisspelled(cur.pos());
}
}
// FIXME: The cursor flag is reset two lines below
// so we need to check here if some of the LFUN did touch that.
// for now only Text::erase() and Text::backspace() do that.

View File

@ -394,7 +394,7 @@ void RowPainter::paintFromPos(pos_type & vpos, bool changed)
lang == "farsi";
// spelling correct?
bool const misspelled_ =
bool const misspelled =
lyxrc.spellcheck_continuously && par_.isMisspelled(pos);
// draw as many chars as we can
@ -410,8 +410,21 @@ void RowPainter::paintFromPos(pos_type & vpos, bool changed)
paintForeignMark(orig_x, orig_font.language());
if (lyxrc.spellcheck_continuously && misspelled_) {
paintMisspelledMark(orig_x, changed);
if (lyxrc.spellcheck_continuously && misspelled) {
// check for cursor position
// don't draw misspelled marker for words at cursor position
// we don't want to disturb the process of text editing
BufferView const * bv = pi_.base.bv;
Cursor const & cur = bv->cursor();
bool current_word = false;
if (par_.id() == cur.paragraph().id()) {
pos_type cpos = cur.pos();
if (cpos > 0 && cpos == par_.size() && !par_.isWordSeparator(cpos-1))
--cpos;
current_word = par_.isSameSpellRange(pos, cpos) ;
}
if (!current_word)
paintMisspelledMark(orig_x, changed);
}
}