From b31e8f7b6d8c4a6f5bd229efebe59993c9d92b00 Mon Sep 17 00:00:00 2001 From: 0HyperCube <78500760+0HyperCube@users.noreply.github.com> Date: Sat, 9 Mar 2024 10:58:13 +0000 Subject: [PATCH] Make menu lists searchable (#1499) * Searchable font list * Bug fixes and UX polish for edge cases * More work, still more bugs to fix * Don't update highlight when not open * Bug fixes * Additional bug fixes and code review * Fix keyboard input being sent to backend --------- Co-authored-by: Keavon Chambers --- .../document/document_message_handler.rs | 2 +- .../components/floating-menus/Dialog.svelte | 2 +- .../components/floating-menus/MenuList.svelte | 324 +++++++++++++++--- .../src/components/layout/FloatingMenu.svelte | 8 +- frontend/src/components/panels/Layers.svelte | 2 +- .../widgets/buttons/TextButton.svelte | 1 - .../widgets/inputs/DropdownInput.svelte | 5 +- .../widgets/inputs/FontInput.svelte | 11 +- .../widgets/inputs/TextInput.svelte | 14 +- .../components/window/workspace/Panel.svelte | 2 +- frontend/src/io-managers/input.ts | 3 + frontend/src/wasm-communication/messages.ts | 5 +- 12 files changed, 297 insertions(+), 82 deletions(-) diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 450e30a3..a2fd87c7 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -1180,7 +1180,7 @@ impl DocumentMessageHandler { .icon(DocumentMode::SelectMode.icon_name()) .on_update(|_| DialogMessage::RequestComingSoonDialog { issue: Some(330) }.into()), MenuListEntry::new(format!("{:?}", DocumentMode::GuideMode)) - .label(DocumentMode::SelectMode.to_string()) + .label(DocumentMode::GuideMode.to_string()) .icon(DocumentMode::GuideMode.icon_name()) .on_update(|_| DialogMessage::RequestComingSoonDialog { issue: Some(331) }.into()), ]]) diff --git a/frontend/src/components/floating-menus/Dialog.svelte b/frontend/src/components/floating-menus/Dialog.svelte index 1beecbbb..f8040a95 100644 --- a/frontend/src/components/floating-menus/Dialog.svelte +++ b/frontend/src/components/floating-menus/Dialog.svelte @@ -20,7 +20,7 @@ onMount(() => { // Focus the button which is marked as emphasized, or otherwise the first button, in the popup - const emphasizedOrFirstButton = (self?.div()?.querySelector("[data-emphasized]") || self?.div()?.querySelector("[data-text-button]") || undefined) as HTMLButtonElement | undefined; + const emphasizedOrFirstButton = (self?.div?.()?.querySelector("[data-emphasized]") || self?.div?.()?.querySelector("[data-text-button]") || undefined) as HTMLButtonElement | undefined; emphasizedOrFirstButton?.focus(); }); diff --git a/frontend/src/components/floating-menus/MenuList.svelte b/frontend/src/components/floating-menus/MenuList.svelte index f7cc172f..93727bc2 100644 --- a/frontend/src/components/floating-menus/MenuList.svelte +++ b/frontend/src/components/floating-menus/MenuList.svelte @@ -1,13 +1,15 @@ @@ -199,6 +394,9 @@ scrollableY={scrollableY && virtualScrollingEntryHeight === 0} bind:this={self} > + {#if search.length > 0} + (search = detail)} bind:this={searchTextInput}> + {/if} {/if} {#each entries as section, sectionIndex (sectionIndex)} - {#if sectionIndex > 0} + {#if includeSeparator(entries, section, sectionIndex, search)} {/if} - {#each virtualScrollingEntryHeight ? section.slice(virtualScrollingStartIndex, virtualScrollingEndIndex) : section as entry, entryIndex (entryIndex + startIndex)} + {#each currentEntries(section, virtualScrollingEntryHeight, virtualScrollingStartIndex, virtualScrollingEndIndex, search) as entry, entryIndex (entryIndex + startIndex)} - + { + // We do a manual dispatch here instead of just `on:naturalWidth` as a workaround for the @@ -68,7 +68,6 @@ {tooltip} on:click={() => !disabled && (open = true)} on:blur={unFocusDropdownBox} - on:keydown={(e) => menuList?.keydown(e, false)} tabindex={disabled ? -1 : 0} data-floating-menu-spawner > diff --git a/frontend/src/components/widgets/inputs/FontInput.svelte b/frontend/src/components/widgets/inputs/FontInput.svelte index 931bbbb0..e839f978 100644 --- a/frontend/src/components/widgets/inputs/FontInput.svelte +++ b/frontend/src/components/widgets/inputs/FontInput.svelte @@ -104,16 +104,7 @@ - menuList?.keydown(e, false)} - data-floating-menu-spawner - > + {activeEntry?.value || ""} diff --git a/frontend/src/components/widgets/inputs/TextInput.svelte b/frontend/src/components/widgets/inputs/TextInput.svelte index 2c9b0d1b..ecc696b1 100644 --- a/frontend/src/components/widgets/inputs/TextInput.svelte +++ b/frontend/src/components/widgets/inputs/TextInput.svelte @@ -17,6 +17,10 @@ export let centered = false; export let minWidth = 0; + let className = ""; + export { className as class }; + export let classes: Record = {}; + let self: FieldInput | undefined; let editing = false; @@ -50,11 +54,15 @@ export function focus() { self?.focus(); } + + export function element(): HTMLInputElement | HTMLTextAreaElement | undefined { + return self?.element(); + } 0 ? `${minWidth}px` : undefined }} {value} on:value @@ -71,6 +79,8 @@