From b0b169639f14cdbee9957afa51240640a0c67838 Mon Sep 17 00:00:00 2001 From: nighca Date: Thu, 2 Jan 2025 12:22:18 +0800 Subject: [PATCH] Stop using monac content-widget for In-editor overlay optimization --- .../editor/code-editor/ui/CodeEditorCard.vue | 9 +- .../editor/code-editor/ui/CodeEditorUI.vue | 11 - .../editor/code-editor/ui/common.ts | 22 +- .../ui/completion/CompletionCard.vue | 4 +- .../ui/completion/CompletionUI.vue | 41 +++- .../editor/code-editor/ui/completion/index.ts | 30 --- .../ui/context-menu/ContextMenu.vue | 7 +- .../ui/context-menu/ContextMenuTrigger.vue | 1 + .../ui/context-menu/ContextMenuUI.vue | 2 +- .../code-editor/ui/context-menu/index.ts | 3 +- .../editor/code-editor/ui/hover/HoverCard.vue | 8 +- .../editor/code-editor/ui/hover/HoverUI.vue | 41 +++- .../editor/code-editor/ui/hover/index.ts | 81 +++---- .../ResourceReferenceUI.vue | 41 +++- .../ui/resource-reference/index.ts | 31 +-- .../selector/ResourceSelector.vue | 4 +- spx-gui/src/components/ui/UIDropdown.ts | 199 ++++++++++++++++++ spx-gui/src/components/ui/UIDropdown.vue | 134 ------------ spx-gui/src/components/ui/index.ts | 2 +- spx-gui/src/components/ui/menu/UIMenuItem.vue | 2 +- 20 files changed, 397 insertions(+), 276 deletions(-) create mode 100644 spx-gui/src/components/ui/UIDropdown.ts delete mode 100644 spx-gui/src/components/ui/UIDropdown.vue diff --git a/spx-gui/src/components/editor/code-editor/ui/CodeEditorCard.vue b/spx-gui/src/components/editor/code-editor/ui/CodeEditorCard.vue index 03a3acf1f..095ecb4d1 100644 --- a/spx-gui/src/components/editor/code-editor/ui/CodeEditorCard.vue +++ b/spx-gui/src/components/editor/code-editor/ui/CodeEditorCard.vue @@ -1,12 +1,5 @@ - - diff --git a/spx-gui/src/components/editor/code-editor/ui/CodeEditorUI.vue b/spx-gui/src/components/editor/code-editor/ui/CodeEditorUI.vue index ddbe7d29d..f61d8d456 100644 --- a/spx-gui/src/components/editor/code-editor/ui/CodeEditorUI.vue +++ b/spx-gui/src/components/editor/code-editor/ui/CodeEditorUI.vue @@ -8,12 +8,6 @@ export function useCodeEditorUICtx() { if (ctx == null) throw new Error('useCodeEditorUICtx should be called inside of CodeEditorUI') return ctx } - -export function makeContentWidgetEl() { - const el = document.createElement('div') - el.className = 'code-editor-content-widget' - return el -} diff --git a/spx-gui/src/components/editor/code-editor/ui/completion/index.ts b/spx-gui/src/components/editor/code-editor/ui/completion/index.ts index dfd7b43e6..298435055 100644 --- a/spx-gui/src/components/editor/code-editor/ui/completion/index.ts +++ b/spx-gui/src/components/editor/code-editor/ui/completion/index.ts @@ -10,7 +10,6 @@ import { } from '../../common' import { type monaco } from '../../monaco' import type { CodeEditorUI } from '../code-editor-ui' -import { makeContentWidgetEl } from '../CodeEditorUI.vue' import { fuzzyScoreGracefulAggressive as fuzzyScore, type FuzzyScore } from './fuzzy' export type CompletionContext = BaseContext @@ -53,25 +52,6 @@ export class CompletionController extends Emitter<{ super() } - widgetEl = makeContentWidgetEl() - - private widget = { - getId: () => `completion-for-${this.ui.id}`, - getDomNode: () => this.widgetEl, - getPosition: () => { - if (this.nonEmptyItems == null) return null - const monaco = this.ui.monaco - const cursorPos = this.ui.editor.getPosition() - return { - position: cursorPos, - preference: [ - monaco.editor.ContentWidgetPositionPreference.BELOW, - monaco.editor.ContentWidgetPositionPreference.ABOVE - ] - } - } - } satisfies monaco.editor.IContentWidget - private currentCompletionRef = shallowRef<{ ctrl: AbortController textDocument: ITextDocument @@ -223,15 +203,6 @@ export class CompletionController extends Emitter<{ }) ) - // Manage completion widget (visibility, position, ...) - editor.addContentWidget(this.widget) - this.addDisposer(() => editor.removeContentWidget(this.widget)) - this.addDisposer( - watch( - () => this.nonEmptyItems, - () => editor.layoutContentWidget(this.widget) - ) - ) this.addDisposer( watch( () => [this.ui.activeTextDocument, this.ui.cursorPosition] as const, @@ -242,7 +213,6 @@ export class CompletionController extends Emitter<{ !positionEq(this.currentCompletion.position, position) ) { this.stopCompletion() - editor.layoutContentWidget(this.widget) } } ) diff --git a/spx-gui/src/components/editor/code-editor/ui/context-menu/ContextMenu.vue b/spx-gui/src/components/editor/code-editor/ui/context-menu/ContextMenu.vue index 6db190327..43e3d65cc 100644 --- a/spx-gui/src/components/editor/code-editor/ui/context-menu/ContextMenu.vue +++ b/spx-gui/src/components/editor/code-editor/ui/context-menu/ContextMenu.vue @@ -5,10 +5,11 @@ import type { ContextMenuController, InternalMenuItem, MenuData } from '.' const props = defineProps<{ controller: ContextMenuController - data: MenuData + data: MenuData | null }>() const pos = computed(() => { + if (props.data == null) return { x: 0, y: 0 } return { x: props.data.position.left, y: props.data.position.top @@ -21,9 +22,9 @@ function handleItemClick(item: InternalMenuItem) {