After searching extensively, I found no resolution for handling mouse clicks within the API. A related discussion on Stack Overflow mentioned that incorporating mouse events into the API is unlikely to happen.
Instead of addressing the click event directly, here is what I managed to accomplish:
- Implemented contribution points for:
- commands
- menus
- editor/context
- commandPalette
- Registered the command in JavaScript and obtained the location from the
textEditor
In the package.json
file, I configured my command to display only in the context menu with a specified title
when an opened file has a .log
extension.
"contributes": {
"commands": [
{
"command": "gd.my-ext.myCommand",
"title": "My Command"
}
],
"menus": {
"commandPalette": [
{
"command": "gd.me-ext.myCommand",
"when": "false"
}
],
"editor/context": [
{
"command": "gd.me-ext.myCommand",
"group": "navigation",
"when": "resourceExtname == .log"
},
]
},
In the extension.ts
file, I defined a text editor command and utilized the textEditor
's selection
and document
.
const disposable = vscode.commands.registerTextEditorCommand(
'gd.me-ext.myCommand',
(textEditor, edit, ...rest): void => {
const { selection, document } = textEditor;
console.log(selection.start.line);
const line: vscode.TextLine = document.lineAt(selection.start.line);
// By using the selection, I can determine the cursor's position within a line and apply decorations accordingly
}
);
context.subscriptions.push(disposable);