From 0778a0e4d365c38e1c6e2c9352637cfb6e94e4f0 Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Mon, 15 Jun 2026 16:27:55 +0200 Subject: [PATCH] Revert "Add markdown link tooltip support to the visual editor" This reverts commit 7ab4fd0793f057c86e4fc0307d81df376efe4d34. GitOrigin-RevId: 625a5cbbb39832f6a32a26d2ad454669d0ed1846 --- .../components/codemirror-command-tooltip.tsx | 17 ++------ .../extensions/command-tooltip.ts | 42 ++----------------- 2 files changed, 8 insertions(+), 51 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/components/codemirror-command-tooltip.tsx b/services/web/frontend/js/features/source-editor/components/codemirror-command-tooltip.tsx index 203b42c148..cb31899c25 100644 --- a/services/web/frontend/js/features/source-editor/components/codemirror-command-tooltip.tsx +++ b/services/web/frontend/js/features/source-editor/components/codemirror-command-tooltip.tsx @@ -5,10 +5,8 @@ import { } from './codemirror-context' import { closeCommandTooltip, - commandTooltipHandlers, commandTooltipState, } from '../extensions/command-tooltip' -import type { CommandTooltipHandler } from '../extensions/command-tooltip' import ReactDOM from 'react-dom' import { HrefTooltipContent } from './command-tooltip/href-tooltip' import { UrlTooltipContent } from './command-tooltip/url-tooltip' @@ -70,18 +68,14 @@ export const CodeMirrorCommandTooltip = memo(function CodeMirrorLinkTooltip() { } return ReactDOM.createPortal( - , + , tooltipView.dom ) }) const CodeMirrorCommandTooltipContent = memo<{ command: string - handlers: readonly CommandTooltipHandler[] -}>(function CodeMirrorCommandTooltipContent({ command, handlers }) { +}>(function CodeMirrorCommandTooltipContent({ command }) { switch (command) { case 'HrefCommand': return @@ -95,10 +89,7 @@ const CodeMirrorCommandTooltipContent = memo<{ return case 'Subfile': return - default: { - // Tooltips contributed by modules via the `commandTooltipHandlers` facet - const handler = handlers.find(handler => handler.command === command) - return handler ? handler.render() : null - } + default: + return null } }) diff --git a/services/web/frontend/js/features/source-editor/extensions/command-tooltip.ts b/services/web/frontend/js/features/source-editor/extensions/command-tooltip.ts index b24f0b948a..567374bdf0 100644 --- a/services/web/frontend/js/features/source-editor/extensions/command-tooltip.ts +++ b/services/web/frontend/js/features/source-editor/extensions/command-tooltip.ts @@ -11,13 +11,11 @@ import { import { EditorSelection, EditorState, - Facet, Prec, SelectionRange, StateEffect, StateField, } from '@codemirror/state' -import type { ReactNode } from 'react' import { ancestorOfNodeWithType } from '../utils/tree-query' import { ensureSyntaxTree, syntaxTree } from '@codemirror/language' import { @@ -34,30 +32,12 @@ import { } from '@codemirror/autocomplete' import { SyntaxNode } from '@lezer/common' -export type ActiveTooltip = { +type ActiveTooltip = { range: SelectionRange tooltip: Tooltip command: string } | null -export type CommandTooltipContext = { - state: EditorState - pos: number - value: ActiveTooltip - commandNode: SyntaxNode -} - -// A command-tooltip handler lets a module add a tooltip for a syntax node type -// that isn't part of the LaTeX `$CommandTooltipCommand` group (e.g. the -// markdown `Link` node) -export type CommandTooltipHandler = { - command: string - createTooltip: (context: CommandTooltipContext) => ActiveTooltip - render: () => ReactNode -} - -export const commandTooltipHandlers = Facet.define() - const createTooltipView = ( update?: (update: ViewUpdate) => void ): TooltipView => { @@ -67,7 +47,7 @@ const createTooltipView = ( return { dom, update } } -export const buildTooltip = ( +const buildTooltip = ( command: string, pos: number, value: ActiveTooltip, @@ -109,12 +89,7 @@ const createTooltipState = ( const { main } = state.selection const pos = main.head const node = syntaxTree(state).resolveInner(pos, 0) - const moduleHandlers = state.facet(commandTooltipHandlers) - const commandNode = ancestorOfNodeWithType( - node, - '$CommandTooltipCommand', - ...moduleHandlers.map(handler => handler.command) - ) + const commandNode = ancestorOfNodeWithType(node, '$CommandTooltipCommand') if (!commandNode) { return null } @@ -124,15 +99,6 @@ const createTooltipState = ( } const commandName = commandNode.name - // Module-provided handlers (e.g. the markdown link tooltip) take priority - // over the built-in LaTeX commands below. - const handler = moduleHandlers.find( - handler => handler.command === commandName - ) - if (handler) { - return handler.createTooltip({ state, pos, value, commandNode }) - } - switch (commandName) { // a hyperlink (\href) case 'HrefCommand': { @@ -351,7 +317,7 @@ export const commandTooltipState = ( state: EditorState ): ActiveTooltip | undefined => state.field(commandTooltipStateField, false) -export const firstInteractiveElement = ( +const firstInteractiveElement = ( view: EditorView, tooltipState: NonNullable ) =>