From 249e6b7ac0578d4ac03c085ba67a1d75af9980e2 Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Tue, 26 Feb 2008 19:20:12 +0000 Subject: [PATCH] * update the words of a paragraph when the cursor leaves. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23260 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Cursor.cpp | 9 +++++++++ src/Paragraph.cpp | 1 + src/insets/InsetText.cpp | 19 +++++++++++++++++++ src/insets/InsetText.h | 2 ++ 4 files changed, 31 insertions(+) diff --git a/src/Cursor.cpp b/src/Cursor.cpp index ef62fea621..531b7bc0bf 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -1772,6 +1772,15 @@ bool notifyCursorLeaves(Cursor const & old, Cursor & cur) if (&old[i].inset() != &cur[i].inset()) break; } + + // update words if we just moved to another paragraph + if (i == old.depth() && i == cur.depth() + && !cur.buffer().isClean() + && cur.inTexted() && old.inTexted() + && cur.pit() != old.pit()) { + old.paragraph().updateWords(old.buffer(), old.top()); + return false; + } // notify everything on top of the common part in old cursor, // but stop if the inset claims the cursor to be invalid now diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index da573acbd1..2477165ded 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2746,6 +2746,7 @@ void Paragraph::registerWords() void Paragraph::updateWords(Buffer const & buf, CursorSlice const & sl) { + BOOST_ASSERT(&sl.paragraph() == this); deregisterWords(); collectWords(buf, sl); registerWords(); diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index b6062d3500..ddd333d6a0 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -474,6 +474,25 @@ void InsetText::updateLabels(Buffer const & buf, ParIterator const & it) } +bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur) +{ + if (cur.buffer().isClean()) + return Inset::notifyCursorLeaves(old, cur); + + // find text inset in old cursor + Cursor insetCur = old; + int scriptSlice = insetCur.find(this); + BOOST_ASSERT(scriptSlice != -1); + insetCur.cutOff(scriptSlice); + BOOST_ASSERT(&insetCur.inset() == this); + + // update the old paragraph's words + insetCur.paragraph().updateWords(insetCur.buffer(), insetCur.top()); + + return Inset::notifyCursorLeaves(old, cur); +} + + bool InsetText::completionSupported(Cursor const & cur) const { Cursor const & bvCur = cur.bv().cursor(); diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index d88752a438..5f75ce35c3 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -137,6 +137,8 @@ public: virtual void updateLabels(Buffer const &, ParIterator const &); /// virtual Inset * clone() const; + /// + virtual bool notifyCursorLeaves(Cursor const & old, Cursor & cur); /// bool completionSupported(Cursor const &) const;