From 4b0a5549b1ef7d1c621c994d0fc0f1e743520494 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 7 Apr 2006 22:16:09 +0000 Subject: [PATCH] * buffer_funcs.[Ch]: new needsUpdateCounters function * text.C: - LyXText::breakParagraph(): test if needsUpdateCounters() is enough before a full updateCounter - LyXText::backspacePos0(): ditto * text2.C: - LyXText::deleteEmptyParagraphMechanism(): ditto git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13593 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer_funcs.C | 23 +++++++++++++++++++++++ src/buffer_funcs.h | 8 ++++++++ src/text.C | 13 +++++++++++-- src/text2.C | 4 +++- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index d616fc79da..7a663b4123 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -503,6 +503,29 @@ void setCounter(Buffer const & buf, ParIterator & it) } // anon namespace +bool needsUpdateCounters(Buffer const & buf, ParIterator & it) +{ + switch (it->layout()->labeltype) { + + case LABEL_NO_LABEL: + case LABEL_MANUAL: + case LABEL_BIBLIO: + case LABEL_TOP_ENVIRONMENT: + case LABEL_CENTERED_TOP_ENVIRONMENT: + case LABEL_STATIC: + case LABEL_ITEMIZE: + setCounter(buf, it); + return false; + + case LABEL_SENSITIVE: + case LABEL_COUNTER: + // do more things with enumerate later + case LABEL_ENUMERATE: + return true; + } +} + + void updateCounters(Buffer const & buf) { // start over diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h index 4b8758ce33..4d6d71e899 100644 --- a/src/buffer_funcs.h +++ b/src/buffer_funcs.h @@ -21,6 +21,7 @@ class Buffer; class DocIterator; class ErrorList; class TeXErrors; +class ParIterator; /** * Loads a LyX file \c filename into \c Buffer @@ -48,6 +49,13 @@ int countWords(DocIterator const & from, DocIterator const & to); std::string expandLabel(Buffer const & buf, LyXLayout_ptr const & layout, bool appendix); +/// updates current counter and/or label if possible. +/** +\retval true if a full updateCounters is required. +\retval false if a full updateCounters is not required. +*/ +bool needsUpdateCounters(Buffer const & buf, ParIterator & it); + /// updates all counters void updateCounters(Buffer const &); diff --git a/src/text.C b/src/text.C index a95f2c81e8..1fd0370caf 100644 --- a/src/text.C +++ b/src/text.C @@ -24,6 +24,7 @@ #include "bufferparams.h" #include "BufferView.h" #include "cursor.h" +#include "pariterator.h" #include "coordcache.h" #include "CutAndPaste.h" #include "debug.h" @@ -1087,7 +1088,12 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout) while (!pars_[next_par].empty() && pars_[next_par].isNewline(0)) pars_[next_par].erase(0); - updateCounters(cur.buffer()); + ParIterator current_it(cur); + ParIterator next_it(cur); next_it.pit() = next_par; + + if (needsUpdateCounters(cur.buffer(), current_it) + || needsUpdateCounters(cur.buffer(), next_it)) + updateCounters(cur.buffer()); // Mark "carriage return" as inserted if change tracking: if (cur.buffer().params().tracking_changes) { @@ -1669,7 +1675,10 @@ bool LyXText::backspacePos0(LCursor & cur) --cur.pos(); // the counters may have changed - updateCounters(cur.buffer()); + ParIterator par_it(cur); + if (needsUpdateCounters(cur.buffer(), par_it)) + updateCounters(cur.buffer()); + setCursor(cur, cur.pit(), cur.pos(), false); } return needsUpdate; diff --git a/src/text2.C b/src/text2.C index 3df5592a45..82f3cd52a6 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1274,7 +1274,9 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old) cur.resetAnchor(); } } - updateCounters(old.buffer()); + ParIterator par_it(old); + if (needsUpdateCounters(old.buffer(), par_it)) + updateCounters(old.buffer()); return true; }