Skip to content

Commit

Permalink
fix: tree scrolling after open note through tree
Browse files Browse the repository at this point in the history
  • Loading branch information
levirs565 committed Jun 15, 2023
1 parent a7a6853 commit 497f9bb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/components/MainComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@
const children: Record<string, NoteComponent> = {};
let pendingOpenNote: Note | null = null;
export function focusTo(vault: DendronVault, note: Note) {
if (pendingOpenNote === note) {
pendingOpenNote = null;
return;
}
const vaultComponent = children[vault.config.name];
if (!vaultComponent) return;
const pathNotes = note.getPathNotes();
pathNotes.shift();
vaultComponent.focusNotes(pathNotes);
}
function onOpenNote(e: CustomEvent<Note>) {
pendingOpenNote = e.detail;
}
</script>

<div>
{#each $dendronVaultList as vault (vault.config.name)}
<NoteComponent note={vault.tree.root} isRoot {vault} bind:this={children[vault.config.name]} />
<NoteComponent
note={vault.tree.root}
isRoot
{vault}
bind:this={children[vault.config.name]}
on:openNote={onOpenNote}
/>
{/each}
</div>
11 changes: 9 additions & 2 deletions src/components/NoteComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { openFile } from "../utils";
import { LookupModal } from "../modal/lookup";
import { DendronVault } from "src/engine/vault";
import { tick } from "svelte";
import { createEventDispatcher, tick } from "svelte";
export let note: Note;
export let isRoot: boolean = false;
Expand Down Expand Up @@ -89,13 +89,20 @@
block: "center",
});
};
interface $$Events {
openNote: CustomEvent<Note>;
}
const dispatcher = createEventDispatcher();
</script>

<div class="tree-item is-clickable" class:is-collapsed={isCollapsed}>
<div
class="tree-item-self is-clickable mod-collapsible is-active"
class:is-active={isActive}
on:click={() => {
dispatcher("openNote", note);
openFile(getPlugin().app, note.file);
isCollapsed = false;
}}
Expand Down Expand Up @@ -130,7 +137,7 @@
}}
>
{#each note.children as child (child.name)}
<svelte:self note={child} {vault} bind:focusNotes={childrenFocus[child.name]} />
<svelte:self note={child} {vault} bind:focusNotes={childrenFocus[child.name]} on:openNote />
{/each}
</div>
{/if}
Expand Down

0 comments on commit 497f9bb

Please sign in to comment.