From 25c901e013a4528706493c00bb13e1605e0d4621 Mon Sep 17 00:00:00 2001 From: Coteh <3276350+Coteh@users.noreply.github.com> Date: Sun, 16 Jan 2022 03:04:56 -0500 Subject: [PATCH] Add jump to context WIP --- assets/components.d.ts | 1 + assets/components/LogViewer.vue | 59 ++++++++++++++++++++++++++++++--- assets/components/Search.vue | 7 +--- assets/composables/search.ts | 13 +++++++- 4 files changed, 69 insertions(+), 11 deletions(-) diff --git a/assets/components.d.ts b/assets/components.d.ts index 436ac4a7..df6d5256 100644 --- a/assets/components.d.ts +++ b/assets/components.d.ts @@ -6,6 +6,7 @@ declare module 'vue' { export interface GlobalComponents { CarbonCaretDown: typeof import('~icons/carbon/caret-down')['default'] CilColumns: typeof import('~icons/cil/columns')['default'] + CilFindInPage: typeof import('~icons/cil/find-in-page')['default'] ContainerStat: typeof import('./components/ContainerStat.vue')['default'] ContainerTitle: typeof import('./components/ContainerTitle.vue')['default'] FuzzySearchModal: typeof import('./components/FuzzySearchModal.vue')['default'] diff --git a/assets/components/LogViewer.vue b/assets/components/LogViewer.vue index d02fb4b3..d6c344bb 100644 --- a/assets/components/LogViewer.vue +++ b/assets/components/LogViewer.vue @@ -1,8 +1,23 @@ @@ -27,7 +42,27 @@ const ansiConvertor = new AnsiConvertor({ escapeXML: true }); const colorize = (value: string) => ansiConvertor.toHtml(value).replace("<mark>", "").replace("</mark>", ""); const { messages } = toRefs(props); -const filtered = useSearchFilter().filteredMessages(messages); +const { filteredMessages, searchFilter, resetSearch, isSearching } = useSearchFilter(); +const filtered = filteredMessages(messages); +const jumpToLine = async (e) => { + const line = e.target.closest("li"); + if (line.tagName !== "LI") { + return; + } + resetSearch(); + for (const item of messages.value) { + item.selected = false; + if (item.key === line.dataset.key) { + item.selected = true; + } + } + // TODO prevent ScrollableView from automatically sticking to the bottom when closing search and jumping to context (ScrollableView.vue:47) + // if that could be achieved, then these timing hacks can be removed + await new Promise((resolve) => setTimeout(resolve, 10)); + window.scrollTo(0, 0); + await new Promise((resolve) => setTimeout(resolve, 1000)); + window.scrollTo(0, line.offsetTop - 200); +};