On Sun, 2006-11-12 at 07:19 +0100, Abdelrazak Younes wrote:
> Martin Vermeer wrote:
> > On Fri, 10 Nov 2006 17:06:00 +0100 Abdelrazak Younes <[EMAIL PROTECTED]> 
> > wrote:
> > 
> >> Martin Vermeer wrote:
> >>> On Fri, 2006-11-10 at 11:09 +0100, Jean-Marc Lasgouttes wrote:
> >>>>>>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes:
> >>>> Martin> Before going to work on this, consider the patch (for 1.4)
> >>>> Martin> that I submitted a while ago and may be relevant. Attached
> >>>> Martin> again.
> >>>>
> >>>> Martin, I finally tested your patch! Better late than never...
> >>>>
> >>>> It works as advertised. Please apply (with status.14x entry!) and
> >>>> close the relevant bug.
> >>> So done, thanks. (What was the bug number? Don't find it.) Should
> >> this
> >>> go into 1.5 too?
> >>>
> >>>         * src/toc.C
> >>>         (outline): Fix undo bug in TOC navigation
> >> If it is a fix, why not?
> >>
> >> Abdel.
> > 
> > Is the code base still close enough? I remember you did things there.
> 
> yes, I didn't touch the contents of outline at all.
> 
> Abdel.

Somebody did... a whitespace clean-up. Patch applied cleanly with -l
switch.

Anyway, here is the patch. Untested.

- Martin

Index: toc.C
===================================================================
--- toc.C	(revision 15698)
+++ toc.C	(working copy)
@@ -123,13 +123,14 @@ string const getGuiName(string const & t
 
 void outline(OutlineOp mode,  LCursor & cur)
 {
-	recordUndo(cur);
 	Buffer * buf = & cur.buffer();
 	pit_type & pit = cur.pit();
 	ParagraphList & pars = buf->text().paragraphs();
 	ParagraphList::iterator bgn = pars.begin();
-	ParagraphList::iterator s = boost::next(bgn, pit);
-	ParagraphList::iterator p = s;
+	// The first paragraph of the area to be copied:
+	ParagraphList::iterator start = boost::next(bgn, pit);
+	// The final paragraph of area to be copied:
+	ParagraphList::iterator finish = start;
 	ParagraphList::iterator end = pars.end();
 
 	LyXTextClass::const_iterator lit =
@@ -137,86 +138,101 @@ void outline(OutlineOp mode,  LCursor & 
 	LyXTextClass::const_iterator const lend =
 		buf->params().getLyXTextClass().end();
 
-	int const thistoclevel = s->layout()->toclevel;
+	int const thistoclevel = start->layout()->toclevel;
 	int toclevel;
 	switch (mode) {
 		case Up: {
-			if (p != end)
-				++p;
-			for (; p != end; ++p) {
-				toclevel = p->layout()->toclevel;
+			// Move out (down) from this section header
+			if (finish != end)
+				++finish;
+			// Seek the one (on same level) below
+			for (; finish != end; ++finish) {
+				toclevel = finish->layout()->toclevel;
 				if (toclevel != LyXLayout::NOT_IN_TOC
 				    && toclevel <= thistoclevel) {
 					break;
 				}
 			}
-			ParagraphList::iterator q = s;
-			if (q != bgn)
-				--q;
+			ParagraphList::iterator dest = start;
+			// Move out (up) from this header
+			if (dest != bgn)
+				--dest;
 			else
 				break;
-			for (; q != bgn; --q) {
-				toclevel = q->layout()->toclevel;
+			// Search previous same-level header above
+			for (; dest != bgn; --dest) {
+				toclevel = dest->layout()->toclevel;
 				if (toclevel != LyXLayout::NOT_IN_TOC
 				    && toclevel <= thistoclevel) {
 					break;
 				}
 			}
-			pit_type const newpit = std::distance(pars.begin(), q);
-			pit_type const len = std::distance(s, p);
+			// Not found; do nothing
+			if (dest == bgn)
+				break;
+			pit_type const newpit = std::distance(bgn, dest);
+			pit_type const len = std::distance(start, finish);
 			pit += len;
-			pars.insert(q, s, p);
-			s = boost::next(pars.begin(), pit);
-			ParagraphList::iterator t = boost::next(s, len);
+			pit = std::min(pit, cur.lastpit());
+			recordUndo(cur, Undo::ATOMIC, newpit, pit);
+			pars.insert(dest, start, finish);
+			start = boost::next(bgn, pit);
 			pit = newpit;
-			pars.erase(s, t);
+			pars.erase(start, finish);
 		break;
 		}
 		case Down: {
-			   if (p != end)
-				++p;
-			for (; p != end; ++p) {
-				toclevel = p->layout()->toclevel;
+			// Go down out of current header:
+   			if (finish != end)
+				++finish;
+			// Find next same-level header:
+			for (; finish != end; ++finish) {
+				toclevel = finish->layout()->toclevel;
 				if (toclevel != LyXLayout::NOT_IN_TOC
 				    && toclevel <= thistoclevel) {
 					break;
 				}
 			}
-			ParagraphList::iterator q = p;
-			if (q != end)
-				++q;
+			ParagraphList::iterator dest = finish;
+			// Go one down from *this* header:
+			if (dest != end)
+				++dest;
 			else
 				break;
-			for (; q != end; ++q) {
-				toclevel = q->layout()->toclevel;
+			// Go further down to find header to insert in front of:
+			for (; dest != end; ++dest) {
+				toclevel = dest->layout()->toclevel;
 				if (toclevel != LyXLayout::NOT_IN_TOC
 				    && toclevel <= thistoclevel) {
 					break;
 				}
 			}
-			pit_type const newpit = std::distance(pars.begin(), q);
-			pit_type const len = std::distance(s, p);
-			pars.insert(q, s, p);
-			s = boost::next(pars.begin(), pit);
-			ParagraphList::iterator t = boost::next(s, len);
+			// One such was found:
+			pit_type newpit = std::distance(bgn, dest);
+			pit_type const len = std::distance(start, finish);
+			recordUndo(cur, Undo::ATOMIC, pit, newpit -1);
+			pars.insert(dest, start, finish);
+			start = boost::next(bgn, pit);
 			pit = newpit - len;
-			pars.erase(s, t);
+			pars.erase(start, finish);
 		break;
 		}
 		case In:
+			recordUndo(cur);
 			for (; lit != lend; ++lit) {
 				if ((*lit)->toclevel == thistoclevel + 1 &&
-				    s->layout()->labeltype == (*lit)->labeltype) {
-					s->layout((*lit));
+				    start->layout()->labeltype == (*lit)->labeltype) {
+					start->layout((*lit));
 					break;
 				}
 			}
 		break;
 		case Out:
+			recordUndo(cur);
 			for (; lit != lend; ++lit) {
 				if ((*lit)->toclevel == thistoclevel - 1 &&
-				    s->layout()->labeltype == (*lit)->labeltype) {
-					s->layout((*lit));
+				    start->layout()->labeltype == (*lit)->labeltype) {
+					start->layout((*lit));
 					break;
 				}
 			}

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to