[LyX/master] Implement CanBreakBefore row flag

Jean-Marc Lasgouttes lasgouttes at lyx.org
Thu Jun 9 18:50:18 UTC 2022


commit 254b2b0bfa68420b612a1be7b2a59ec38cf7888f
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Thu Jun 9 21:27:43 2022 +0200

    Implement CanBreakBefore row flag
    
    This is used for elements that allow to break a row before them
    (similar to CanBreakAfter).
---
 src/Row.cpp    |   12 +++++++++++-
 src/RowFlags.h |   29 +++++++++++++++--------------
 2 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/src/Row.cpp b/src/Row.cpp
index 3d5ab90..68ab984 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -562,7 +562,7 @@ Row::Elements Row::shortenIfNeeded(int const w, int const next_width)
 		Element brk = *cit_brk;
 		/* If the current element is an inset that allows breaking row
 		 * after itself, and if the row is already short enough after
-		 * this inset, then cut right after this element.
+		 * this element, then cut right after it.
 		 */
 		if (wid_brk <= w && brk.row_flags & CanBreakAfter) {
 			end_ = brk.endpos;
@@ -572,6 +572,16 @@ Row::Elements Row::shortenIfNeeded(int const w, int const next_width)
 		}
 		// assume now that the current element is not there
 		wid_brk -= brk.dim.wid;
+		/* If the current element is an inset that allows breaking row
+		 * before itself, and if the row is already short enough before
+		 * this element, then cut right before it.
+		 */
+		if (wid_brk <= w && brk.row_flags & CanBreakBefore && cit_brk != beg) {
+			end_ = (cit_brk -1)->endpos;
+			dim_.wid = wid_brk;
+			moveElements(elements_, cit_brk, tail);
+			return tail;
+		}
 		/* We have found a suitable separable element. This is the common case.
 		 * Try to break it cleanly at a length that is both
 		 * - less than the available space on the row
diff --git a/src/RowFlags.h b/src/RowFlags.h
index 01c4dd2..953d7f9 100644
--- a/src/RowFlags.h
+++ b/src/RowFlags.h
@@ -16,10 +16,9 @@
 
 namespace lyx {
 
-/* The list of possible flags, that can be combined.
- * Some flags that should logically be here (e.g.,
- * CanBreakBefore), do not exist. This is because the need has not
- * been identitfied yet.
+/* The list of possible flags, that can be combined. Some flags that
+ * should logically be here (e.g., AlwaysBreakBefore), do not exist.
+ * This is because the need has not been identitfied yet.
  *
  * Priorities when before/after disagree:
  *      AlwaysBreak* > NoBreak* > Break* or CanBreak*.
@@ -30,26 +29,28 @@ enum RowFlags {
 	Inline = 0,
 	// break row before this element if the row is not empty
 	BreakBefore = 1 << 0,
+	// break row whenever needed before this element
+	CanBreakBefore = 1 << 1,
 	// Avoid breaking row before this element
-	NoBreakBefore = 1 << 1,
+	NoBreakBefore = 1 << 2,
 	// flush the row before this element (useful with BreakBefore)
-	FlushBefore = 1 << 2,
+	FlushBefore = 1 << 3,
 	// force new (maybe empty) row after this element
-	AlwaysBreakAfter = 1 << 3,
+	AlwaysBreakAfter = 1 << 4,
 	// break row after this element if there are more elements
-	BreakAfter = 1 << 4,
+	BreakAfter = 1 << 5,
 	// break row whenever needed after this element
-	CanBreakAfter = 1 << 5,
+	CanBreakAfter = 1 << 6,
 	// Avoid breaking row after this element
-	NoBreakAfter = 1 << 6,
+	NoBreakAfter = 1 << 7,
 	// The contents of the row may be broken in two (e.g. string)
-	CanBreakInside = 1 << 7,
+	CanBreakInside = 1 << 8,
 	// Flush the row that ends with this element
-	Flush = 1 << 8,
+	Flush = 1 << 9,
 	// specify an alignment (left, right) for a display element
 	// (default is center)
-	AlignLeft = 1 << 9,
-	AlignRight = 1 << 10,
+	AlignLeft = 1 << 10,
+	AlignRight = 1 << 11,
 	// A display element breaks row at both ends
 	Display = FlushBefore | BreakBefore | BreakAfter,
 	// Flags that concern breaking after element


More information about the lyx-cvs mailing list