mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-18 16:08:55 +00:00
fix(vcs): show the ⌘-hover declaration info as a popup in diff views (#3783)
The ⌘/Ctrl-hover declaration info in a diff view used CodeMirror's default dark tooltip, clipped by the pane and covered by the tool window stripe. The hint is now styled in full by the LSP theme as a rounded popup with an arrow pointing at the word (same in the editor and diffs), and a diff side showing an open document parents its tooltips to the body with the editor's tooltip bounds. Co-authored-by: PLZY <41029728+PLZY@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { lspTheme } from "./theme";
|
||||
|
||||
let view: EditorView | null = null;
|
||||
afterEach(() => {
|
||||
view?.destroy();
|
||||
view = null;
|
||||
});
|
||||
|
||||
it("draws the ⌘-hover info as a popup in a view without the editor theme", () => {
|
||||
// Diff viewers declare a dark theme and leave out the editor's `.cm-tooltip` rule.
|
||||
view = new EditorView({
|
||||
state: EditorState.create({ extensions: [EditorView.theme({}, { dark: true }), lspTheme] }),
|
||||
parent: document.body,
|
||||
});
|
||||
const info = document.createElement("div");
|
||||
info.className = "cm-tooltip cm-lsp-hover cm-lsp-nav-info";
|
||||
view.dom.appendChild(info);
|
||||
const style = getComputedStyle(info);
|
||||
expect(style.backgroundColor).toBe("var(--bg-popup)");
|
||||
expect(style.color).toBe("var(--fg)");
|
||||
expect(style.width).toBe("max-content");
|
||||
expect(style.borderRadius).toBe("var(--radius-popup-large)");
|
||||
expect(style.overflow).toBe("visible");
|
||||
});
|
||||
@@ -836,6 +836,7 @@ const linkField = StateField.define<LinkState | null>({
|
||||
return {
|
||||
pos: v.from,
|
||||
above: true,
|
||||
arrow: true,
|
||||
create: (view) => {
|
||||
const dom = document.createElement("div");
|
||||
dom.className = "cm-lsp-hover cm-lsp-nav-info";
|
||||
|
||||
+20
-1
@@ -328,7 +328,26 @@ export const lspTheme = EditorView.theme({
|
||||
backgroundImage:
|
||||
"linear-gradient(to right, transparent var(--lsp-occurrence-from), var(--lsp-occurrence-bg) var(--lsp-occurrence-from))",
|
||||
},
|
||||
".cm-lsp-nav-info": { padding: "4px 8px" },
|
||||
// IDEA's ⌘-hover hint: a rounded popup pointing at the word. Styled here in full, as diff
|
||||
// viewers lack the editor theme and would show CodeMirror's default tooltip. A few lines at
|
||||
// most, so no scrolling, which would clip the arrow.
|
||||
".cm-tooltip.cm-lsp-nav-info": {
|
||||
...tooltipSurface,
|
||||
borderRadius: "var(--radius-popup-large)",
|
||||
width: "max-content",
|
||||
maxWidth: "100%",
|
||||
maxHeight: "none",
|
||||
overflow: "visible",
|
||||
},
|
||||
".cm-lsp-nav-info .cm-lsp-code": { overflowWrap: "anywhere" },
|
||||
".cm-tooltip.cm-lsp-nav-info .cm-tooltip-arrow:before": {
|
||||
borderTopColor: "var(--border-popup)",
|
||||
borderBottomColor: "var(--border-popup)",
|
||||
},
|
||||
".cm-tooltip.cm-lsp-nav-info .cm-tooltip-arrow:after": {
|
||||
borderTopColor: "var(--bg-popup)",
|
||||
borderBottomColor: "var(--bg-popup)",
|
||||
},
|
||||
// Chooser highlight (tempHighlight.ts): the expression / occurrences a choice would take.
|
||||
".cm-lsp-chooser-highlight": { backgroundColor: "var(--bg-text-search-result)" },
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import { useWorkflowSettings } from "@/platform/workflowSettings";
|
||||
import { IconButton, Select, Spinner, T, isPopupOpen, showContextMenu } from "@/ui";
|
||||
import { registerSoftWrapSurface } from "@/workbench/softWrap";
|
||||
import { editorService, notifications, type EditorInput } from "@/workbench/contributions";
|
||||
import { changedLineGutters, diffOverview, diffWords, languageFor, viewerBase } from "./cm";
|
||||
import { changedLineGutters, diffOverview, diffWords, documentTooltips, languageFor, viewerBase } from "./cm";
|
||||
import { applyChunk, arrowControls, chunkAt, hoverRevert, revertUnifiedChunk } from "./diffControls";
|
||||
import {
|
||||
HIGHLIGHT_OPTIONS,
|
||||
@@ -538,7 +538,7 @@ export function DiffEditor({
|
||||
blameSlot(),
|
||||
att?.extension ?? [],
|
||||
// The file's open document: quick docs and ⌘/Ctrl-click navigation, as in its editor.
|
||||
att ? diffSideExtensions(att.context()) : [],
|
||||
att ? [diffSideExtensions(att.context()), documentTooltips] : [],
|
||||
editable ? [editableExtensions(), embeddedEditorExtensions(path)] : [],
|
||||
notes
|
||||
? diffAnnotations(
|
||||
|
||||
+12
-1
@@ -26,6 +26,7 @@ import {
|
||||
lineNumberMarkers,
|
||||
lineNumberWidgetMarker,
|
||||
lineNumbers,
|
||||
tooltips,
|
||||
WidgetType,
|
||||
type DecorationSet,
|
||||
type ViewUpdate,
|
||||
@@ -40,7 +41,7 @@ import { findExtension } from "@/editor/core/cm/find";
|
||||
import { overviewLane, overviewLaneIn } from "@/editor/core/cm/lanes";
|
||||
import { LINE_INSET } from "@/editor/core/cm/lineInset";
|
||||
import { caretExtension } from "@/editor/core/cm/prefs";
|
||||
import { fontExtension } from "@/editor/core/cm/setup";
|
||||
import { fontExtension, tooltipBounds } from "@/editor/core/cm/setup";
|
||||
import { caretStyles, findLocals, findStyles, overviewStyles } from "@/editor/core/cm/theme";
|
||||
import { editorPrefs } from "@/platform/editorSettings";
|
||||
import { useProject } from "@/platform/project";
|
||||
@@ -522,6 +523,16 @@ export function viewerBase(opts: {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tooltips of a pane showing an open document (quick docs, ⌘-hover info), parented to the
|
||||
* body as the editor's are, so the pane neither clips them nor keeps them under the tool
|
||||
* window stripes, and they move left to fit.
|
||||
*/
|
||||
export const documentTooltips: Extension = tooltips({
|
||||
parent: typeof document === "undefined" ? undefined : document.body,
|
||||
tooltipSpace: tooltipBounds,
|
||||
});
|
||||
|
||||
const cache = new Map<string, Promise<LanguageSupport | null>>();
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user