|
1 | | -import { FileSystemAdapter, Plugin, addIcon } from "obsidian"; |
| 1 | +import { FileSystemAdapter, Plugin, addIcon, MarkdownView } from "obsidian"; |
2 | 2 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
3 | | -import * as internal from "obsidian-typings"; |
| 3 | +import * as obsidianInternal from "obsidian-typings"; |
4 | 4 | import { DEFAULT_SETTINGS, OpenVSCodeSettings, OpenVSCodeSettingsTab } from "./settings"; |
5 | 5 | import { exec } from "child_process"; |
6 | 6 |
|
@@ -77,11 +77,18 @@ export default class OpenVSCode extends Plugin { |
77 | 77 | const filePath = file?.path ?? ""; |
78 | 78 | const folderPath = file?.parent?.path ?? ""; |
79 | 79 |
|
| 80 | + const cursor = this.app.workspace.getActiveViewOfType(MarkdownView)?.editor.getCursor(); |
| 81 | + // VSCode line and column are 1-based |
| 82 | + const line = (cursor?.line ?? 0) + 1; |
| 83 | + const ch = (cursor?.ch ?? 0) + 1; |
| 84 | + |
80 | 85 | let command = executeTemplate.trim() === "" ? DEFAULT_SETTINGS.executeTemplate : executeTemplate; |
81 | 86 | command = command |
82 | 87 | .replaceAll("{{vaultpath}}", path) |
83 | 88 | .replaceAll("{{filepath}}", filePath) |
84 | | - .replaceAll("{{folderpath}}", folderPath); |
| 89 | + .replaceAll("{{folderpath}}", folderPath) |
| 90 | + .replaceAll("{{line}}", line.toString()) |
| 91 | + .replaceAll("{{ch}}", ch.toString()); |
85 | 92 | if (this.DEV) console.log("[openVSCode]", { command }); |
86 | 93 | exec(command, error => { |
87 | 94 | if (error) { |
|
0 commit comments