fixed Resizing window resets window contents #479

This commit is contained in:
Jan Prochazka
2023-03-12 08:45:28 +01:00
parent edc3a7409a
commit b2f55522a8
2 changed files with 16 additions and 5 deletions

View File

@@ -1,5 +1,8 @@
<script context="module">
export function computeSplitterSize(initialValue, clientSize) {
export function computeSplitterSize(initialValue, clientSize, customRatio) {
if (customRatio != null) {
return clientSize * customRatio;
}
if (_.isString(initialValue) && initialValue.startsWith('~') && initialValue.endsWith('px'))
return clientSize - parseInt(initialValue.slice(1, -2));
if (_.isString(initialValue) && initialValue.endsWith('px')) return parseInt(initialValue.slice(0, -2));
@@ -27,8 +30,9 @@
export let size = 0;
let clientWidth;
let customRatio = null;
$: size = computeSplitterSize(initialValue, clientWidth);
$: size = computeSplitterSize(initialValue, clientWidth, customRatio);
</script>
<div class="container" bind:clientWidth>
@@ -52,7 +56,10 @@
class="horizontal-split-handle"
style={collapsed1 || collapsed2 ? 'display:none' : ''}
use:splitterDrag={'clientX'}
on:resizeSplitter={e => (size += e.detail)}
on:resizeSplitter={e => {
size += e.detail;
if (clientWidth > 0) customRatio = size / clientWidth;
}}
/>
{/if}
<div

View File

@@ -16,8 +16,9 @@
let collapsed1 = false;
let collapsed2 = false;
let customRatio = null;
$: size = computeSplitterSize(initialValue, clientHeight);
$: size = computeSplitterSize(initialValue, clientHeight, customRatio);
</script>
<div class="container" bind:clientHeight>
@@ -38,7 +39,10 @@
class={'vertical-split-handle'}
style={collapsed1 || collapsed2 ? 'display:none' : ''}
use:splitterDrag={'clientY'}
on:resizeSplitter={e => (size += e.detail)}
on:resizeSplitter={e => {
size += e.detail;
if (clientHeight > 0) customRatio = size / clientHeight;
}}
/>
<div
class={collapsed1 ? 'child1' : 'child2'}