From 278ccb1e2c37b385c1f27b2fd37dae5d4389b2f1 Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Mon, 8 Dec 2003 12:47:18 +0000 Subject: [PATCH] lyxtext.h, text2.C (setLayout): don't use cursor to iterate when a pit is enough. Standarize a couple of loops. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8211 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++ src/lyxtext.h | 5 +-- src/text2.C | 118 +++++++++++++++++++------------------------------- 3 files changed, 51 insertions(+), 77 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b8e67ebaa0..21034c64ac 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-12-08 Alfredo Braunstein + + * lyxtext.h, text2.C (setLayout): don't use cursor to iterate, + when a pit is enough. Standarize a couple of loops. + 2003-12-05 Angus Leeming * lyxfunc.C (dispatch): DIALOG_SHOW now handles "latexlog" and diff --git a/src/lyxtext.h b/src/lyxtext.h index a5a82ffdb1..799d02ed23 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -81,9 +81,8 @@ public: those paragraphs */ ParagraphList::iterator - setLayout(LyXCursor & actual_cursor, - LyXCursor & selection_start, - LyXCursor & selection_end, + setLayout(ParagraphList::iterator start, + ParagraphList::iterator end, std::string const & layout); /// void setLayout(std::string const & layout); diff --git a/src/text2.C b/src/text2.C index 38e5b8497f..41601ebcd0 100644 --- a/src/text2.C +++ b/src/text2.C @@ -269,46 +269,32 @@ void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params, ParagraphList::iterator -LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur, - LyXCursor & send_cur, +LyXText::setLayout(ParagraphList::iterator start, + ParagraphList::iterator end, string const & layout) { - ParagraphList::iterator endpit = boost::next(getPar(send_cur)); - ParagraphList::iterator undoendpit = endpit; + ParagraphList::iterator undopit = end; ParagraphList::iterator pars_end = paragraphs().end(); - if (endpit != pars_end && endpit->getDepth()) { - while (endpit != pars_end && endpit->getDepth()) { - ++endpit; - undoendpit = endpit; - } - } else if (endpit != pars_end) { - // because of parindents etc. - ++endpit; - } - - recUndo(sstart_cur.par(), parOffset(undoendpit) - 1); - - // ok we have a selection. This is always between sstart_cur - // and sel_end cursor - cur = sstart_cur; - ParagraphList::iterator pit = getPar(sstart_cur); - ParagraphList::iterator epit = boost::next(getPar(send_cur)); + while (undopit != pars_end && undopit->getDepth()) + ++undopit; + //because of parindets etc + if (undopit != pars_end) + ++undopit; + recUndo(parOffset(start), parOffset(undopit) - 1); BufferParams const & bufparams = bv()->buffer()->params(); LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout]; - do { + for (ParagraphList::iterator pit = start; pit != end; ++pit) { pit->applyLayout(lyxlayout); makeFontEntriesLayoutSpecific(bufparams, *pit); if (lyxlayout->margintype == MARGIN_MANUAL) pit->setLabelWidthString(lyxlayout->labelstring()); - cur.par(std::distance(paragraphs().begin(), pit)); - ++pit; - } while (pit != epit); + } - return endpit; + return undopit; } @@ -335,9 +321,11 @@ void LyXText::setLayout(string const & layout) return; } - ParagraphList::iterator endpit = setLayout(cursor, selection.start, - selection.end, layout); - redoParagraphs(getPar(selection.start), endpit); + ParagraphList::iterator start = getPar(selection.start.par()); + ParagraphList::iterator end = boost::next(getPar(selection.end.par())); + ParagraphList::iterator endpit = setLayout(start, end, layout); + + redoParagraphs(start, endpit); updateCounters(); redoCursor(); } @@ -430,11 +418,11 @@ void LyXText::setFont(LyXFont const & font, bool toggleall) if (!selection.set()) { // Determine basis font LyXFont layoutfont; - if (cursor.pos() < cursorPar()->beginOfBody()) { + if (cursor.pos() < cursorPar()->beginOfBody()) layoutfont = getLabelFont(cursorPar()); - } else { + else layoutfont = getLayoutFont(cursorPar()); - } + // Update current font real_current_font.update(font, bv()->buffer()->params().language, @@ -597,36 +585,26 @@ string LyXText::getStringToIndex() // they do not duplicate themself and you cannot play dirty tricks with // them! -void LyXText::setParagraph( - Spacing const & spacing, - LyXAlignment align, - string const & labelwidthstring, - bool noindent) +void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align, + string const & labelwidthstring, bool noindent) { setSelection(); // make sure that the depth behind the selection are restored, too ParagraphList::iterator endpit = boost::next(getPar(selection.end)); - ParagraphList::iterator undoendpit = endpit; ParagraphList::iterator pars_end = paragraphs().end(); - if (endpit != pars_end && endpit->getDepth()) { - while (endpit != pars_end && endpit->getDepth()) { - ++endpit; - undoendpit = endpit; - } - } else if (endpit != pars_end) { - // because of parindents etc. + while (endpit != pars_end && endpit->getDepth()) + ++endpit; + // because of parindents etc. + if (endpit != pars_end) ++endpit; - } - recUndo(selection.start.par(), parOffset(undoendpit) - 1); + recUndo(selection.start.par(), parOffset(endpit) - 1); - int tmppit = selection.end.par(); + ParagraphList::reverse_iterator pit(getPar(selection.end.par())); + ParagraphList::reverse_iterator beg(getPar(selection.start.par())); - while (tmppit != selection.start.par() - 1) { - setCursor(tmppit, 0); - - ParagraphList::iterator const pit = cursorPar(); + for (++beg; pit != beg; ++pit) { ParagraphParameters & params = pit->params(); params.spacing(spacing); @@ -643,7 +621,6 @@ void LyXText::setParagraph( } pit->setLabelWidthString(labelwidthstring); params.noindent(noindent); - --tmppit; } redoParagraphs(getPar(selection.start), endpit); @@ -982,43 +959,38 @@ void LyXText::cutSelection(bool doclear, bool realcut) // and selection.end // make sure that the depth behind the selection are restored, too - ParagraphList::iterator endpit = boost::next(getPar(selection.end.par())); - ParagraphList::iterator undoendpit = endpit; + ParagraphList::iterator begpit = getPar(selection.start.par()); + ParagraphList::iterator endpit = getPar(selection.end.par()); + ParagraphList::iterator undopit = boost::next(endpit); ParagraphList::iterator pars_end = paragraphs().end(); - if (endpit != pars_end && endpit->getDepth()) { - while (endpit != pars_end && endpit->getDepth()) { - ++endpit; - undoendpit = endpit; - } - } else if (endpit != pars_end) { - // because of parindents etc. - ++endpit; - } + while (undopit != pars_end && undopit->getDepth()) + ++undopit; + //because of parindents etc. + if (undopit != pars_end) + ++undopit; + recUndo(selection.start.par(), parOffset(undopit) - 1); - recUndo(selection.start.par(), parOffset(undoendpit) - 1); - - endpit = getPar(selection.end.par()); int endpos = selection.end.pos(); BufferParams const & bufparams = bv()->buffer()->params(); boost::tie(endpit, endpos) = realcut ? CutAndPaste::cutSelection(bufparams, paragraphs(), - getPar(selection.start.par()), endpit, + begpit , endpit, selection.start.pos(), endpos, bufparams.textclass, doclear) : CutAndPaste::eraseSelection(bufparams, paragraphs(), - getPar(selection.start.par()), endpit, + begpit, endpit, selection.start.pos(), endpos, doclear); // sometimes necessary if (doclear) - getPar(selection.start.par())->stripLeadingSpaces(); + begpit->stripLeadingSpaces(); - redoParagraphs(getPar(selection.start.par()), boost::next(endpit)); + redoParagraphs(begpit, undopit); // cutSelection can invalidate the cursor so we need to set // it anew. (Lgb) // we prefer the end for when tracking changes @@ -1027,9 +999,7 @@ void LyXText::cutSelection(bool doclear, bool realcut) // need a valid cursor. (Lgb) clearSelection(); - - setCursor(cursorPar(), cursor.pos()); - selection.cursor = cursor; + redoCursor(); updateCounters(); }