diff --git a/src/lib/components/Preview.svelte b/src/lib/components/Preview.svelte index f317cf6..7a8ff04 100644 --- a/src/lib/components/Preview.svelte +++ b/src/lib/components/Preview.svelte @@ -13,12 +13,15 @@ const dispatch = createEventDispatcher(); let isEditing: boolean = false; - let hasCursor: boolean = false; let currentContent: string; + let hasCursor: boolean = false; + let childHasCursor: boolean; const title = $parser.getIndexTitle(rootId); const orderedChildren = $parser.getOrderedChildIds(rootId); + $: buttonsVisible = hasCursor && !childHasCursor; + const getHeadingTag = (depth: number) => { switch (depth) { case 0: @@ -39,10 +42,20 @@ dispatch('cursorcapture', e); }; - const handleMouseLeave = (_: MouseEvent) => { + const handleMouseLeave = (e: MouseEvent) => { hasCursor = false; + dispatch('cursorrelease', e); }; + const handleChildCursorCaptured = (e: MouseEvent) => { + childHasCursor = true; + dispatch('cursorrelase', e); + }; + + const handleChildCursorReleased = (e: MouseEvent) => { + childHasCursor = false; + } + // TODO: Trigger rerender when editing state changes. const toggleEditing = (id: string, shouldSave: boolean = true) => { const editing = isEditing; @@ -81,13 +94,14 @@ depth={depth + 1} {allowEditing} isSectionStart={index === 0} - on:cursorcapture={handleMouseLeave} + on:cursorcapture={handleChildCursorCaptured} + on:cursorrelease={handleChildCursorReleased} /> {/each} {/if} {#if allowEditing} -
+