From e293c875b5ea1cf8bc820e5af89e794618dd252e Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Thu, 14 Nov 2024 17:56:01 +0100 Subject: [PATCH] Fix not being able to search for the letter 'f' --- svelte/src/filesystem/FilesystemAPI.ts | 2 ++ .../filesystem/filemanager/SearchBar.svelte | 20 ++++++++++++++----- webcontroller/file_viewer.go | 3 +++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/svelte/src/filesystem/FilesystemAPI.ts b/svelte/src/filesystem/FilesystemAPI.ts index d43cc51..7b23053 100644 --- a/svelte/src/filesystem/FilesystemAPI.ts +++ b/svelte/src/filesystem/FilesystemAPI.ts @@ -260,6 +260,8 @@ export const fs_node_type = (node: FSNode) => { return "pdf" } else if ( node.file_type === "application/json" || + node.file_type === "application/x-yaml" || + node.file_type === "application/x-shellscript" || node.file_type.startsWith("text") ) { return "text" diff --git a/svelte/src/filesystem/filemanager/SearchBar.svelte b/svelte/src/filesystem/filemanager/SearchBar.svelte index bcf412d..4f08115 100644 --- a/svelte/src/filesystem/filemanager/SearchBar.svelte +++ b/svelte/src/filesystem/filemanager/SearchBar.svelte @@ -89,14 +89,15 @@ const clear_search = (blur) => { // Cursor navigation events can only be prevented with keydown. But we want to // use keyup for searching, so we use two listeners here -const keydown = e => { +const input_keydown = e => { if (e.key === "Escape" || e.key === "ArrowUp" || e.key === "ArrowDown") { e.preventDefault() } } -const keyup = e => { +const input_keyup = e => { if (e.key === "Escape") { clear_search(true) + e.preventDefault() } else if (e.key === "ArrowUp") { if (selected_result > 0) { selected_result-- @@ -123,6 +124,12 @@ const open_result = index => { } const window_keydown = (e) => { + if (e.ctrlKey || e.altKey || e.metaKey) { + return // prevent custom shortcuts from interfering with system shortcuts + } else if (document.activeElement.type && document.activeElement.type === "text") { + return // Prevent shortcuts from interfering with input fields + } + if (e.key === "Escape" && search_term !== "") { clear_search(true) e.preventDefault() @@ -160,12 +167,16 @@ const window_keydown = (e) => { placeholder="Type to search in {$nav.base.name}" style="width: 100%;" bind:value={search_term} - on:keydown={keydown} - on:keyup={keyup} + on:keydown={input_keydown} + on:keyup={input_keyup} />
+ {#if search_term !== "" && search_results.length === 0} + No results found + {/if} + {#each search_results as result, index} { .node_name { flex: 1 1 auto; width: 100%; - overflow: hidden; line-height: 1.2em; word-break: break-all; } diff --git a/webcontroller/file_viewer.go b/webcontroller/file_viewer.go index e84050c..0bcb8c9 100644 --- a/webcontroller/file_viewer.go +++ b/webcontroller/file_viewer.go @@ -154,6 +154,9 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request, if apiErr, ok := err.(pixelapi.Error); ok && apiErr.Status == http.StatusNotFound { w.WriteHeader(http.StatusNotFound) wc.templates.Run(w, r, "list_not_found", templateData) + } else if strings.HasSuffix(err.Error(), "invalid control character in URL") { + w.WriteHeader(http.StatusNotFound) + wc.templates.Run(w, r, "list_not_found", templateData) } else { log.Error("API request error occurred: %s", err) w.WriteHeader(http.StatusInternalServerError)