From 93b0f9c080cbb3dd807850ad60dbe211fc5bc703 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Wed, 6 May 2015 18:39:24 +0200 Subject: [PATCH] #9514 contents inside of LyX insets with spell check disabled should be ignored by spell checker. The document iterator now skips math insets and insets like notes where spell check is disabled. The continuous spell checking is part of the row painter drawing and the spell check disabled state has to be passed down recursively while doing the inset painting. --- src/Buffer.cpp | 6 +++--- src/MetricsInfo.cpp | 2 +- src/MetricsInfo.h | 2 ++ src/RowPainter.cpp | 5 ++++- src/TextMetrics.cpp | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 194cd9bef0..fb3602691d 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -4809,12 +4809,13 @@ int Buffer::spellCheck(DocIterator & from, DocIterator & to, // OK, we start from here. for (; from != end; from.forwardPos()) { // We are only interested in text so remove the math CursorSlice. - while (from.inMathed()) { + // The same is done for insets with disabled spell check. + while (from.inMathed() || !from.inset().allowSpellCheck()) { from.pop_back(); from.pos()++; } // If from is at the end of the document (which is possible - // when leaving the mathed) LyX will crash later otherwise. + // when "from" was manipulated) LyX will crash later otherwise. if (from.atEnd() || (!to_end && from >= end)) break; to = from; @@ -4824,7 +4825,6 @@ int Buffer::spellCheck(DocIterator & from, DocIterator & to, word_lang = wl; break; } - // Do not increase progress when from == to, otherwise the word // count will be wrong. if (from != to) { diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp index b75ec81108..2b954d3ed9 100644 --- a/src/MetricsInfo.cpp +++ b/src/MetricsInfo.cpp @@ -66,7 +66,7 @@ MetricsInfo::MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth, PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter) : pain(painter), ltr_pos(false), change_(), selected(false), - full_repaint(true), background_color(Color_background) + do_spellcheck(true), full_repaint(true), background_color(Color_background) { base.bv = bv; } diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h index 88dd39fd7d..7ad62426e7 100644 --- a/src/MetricsInfo.h +++ b/src/MetricsInfo.h @@ -117,6 +117,8 @@ public: Change change_; /// Whether the parent is selected as a whole bool selected; + /// Whether the spell checker is enabled for the parent + bool do_spellcheck; /// bool full_repaint; /// Current background color diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp index 4c9118d916..fbe35792a2 100644 --- a/src/RowPainter.cpp +++ b/src/RowPainter.cpp @@ -121,13 +121,15 @@ void RowPainter::paintInset(Inset const * inset, pos_type const pos) LASSERT(inset, return); // Backup full_repaint status because some insets (InsetTabular) // requires a full repaint - bool pi_full_repaint = pi_.full_repaint; + bool const pi_full_repaint = pi_.full_repaint; + bool const pi_do_spellcheck = pi_.do_spellcheck; pi_.base.font = inset->inheritFont() ? font.fontInfo() : pi_.base.bv->buffer().params().getFont().fontInfo(); pi_.ltr_pos = (bidi_.level(pos) % 2 == 0); Change prev_change = change_; pi_.change_ = change_.changed() ? change_ : par_.lookupChange(pos); + pi_.do_spellcheck &= inset->allowSpellCheck(); int const x1 = int(x_); pi_.base.bv->coordCache().insets().add(inset, x1, yo_); @@ -147,6 +149,7 @@ void RowPainter::paintInset(Inset const * inset, pos_type const pos) // Restore full_repaint status. pi_.full_repaint = pi_full_repaint; pi_.change_ = prev_change; + pi_.do_spellcheck = pi_do_spellcheck; #ifdef DEBUG_METRICS int const x2 = x1 + dim.wid; diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 59eb2abd71..a347b993ec 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1878,7 +1878,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const || rowSlice == bv_->lastRowSlice(); // Take this opportunity to spellcheck the row contents. - if (row_has_changed && lyxrc.spellcheck_continuously) { + if (row_has_changed && pi.do_spellcheck && lyxrc.spellcheck_continuously) { text_->getPar(pit).spellCheck(); } -- 2.39.2