Fix CodeMirror not properly sized when opening editor (#2426)

* Revert "Fix open editors getting carried over to different notetypes (#2393)"

This reverts commit bf5bcd3f52.

* Fix CodeMirror not properly sized when opening editor

If the initial value of a tweened store is 'undefined' or 'null', the
first value change will take effect immediately. Therefore, by setting
the initial value of 'size' to 'undefined', 'collpased' will be set to
'false' with no transition time if 'false' is passed to 'collapse' prop,
ensuring that CodeMirror is properly sized.
This commit is contained in:
Hikaru Y 2023-03-08 18:46:50 +09:00 committed by GitHub
parent fd688b5fc0
commit a32c7a8e63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,7 +18,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
$: duration = dynamicDuration(contentHeight); $: duration = dynamicDuration(contentHeight);
const size = tweened<number>(0); const size = tweened<number | undefined>(undefined);
async function transition(collapse: boolean): Promise<void> { async function transition(collapse: boolean): Promise<void> {
if (collapse) { if (collapse) {
@ -50,10 +50,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let collapsibleElement: HTMLElement; let collapsibleElement: HTMLElement;
$: collapsed = $size === 0; $: collapsed = ($size ?? 0) === 0;
$: expanded = $size === 1; $: expanded = $size === 1;
$: height = $size * contentHeight; $: height = ($size ?? 0) * contentHeight;
$: transitioning = $size > 0 && !(collapsed || expanded); $: transitioning = ($size ?? 0) > 0 && !(collapsed || expanded);
$: measuring = !(collapsed || transitioning || expanded); $: measuring = !(collapsed || transitioning || expanded);
let hidden = collapsed; let hidden = collapsed;