[LyX/master] Refresh previews on branch toggle

Scott Kostyshak skostysh at lyx.org
Wed Dec 11 16:33:44 UTC 2019


commit f1accdebf3feb42e4eacb615237204cfa8d61747
Author: Scott Kostyshak <skostysh at lyx.org>
Date:   Wed Dec 11 11:46:56 2019 -0500

    Refresh previews on branch toggle
    
    We only referesh previews if the branch that is toggled exists in a
    descendant. This code could be further optimized, as noted in the
    comments.
    
    For relevant discussion, see the following ML thread:
    
    https://www.mail-archive.com/search?l=mid&q=20191209022030.d6gyy3abdectr3yz%40tallinn
---
 src/insets/InsetBranch.cpp |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp
index 88d00e6..ecce379 100644
--- a/src/insets/InsetBranch.cpp
+++ b/src/insets/InsetBranch.cpp
@@ -190,6 +190,21 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
 			// cur.forceBufferUpdate() is not enough
 			buf->updateBuffer();
 		}
+
+		// if branch exists in a descendant, update previews.
+		// TODO: only needed if "Show preview" is enabled in the included inset.
+		bool exists_in_desc = false;
+		for (auto const & it : buf->getDescendents()) {
+			if (it->params().branchlist().find(params_.branch))
+				exists_in_desc = true;
+		}
+		if (exists_in_desc) {
+			// TODO: ideally we would only update the previews of the
+			// specific children that have this branch directly or
+			// in one of their descendants
+			buf->removePreviews();
+			buf->updatePreviews();
+		}
 		break;
 	}
 	case LFUN_BRANCH_INVERT:


More information about the lyx-cvs mailing list