Two blocks of code differed very little so I combined them. I'm not
sure what LyX's style norms are about this. I like this because (1)
now it is not easy to change in one place and forget about the other
and (2) it's easy to see exactly where the code differs between the
two.

Opinions?

Scott
From 555ffaaba247f5a4ba77e536e14c28f7c4613222 Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <[email protected]>
Date: Sat, 7 Jun 2014 00:41:20 -0400
Subject: [PATCH] Combine OutlineIn and OutlineOut blocks

They differ only by adding/subtracting 1.
---
 src/Text3.cpp | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/src/Text3.cpp b/src/Text3.cpp
index b78ba15..ccd8de3 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -409,7 +409,8 @@ static void outline(OutlineOp mode, Cursor & cur)
 			cur.pit() = newpit - len;
 			break;
 		}
-		case OutlineIn: {
+		case OutlineIn:
+		case OutlineOut: {
 			pit_type const len = distance(start, finish);
 			buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
 			for (; start != finish; ++start) {
@@ -419,7 +420,8 @@ static void outline(OutlineOp mode, Cursor & cur)
 				DocumentClass::const_iterator lit = tc.begin();
 				DocumentClass::const_iterator len = tc.end();
 				for (; lit != len; ++lit) {
-					if (lit->toclevel == toclevel + 1 &&
+					if (lit->toclevel == (mode == OutlineIn ?
+							      toclevel + 1 : toclevel - 1) &&
 					    start->layout().labeltype == lit->labeltype) {
 						start->setLayout(*lit);
 						break;
@@ -428,25 +430,6 @@ static void outline(OutlineOp mode, Cursor & cur)
 			}
 			break;
 		}
-		case OutlineOut: {
-			pit_type const len = distance(start, finish);
-			buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
-			for (; start != finish; ++start) {
-				toclevel = buf.text().getTocLevel(distance(bgn, start));
-				if (toclevel == Layout::NOT_IN_TOC)
-					continue;
-				DocumentClass::const_iterator lit = tc.begin();
-				DocumentClass::const_iterator len = tc.end();
-				for (; lit != len; ++lit) {
-					if (lit->toclevel == toclevel - 1 &&
-						start->layout().labeltype == lit->labeltype) {
-							start->setLayout(*lit);
-							break;
-					}
-				}
-			}
-			break;
-		}
 	}
 }
 
-- 
1.9.1

Reply via email to