fix: filetree no longer expanded by default
mellbacon committed
Jul 15, 2023 at 12:39 UTC
f849718c86adc0773544a689b14cba8ef08cce0d
3 files changed
+14
-7
src/lib/FileTree/FileTreeList.svelte
+10
-3
@@ -14,6 +14,7 @@
14
import { clipboard } from "@tauri-apps/api";
15
import { openInputModal, openRenameModal } from "../../App.svelte";
16
import { path as p } from "@tauri-apps/api";
17
+ import { onMount } from "svelte";
18
19
export let root = false;
20
export let isroot = false;
@@ -24,8 +25,9 @@
25
export let children = [];
26
export let contextMenuEnabled;
27
export let iconsEnabled;
28
+ export let isExpanded;
29
28
- export let expanded = _expansionState[name] || false;
30
+ let expanded = _expansionState[name] || false;
31
let ref = null;
32
let refLabel = null;
33
let refChildren = null;
@@ -59,6 +61,11 @@
61
{name: "Delete", disabled: isroot, shortcut: "Delete", action: async () => {await moveToTrash(path)}}
62
]
63
64
+ onMount(() => {
65
+ if (isExpanded) {
66
+ expanded = _expansionState[name] = !expanded;
67
+ }
68
+ })
69
function findNode(nodeid, tree = null) {
70
if (!tree) {
71
tree = $filetree;
@@ -162,7 +169,7 @@
169
{#if root}
170
{#each children as child}
171
{#if Array.isArray(child.children)}
165
- <svelte:self on:nodeselect on:dblnodeselect isroot={root} {...child} {contextMenuEnabled} {expanded} {iconsEnabled}></svelte:self>
172
+ <svelte:self on:nodeselect on:dblnodeselect isroot={root} {...child} {contextMenuEnabled} {iconsEnabled} {isExpanded}></svelte:self>
173
{:else}
174
<FileTreeNode on:nodeselect on:dblnodeselect {...child} {contextMenuEnabled} {iconsEnabled}/>
175
{/if}
@@ -185,7 +192,7 @@
192
<ul role="group" bind:this={refChildren} data-id={id} class="tree-children" on:dragover|preventDefault on:drop|stopPropagation={drop}>
193
{#each children as child (child.id) }
194
{#if Array.isArray(child.children)}
188
- <svelte:self on:nodeselect on:dblnodeselect {...child} {contextMenuEnabled} {expanded} {iconsEnabled}></svelte:self>
195
+ <svelte:self on:nodeselect on:dblnodeselect {...child} {contextMenuEnabled} {iconsEnabled} {isExpanded}></svelte:self>
196
{:else}
197
<FileTreeNode on:nodeselect on:dblnodeselect {...child} {contextMenuEnabled} {iconsEnabled} />
198
{/if}
src/lib/FileTree/FileTreeView.svelte
+3
-3
@@ -5,13 +5,13 @@
5
</script>
6
7
<script lang="ts">
8
- import { createEventDispatcher } from "svelte";
8
+ import { createEventDispatcher, onMount } from "svelte";
9
10
import FileTreeList from "./FileTreeList.svelte";
11
12
export let tree;
13
export let contextMenuEnabled = false;
14
- export let expanded = false;
14
+ export let isExpanded = false;
15
export let iconsEnabled = true;
16
17
let ref;
@@ -35,7 +35,7 @@
35
</script>
36
37
<ul bind:this={ref} class="tree" role="tree" on:mouseup={handleMouseUp}>
38
- <FileTreeList {expanded} on:nodeselect on:dblnodeselect children={tree} root {contextMenuEnabled} {iconsEnabled} />
38
+ <FileTreeList {isExpanded} on:nodeselect on:dblnodeselect children={tree} root {contextMenuEnabled} {iconsEnabled} />
39
</ul>
40
41
<style>
src/lib/Settings.svelte
+1
-1
@@ -40,7 +40,7 @@
40
41
<div class="settings-container" class:hidden>
42
<div class="settings-directory">
43
- <FileTreeView expanded={true} iconsEnabled={false} tree={[
43
+ <FileTreeView isExpanded iconsEnabled={false} tree={[
44
{id: 0, path: "", name: "General", children: [
45
{id: 1, path: "", name: "Theme"},
46
{id: 2, path: "", name: "Editor", children: [