mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-22 03:16:16 +08:00
Highlight range when showing hover details (#2747)
This commit is contained in:
parent
72c65ba34c
commit
403be80603
4 changed files with 38 additions and 8 deletions
|
@ -1,6 +1,5 @@
|
||||||
import {
|
import {
|
||||||
EditorView,
|
EditorView,
|
||||||
hoverTooltip,
|
|
||||||
keymap,
|
keymap,
|
||||||
highlightSpecialChars,
|
highlightSpecialChars,
|
||||||
drawSelection,
|
drawSelection,
|
||||||
|
@ -57,6 +56,7 @@ import {
|
||||||
import { ancestorNode, closestNode } from "./live_editor/codemirror/tree_utils";
|
import { ancestorNode, closestNode } from "./live_editor/codemirror/tree_utils";
|
||||||
import { selectingClass } from "./live_editor/codemirror/selecting_class";
|
import { selectingClass } from "./live_editor/codemirror/selecting_class";
|
||||||
import { globalPubsub } from "../../lib/pubsub";
|
import { globalPubsub } from "../../lib/pubsub";
|
||||||
|
import { hoverDetails } from "./live_editor/codemirror/hover_details";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mounts cell source editor with real-time collaboration mechanism.
|
* Mounts cell source editor with real-time collaboration mechanism.
|
||||||
|
@ -352,7 +352,7 @@ export default class LiveEditor {
|
||||||
this.intellisense
|
this.intellisense
|
||||||
? [
|
? [
|
||||||
autocompletion({ override: [this.completionSource.bind(this)] }),
|
autocompletion({ override: [this.completionSource.bind(this)] }),
|
||||||
hoverTooltip(this.docsHoverTooltipSource.bind(this)),
|
hoverDetails(this.docsHoverTooltipSource.bind(this)),
|
||||||
signature(this.signatureSource.bind(this), {
|
signature(this.signatureSource.bind(this), {
|
||||||
activateOnTyping: settings.editor_auto_signature,
|
activateOnTyping: settings.editor_auto_signature,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { Decoration, EditorView, hoverTooltip } from "@codemirror/view";
|
||||||
|
import { RangeSet } from "@codemirror/state";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an extension that enables hover details tooltip.
|
||||||
|
*/
|
||||||
|
export function hoverDetails(hoverTooltipSource) {
|
||||||
|
const tooltipExtension = hoverTooltip(hoverTooltipSource);
|
||||||
|
|
||||||
|
const decorationsExtension = EditorView.decorations.from(
|
||||||
|
tooltipExtension.active,
|
||||||
|
(tooltips) => {
|
||||||
|
const backgroundDecoration = Decoration.mark({
|
||||||
|
class: "cm-hoverDocsSelection",
|
||||||
|
});
|
||||||
|
|
||||||
|
const decorationRanges = tooltips.map((tooltip) =>
|
||||||
|
backgroundDecoration.range(tooltip.pos, tooltip.end),
|
||||||
|
);
|
||||||
|
|
||||||
|
return RangeSet.of(decorationRanges, true);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return [tooltipExtension, decorationsExtension];
|
||||||
|
}
|
|
@ -289,6 +289,10 @@ function buildEditorTheme(colors, { dark }) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
".cm-hoverDocsSelection": {
|
||||||
|
backgroundColor: colors.selectionMatchBackground,
|
||||||
|
},
|
||||||
|
|
||||||
// Signature
|
// Signature
|
||||||
|
|
||||||
".cm-tooltip.cm-signatureHint": {
|
".cm-tooltip.cm-signatureHint": {
|
||||||
|
|
12
assets/package-lock.json
generated
12
assets/package-lock.json
generated
|
@ -1970,9 +1970,9 @@
|
||||||
"integrity": "sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A=="
|
"integrity": "sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A=="
|
||||||
},
|
},
|
||||||
"node_modules/@codemirror/view": {
|
"node_modules/@codemirror/view": {
|
||||||
"version": "6.27.0",
|
"version": "6.32.0",
|
||||||
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.27.0.tgz",
|
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.32.0.tgz",
|
||||||
"integrity": "sha512-8kqX1sHbVW1lVzWwrjAbh4dR7eKhV8eIQ952JKaBXOoXE04WncoqCy4DMU701LSrPZ3N2Q4zsTawz7GQ+2mrUw==",
|
"integrity": "sha512-AgVNvED2QTsZp5e3syoHLsrWtwJFYWdx1Vr/m3f4h1ATQz0ax60CfXF3Htdmk69k2MlYZw8gXesnQdHtzyVmAw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/state": "^6.4.0",
|
"@codemirror/state": "^6.4.0",
|
||||||
"style-mod": "^4.1.0",
|
"style-mod": "^4.1.0",
|
||||||
|
@ -16265,9 +16265,9 @@
|
||||||
"integrity": "sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A=="
|
"integrity": "sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A=="
|
||||||
},
|
},
|
||||||
"@codemirror/view": {
|
"@codemirror/view": {
|
||||||
"version": "6.27.0",
|
"version": "6.32.0",
|
||||||
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.27.0.tgz",
|
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.32.0.tgz",
|
||||||
"integrity": "sha512-8kqX1sHbVW1lVzWwrjAbh4dR7eKhV8eIQ952JKaBXOoXE04WncoqCy4DMU701LSrPZ3N2Q4zsTawz7GQ+2mrUw==",
|
"integrity": "sha512-AgVNvED2QTsZp5e3syoHLsrWtwJFYWdx1Vr/m3f4h1ATQz0ax60CfXF3Htdmk69k2MlYZw8gXesnQdHtzyVmAw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@codemirror/state": "^6.4.0",
|
"@codemirror/state": "^6.4.0",
|
||||||
"style-mod": "^4.1.0",
|
"style-mod": "^4.1.0",
|
||||||
|
|
Loading…
Add table
Reference in a new issue