[LyX/master] Correctly show merged paragraphs with change tracking

Juergen Spitzmueller spitz at lyx.org
Thu Dec 26 12:31:59 UTC 2019


commit afb442c76c53c37789680cb9814863e02dfc9663
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Thu Dec 26 13:47:50 2019 +0100

    Correctly show merged paragraphs with change tracking
    
    Fixes #3136
---
 src/Paragraph.cpp    |    5 +++++
 src/Paragraph.h      |    2 ++
 src/output_latex.cpp |   27 ++++++++++++++++++---------
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index eb2bb95..3c4919c 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -621,6 +621,11 @@ bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
 	return change.inserted() && change.currentAuthor();
 }
 
+Change Paragraph::parEndChange() const
+{
+	return d->changes_.lookup(size());
+}
+
 
 void Paragraph::setChange(Change const & change)
 {
diff --git a/src/Paragraph.h b/src/Paragraph.h
index dbf7f2a..091c604 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -279,6 +279,8 @@ public:
 	/// will the paragraph be physically merged with the next
 	/// one if the imaginary end-of-par character is logically deleted?
 	bool isMergedOnEndOfParDeletion(bool trackChanges) const;
+	/// Return Change form of paragraph break
+	Change parEndChange() const;
 
 	/// set change for the entire par
 	void setChange(Change const & change);
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 89974bb..7849db5 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -769,11 +769,14 @@ void TeXOnePar(Buffer const & buf,
 		state->open_encoding_ = none;
 	}
 
+	// This paragraph is merged and we do not show changes in the output
+	bool const merged_par = !bparams.output_changes && par.parEndChange().deleted();
+
 	if (text.inset().isPassThru()) {
 		Font const outerfont = text.outerFont(pit);
 
 		// No newline before first paragraph in this lyxtext
-		if (pit > 0 && !text.inset().getLayout().parbreakIgnored()) {
+		if (pit > 0 && !text.inset().getLayout().parbreakIgnored() && !merged_par) {
 			os << '\n';
 			if (!text.inset().getLayout().parbreakIsNewline())
 				os << '\n';
@@ -813,17 +816,20 @@ void TeXOnePar(Buffer const & buf,
 			if (par.needsCProtection(runparams.moving_arg)
 			    && contains(runparams.active_chars, '^'))
 				os << "\\endgroup";
-			os << "\n";
+			if (merged_par)
+				os << "{}";
+			else
+				os << "\n";
 		}
-		else
+		else if (!merged_par)
 			os << '\n';
-		if (!style.parbreak_is_newline) {
+		if (!style.parbreak_is_newline && !merged_par) {
 			os << '\n';
 		} else if (nextpar && !style.isEnvironment()) {
 			Layout const nextstyle = text.inset().forcePlainLayout()
 				? bparams.documentClass().plainLayout()
 				: nextpar->layout();
-			if (nextstyle.name() != style.name())
+			if (nextstyle.name() != style.name() && !merged_par)
 				os << '\n';
 		}
 
@@ -1176,7 +1182,7 @@ void TeXOnePar(Buffer const & buf,
 			    && nextpar->getDepth() < par.getDepth()))
 			close_lang_switch = using_begin_end;
 		if (nextpar && par.params().depth() < nextpar->params().depth())
-			pending_newline = !text.inset().getLayout().parbreakIgnored();
+			pending_newline = !text.inset().getLayout().parbreakIgnored() && !merged_par;
 		break;
 	case LATEX_ENVIRONMENT: {
 		// if it's the last paragraph of the current environment
@@ -1195,7 +1201,7 @@ void TeXOnePar(Buffer const & buf,
 	default:
 		// we don't need it for the last paragraph and in InTitle commands!!!
 		if (nextpar && !intitle_command)
-			pending_newline = !text.inset().getLayout().parbreakIgnored();
+			pending_newline = !text.inset().getLayout().parbreakIgnored() && !merged_par;
 	}
 
 	// InTitle commands use switches (not environments) for space settings
@@ -1415,7 +1421,7 @@ void TeXOnePar(Buffer const & buf,
 	// TeXEnvironment, because it is needed in this case
 	if (nextpar && !os.afterParbreak() && !last_was_separator) {
 		Layout const & next_layout = nextpar->layout();
-		if (!text.inset().getLayout().parbreakIgnored())
+		if (!text.inset().getLayout().parbreakIgnored() && !merged_par)
 			// Make sure to start a new line
 			os << breakln;
 		// A newline '\n' is always output before a command,
@@ -1459,7 +1465,10 @@ void TeXOnePar(Buffer const & buf,
 				&& next_layout.align == nextpar->getAlign(bparams))
 			    || (style.align != par.getAlign(bparams)
 				&& tclass.isDefaultLayout(next_layout))) {
-				os << '\n';
+				// and omit paragraph break if it has been deleted with ct
+				// and changes are not shown in output
+				if (!merged_par)
+					os << '\n';
 			}
 		}
 	}


More information about the lyx-cvs mailing list