]> git.lyx.org Git - features.git/commitdiff
make redoParagraph more independent of current cursor
authorAndré Pönitz <poenitz@gmx.net>
Fri, 1 Aug 2003 11:22:13 +0000 (11:22 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 1 Aug 2003 11:22:13 +0000 (11:22 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7470 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/ChangeLog
src/insets/insetcollapsable.C
src/lyxtext.h
src/text.C
src/text2.C

index 8dfbdbb964d2520716b03903697603291963a26b..8a7bee84b17775a0551cb9843ed534cf10371ba5 100644 (file)
@@ -625,8 +625,7 @@ bool BufferView::ChangeInsets(InsetOld::Code code,
                        // How to set the cursor corretly when it.size()>1 ??
                        if (it.size() == 1) {
                                text->setCursorIntern(it.pit(), 0);
-                               text->redoParagraphs(text->cursor,
-                                                    boost::next(text->cursor.par()));
+                               text->redoParagraph(text->cursor.par());
                                text->partialRebreak();
                        }
                }
index 1015416b2f86836e12b5eeb9a7a251c817ef43a2..506cbb779fa8e9e65ac62841d14d1444fb8215d6 100644 (file)
@@ -2,6 +2,13 @@
 
        * buffer.[Ch]: file_format is no longer a buffer data element.
 
+2003-08-01  André Pönitz  <poenitz@gmx.net>
+
+       * BufferView.C:
+       * lyxtext.h:
+       * text.C:
+       * text2.C: make redoParagraph more independent of current cursor
+
 2003-07-30  André Pönitz  <poenitz@gmx.net>
 
        * paragraph.[Ch] (copyIntoMinibuffer): removed unused function
index b70653314a0246dfc7b2c73d2ced2202912f58a2..5cb670318b39cd368fda74b1d3171a039aa1dfe9 100644 (file)
@@ -289,8 +289,8 @@ bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
 
 InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
 {
-       lyxerr << "InsetCollapsable::localDispatch: "
-               << cmd.action << " '" << cmd.argument << "'\n";
+       //lyxerr << "InsetCollapsable::localDispatch: "
+       //      << cmd.action << " '" << cmd.argument << "'\n";
        BufferView * bv = cmd.view();
        switch (cmd.action) {
                case LFUN_INSET_EDIT: {
index 83027e9c43099343e4472fd80dbf7eb7f433fcfc..c45f319f34f9b066074372b59443282b588a0f44 100644 (file)
@@ -131,15 +131,15 @@ public:
          */
        void setFont(LyXFont const &, bool toggleall = false);
 
-       /** deletes and inserts again all paragaphs between the cursor
-         and the specified par. The Cursor is needed to set the refreshing
-         parameters.
-         This function is needed after SetLayout and SetFont etc.
-         */
-       void redoParagraphs(LyXCursor const & cursor,
-                           ParagraphList::iterator endpit);
-       ///
+       /// rebreaks all paragaphs between the given pars.
+       void redoParagraphs(ParagraphList::iterator begin,
+                           ParagraphList::iterator end);
+       /// rebreaks the given par
+       void redoParagraph(ParagraphList::iterator pit);
+       /// rebreaks the cursor par
        void redoParagraph();
+       /// returns first row belongin to some par
+       RowList::iterator firstRow(ParagraphList::iterator pit);
 
        ///
        void toggleFree(LyXFont const &, bool toggleall = false);
index a4ad945e4b6b8916567129cd24dbbc9d5649b8aa..53211171d22fbf02685dfc83480d97e9bc65bb03 100644 (file)
@@ -1579,7 +1579,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
 void LyXText::redoParagraph()
 {
        clearSelection();
-       redoParagraphs(cursor, boost::next(cursor.par()));
+       redoParagraph(cursor.par());
        setCursorIntern(cursor.par(), cursor.pos());
 }
 
@@ -2007,7 +2007,7 @@ void LyXText::acceptChange()
                startc.par()->acceptChange(startc.pos(), endc.pos());
                finishUndo();
                clearSelection();
-               redoParagraphs(startc, boost::next(startc.par()));
+               redoParagraph(startc.par());
                setCursorIntern(startc.par(), 0);
        }
 #warning handle multi par selection
@@ -2026,7 +2026,7 @@ void LyXText::rejectChange()
                startc.par()->rejectChange(startc.pos(), endc.pos());
                finishUndo();
                clearSelection();
-               redoParagraphs(startc, boost::next(startc.par()));
+               redoParagraph(startc.par());
                setCursorIntern(startc.par(), 0);
        }
 #warning handle multi par selection
index dcb79784ced786986e5da9fe2b1f6a4cc43338a4..0c798d4bc8c5f30828bf83bf9a5efc15613a1733 100644 (file)
@@ -443,7 +443,7 @@ void LyXText::setLayout(string const & layout)
 
        ParagraphList::iterator endpit = setLayout(cursor, selection.start,
                                                   selection.end, layout);
-       redoParagraphs(selection.start, endpit);
+       redoParagraphs(selection.start.par(), endpit);
 
        // we have to reset the selection, because the
        // geometry could have changed
@@ -511,15 +511,12 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
        if (test_only)
                return changed;
 
-       // Wow, redoParagraphs is stupid.
-       LyXCursor tmpcursor;
-       setCursor(tmpcursor, start, 0);
 
-       redoParagraphs(tmpcursor, pastend);
+       redoParagraphs(start, pastend);
 
        // We need to actually move the text->cursor. I don't
        // understand why ...
-       tmpcursor = cursor;
+       LyXCursor tmpcursor = cursor;
 
        // we have to reset the visual selection because the
        // geometry could have changed
@@ -589,7 +586,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
        }
        unFreezeUndo();
 
-       redoParagraphs(selection.start, boost::next(selection.end.par()));
+       redoParagraph(selection.start.par());
 
        // we have to reset the selection, because the
        // geometry could have changed, but we keep
@@ -621,17 +618,31 @@ void LyXText::redoHeightOfParagraph()
 }
 
 
-// deletes and inserts again all paragraphs between the cursor
-// and the specified par
+RowList::iterator LyXText::firstRow(ParagraphList::iterator pit)
+{
+       RowList::iterator rit;
+       for (rit = rows().begin(); rit != rows().end(); ++rit)
+               if (rit->par() == pit)
+                       break;
+       return rit;
+}
+
+
+// rebreaks all paragraphs between the specified pars
 // This function is needed after SetLayout and SetFont etc.
-void LyXText::redoParagraphs(LyXCursor const & cur,
-                            ParagraphList::iterator endpit)
+void LyXText::redoParagraphs(ParagraphList::iterator start,
+  ParagraphList::iterator endpit)
 {
-       RowList::iterator tmprit = getRow(cur);
+       RowList::iterator rit = firstRow(start);
+
+       if (rit == rows().end()) {
+               lyxerr << "LyXText::redoParagraphs: should not happen\n";
+               Assert(0);
+       }
 
        ParagraphList::iterator first_phys_pit;
        RowList::iterator prevrit;
-       if (tmprit == rows().begin()) {
+       if (rit == rows().begin()) {
                // A trick/hack for UNDO.
                // This is needed because in an UNDO/REDO we could have
                // changed the ownerParagraph() so the paragraph inside
@@ -640,30 +651,28 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
                first_phys_pit = ownerParagraphs().begin();
                prevrit = rows().end();
        } else {
-               first_phys_pit = tmprit->par();
-               while (tmprit != rows().begin()
-                      && boost::prior(tmprit)->par() == first_phys_pit)
+               first_phys_pit = rit->par();
+               while (rit != rows().begin()
+                      && boost::prior(rit)->par() == first_phys_pit)
                {
-                       --tmprit;
+                       --rit;
                }
-               prevrit = boost::prior(tmprit);
+               prevrit = boost::prior(rit);
        }
 
        // remove it
-       while (tmprit != rows().end() && tmprit->par() != endpit) {
-               RowList::iterator tmprit2 = tmprit++;
-               removeRow(tmprit2);
+       while (rit != rows().end() && rit->par() != endpit) {
+               RowList::iterator rit2 = rit++;
+               removeRow(rit2);
        }
 
        // Reinsert the paragraphs.
        ParagraphList::iterator tmppit = first_phys_pit;
 
        while (tmppit != ownerParagraphs().end()) {
-               insertParagraph(tmppit, tmprit);
-               while (tmprit != rows().end()
-                      && tmprit->par() == tmppit) {
-                       ++tmprit;
-               }
+               insertParagraph(tmppit, rit);
+               while (rit != rows().end() && rit->par() == tmppit)
+                       ++rit;
                ++tmppit;
                if (tmppit == endpit)
                        break;
@@ -673,13 +682,19 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
        else
                setHeightOfRow(rows().begin());
        postPaint();
-       if (tmprit != rows().end())
-               setHeightOfRow(tmprit);
+       if (rit != rows().end())
+               setHeightOfRow(rit);
 
        updateCounters();
 }
 
 
+void LyXText::redoParagraph(ParagraphList::iterator pit)
+{
+       redoParagraphs(pit, boost::next(pit));
+}
+
+
 void LyXText::fullRebreak()
 {
        init(bv());
@@ -948,7 +963,7 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
        }
        postPaint();
 
-       redoParagraphs(selection.start, endpit);
+       redoParagraphs(selection.start.par(), endpit);
 
        clearSelection();
        setCursor(selection.start.par(), selection.start.pos());
@@ -1279,7 +1294,7 @@ void LyXText::cutSelection(bool doclear, bool realcut)
        if (doclear)
                selection.start.par()->stripLeadingSpaces();
 
-       redoParagraphs(selection.start, boost::next(endpit));
+       redoParagraphs(selection.start.par(), boost::next(endpit));
 #warning FIXME latent bug
        // endpit will be invalidated on redoParagraphs once ParagraphList
        // becomes a std::list? There are maybe other places on which this
@@ -1347,7 +1362,7 @@ void LyXText::pasteSelection(size_t sel_index)
        bufferErrors(*bv()->buffer(), el);
        bv()->showErrorList(_("Paste"));
 
-       redoParagraphs(cursor, endpit);
+       redoParagraphs(cursor.par(), endpit);
 
        setCursor(cursor.par(), cursor.pos());
        clearSelection();
@@ -1417,7 +1432,7 @@ void LyXText::insertStringAsLines(string const & str)
 
        bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
 
-       redoParagraphs(cursor, endpit);
+       redoParagraphs(cursor.par(), endpit);
        setCursor(cursor.par(), cursor.pos());
        selection.cursor = cursor;
        setCursor(pit, pos);
@@ -2067,7 +2082,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
                    && old_cursor.par()->isLineSeparator(old_cursor.pos())
                    && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
                        old_cursor.par()->erase(old_cursor.pos() - 1);
-                       redoParagraphs(old_cursor, boost::next(old_cursor.par()));
+                       redoParagraph(old_cursor.par());
 
 #ifdef WITH_WARNINGS
 #warning This will not work anymore when we have multiple views of the same buffer
@@ -2185,7 +2200,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
        }
        if (!deleted) {
                if (old_cursor.par()->stripLeadingSpaces()) {
-                       redoParagraphs(old_cursor, boost::next(old_cursor.par()));
+                       redoParagraph(old_cursor.par());
                        // correct cursor y
                        setCursorIntern(cursor.par(), cursor.pos());
                        selection.cursor = cursor;