Skip to content

Commit c9c1ce6

Browse files
committed
feat: add enablement condition for visualize file command and improve editor decoration handling
1 parent 5b6cf89 commit c9c1ce6

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"command": "ucd.visualize-file",
3737
"title": "Visualize UCD File",
3838
"category": "UCD",
39-
"icon": "$(eye)"
39+
"icon": "$(eye)",
40+
"enablement": "resourceScheme == ucd"
4041
},
4142
{
4243
"command": "ucd.refresh-explorer",

src/extension.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { TreeViewNode } from "reactive-vscode";
22
import type { UCDTreeItem } from "./views/ucd-explorer";
33
import { hasUCDFolderPath } from "@luxass/unicode-utils";
4-
import { defineExtension, executeCommand, useCommand } from "reactive-vscode";
5-
import { Uri, window } from "vscode";
4+
import { defineExtension, executeCommand, useActiveTextEditor, useCommand, useEditorDecorations } from "reactive-vscode";
5+
import { Range, Uri, window } from "vscode";
66
import { useUCDContentProvider } from "./composables/useUCDContentProvider";
77
import { useUCDStore } from "./composables/useUCDStore";
88
import * as Meta from "./generated/meta";
@@ -17,15 +17,23 @@ const { activate, deactivate } = defineExtension(async () => {
1717
logger.info(`Fetched files for version 16.0.0: ${JSON.stringify(data, null, 2)}`);
1818
});
1919

20-
useCommand(Meta.commands.visualizeFile, () => {
21-
logger.info("Visualizing UCD file...");
22-
});
23-
2420
useCommand(Meta.commands.refreshExplorer, async () => {
2521
logger.info("Refreshing UCD Explorer...");
2622
logger.info("UCD Explorer refreshed.");
2723
});
2824

25+
useCommand(Meta.commands.visualizeFile, () => {
26+
logger.info("Visualizing UCD file...");
27+
// require that current editor is a UCD File
28+
const editor = useActiveTextEditor();
29+
logger.info("Current active editor:", JSON.stringify(editor.value, null, 2));
30+
useEditorDecorations(editor, {
31+
backgroundColor: "red",
32+
}, () => [
33+
editor.value?.visibleRanges[0] || new Range(0, 0, 20, 20),
34+
]);
35+
});
36+
2937
useCommand(Meta.commands.openExplorerEntry, async (versionOrTreeView: string | TreeViewNode, filePath?: string) => {
3038
if (versionOrTreeView == null) {
3139
logger.error("No entry provided to openExplorerEntry command.");

0 commit comments

Comments
 (0)