]> git.lyx.org Git - features.git/blobdiff - src/Cursor.cpp
start work on less-likely-to-misuse iterators.
[features.git] / src / Cursor.cpp
index eb23d79533094ea87ecf8ad64ba81515eabe79dc..6868651e212bfed80d54da1defde1fad39b06e67 100644 (file)
 #include <config.h>
 
 #include "Bidi.h"
-#include "BufferView.h"
 #include "Buffer.h"
-#include "Cursor.h"
+#include "BufferView.h"
 #include "CoordCache.h"
+#include "Cursor.h"
 #include "CutAndPaste.h"
 #include "DispatchResult.h"
 #include "Encoding.h"
+#include "Font.h"
 #include "FuncRequest.h"
 #include "Language.h"
 #include "lfuns.h"
-#include "Font.h"
 #include "LyXFunc.h" // only for setMessage()
 #include "LyXRC.h"
-#include "Row.h"
-#include "Text.h"
-#include "Paragraph.h"
 #include "paragraph_funcs.h"
+#include "Paragraph.h"
 #include "ParIterator.h"
+#include "Row.h"
+#include "Text.h"
 #include "TextMetrics.h"
+#include "TocBackend.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
@@ -271,7 +272,8 @@ void Cursor::reset(Inset & inset)
 {
        clear();
        push_back(CursorSlice(inset));
-       anchor_ = DocIterator(inset);
+       anchor_ = doc_iterator_begin(inset);
+       anchor_.clear();
        clearTargetX();
        selection_ = false;
        mark_ = false;
@@ -1412,13 +1414,7 @@ Encoding const * Cursor::getEncoding() const
 {
        if (empty())
                return 0;
-       int s = 0;
-       // go up until first non-0 text is hit
-       // (innermost text is 0 in mathed)
-       for (s = depth() - 1; s >= 0; --s)
-               if (operator[](s).text())
-                       break;
-       CursorSlice const & sl = operator[](s);
+       CursorSlice const & sl = innerTextSlice();
        Text const & text = *sl.text();
        Font font = text.getPar(sl.pit()).getFont(
                bv().buffer().params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
@@ -1457,13 +1453,8 @@ Font Cursor::getFont() const
        // if a character is entered.
        
        // HACK. far from being perfect...
-       // go up until first non-0 text is hit
-       // (innermost text is 0 in mathed)
-       int s = 0;
-       for (s = depth() - 1; s >= 0; --s)
-               if (operator[](s).text())
-                       break;
-       CursorSlice const & sl = operator[](s);
+
+       CursorSlice const & sl = innerTextSlice();
        Text const & text = *sl.text();
        Paragraph const & par = text.getPar(sl.pit());
        
@@ -1639,4 +1630,14 @@ void Cursor::recordUndoSelection()
 }
 
 
+void Cursor::checkBufferStructure()
+{
+       if (paragraph().layout()->toclevel == Layout::NOT_IN_TOC)
+               return;
+       Buffer const * master = buffer().masterBuffer();
+       master->tocBackend().updateItem(ParConstIterator(*this));
+       master->structureChanged();
+}
+
+
 } // namespace lyx