From 30f822d59fe5d4765a2f255f11dd52d95f938d88 Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Tue, 26 Mar 2024 05:09:41 +0100 Subject: [PATCH] dynanode: set only intrinsic height and only if needed --- TiddlyFlex/files/modules/widgets/dynanode.js | 32 +++++++++++++------- TiddlyFlex/plugin.info | 2 +- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/TiddlyFlex/files/modules/widgets/dynanode.js b/TiddlyFlex/files/modules/widgets/dynanode.js index 92007ac..1d3ee08 100644 --- a/TiddlyFlex/files/modules/widgets/dynanode.js +++ b/TiddlyFlex/files/modules/widgets/dynanode.js @@ -109,14 +109,11 @@ DynaNodeWidget.prototype.render = function(parent,nextSibling) { self.dynanodeElements.push(entry); } var target = entry.target ? entry.target : entry; - if(entry.target && entry.target.getAttribute("data-tiddler-title") && entry.target.getAttribute("data-tiddler-title") === "New Tiddler") { - console.log(entry.borderBoxSize); - } var rect; if(entry.target) { rect = { - width: entry.borderBoxSize[0].inlineSize, - height: entry.borderBoxSize[0].blockSize + width: entry.contentBoxSize[0].inlineSize, + height: entry.contentBoxSize[0].blockSize } } self.checkVisibility(target,rect); @@ -236,14 +233,27 @@ DynaNodeWidget.prototype.checkVisibility = function(element,rect) { newValue = currValue; var elementRect = element.getBoundingClientRect(); + var height, + oldHeight; if(rect) { - $tw.utils.setStyle(element,[ - { containIntrinsicSize: `${rect.width}px ${rect.height}px` } - ]); + height = rect.height; + oldHeight = this.spaced.get(element); + if(!oldHeight || (oldHeight !== height)) { + this.spaced.set(element,height); + $tw.utils.setStyle(element,[ + { containIntrinsicHeight: `${rect.height}px` } + ]); + } } else { - $tw.utils.setStyle(element,[ - { containIntrinsicSize: `${elementRect.width}px ${elementRect.height}px` } - ]); + var computedStyle = this.domNode.ownerDocument.defaultView.getComputedStyle(element); + height = elementRect.height - (parseFloat(computedStyle.paddingTop) + parseFloat(computedStyle.paddingBottom) + parseFloat(computedStyle.borderTopWidth) + parseFloat(computedStyle.borderBottomWidth)); + oldHeight = this.spaced.get(element); + if(!oldHeight || (oldHeight !== height)) { + this.spaced.set(element,height); + $tw.utils.setStyle(element,[ + { containIntrinsicHeight: `${elementRect.height}px` } + ]); + } } // Within viewport diff --git a/TiddlyFlex/plugin.info b/TiddlyFlex/plugin.info index 166e617..4c25946 100644 --- a/TiddlyFlex/plugin.info +++ b/TiddlyFlex/plugin.info @@ -4,7 +4,7 @@ "name": "TiddlyFlex", "plugin-type": "plugin", "author": "Simon Huber", - "version": "0.0.169", + "version": "0.0.170", "core-version": ">=5.3.3", "source": "https://github.com/BurningTreeC/TiddlyFlex", "list": "readme license"