|
1 | 1 | import type {App} from "obsidian";
|
2 |
| -import {Notice} from "obsidian"; |
| 2 | +import {MarkdownView, Notice} from "obsidian"; |
3 | 3 | import {log} from "./logger/logManager";
|
4 | 4 |
|
5 | 5 | export function getTemplater(app: App) {
|
@@ -27,23 +27,28 @@ export function getDate(input?: {format?: string, offset?: number|string}) {
|
27 | 27 |
|
28 | 28 | export function appendToCurrentLine(toAppend: string, app: App) {
|
29 | 29 | try {
|
30 |
| - // @ts-ignore |
31 |
| - const editor = app.workspace.activeLeaf.view.editor; |
32 |
| - const selected = editor.getSelection(); |
| 30 | + const activeView = app.workspace.getActiveViewOfType(MarkdownView); |
| 31 | + |
| 32 | + if (!activeView) { |
| 33 | + log.logError(`unable to append '${toAppend}' to current line.`); |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + const selected = activeView.editor.getSelection(); |
33 | 38 |
|
34 |
| - editor.replaceSelection(`${selected}${toAppend}`); |
| 39 | + activeView.editor.replaceSelection(`${selected}${toAppend}`); |
35 | 40 | } catch {
|
36 | 41 | log.logError(`unable to append '${toAppend}' to current line.`);
|
37 | 42 | }
|
38 | 43 | }
|
39 | 44 |
|
40 |
| -export function findObsidianCommand(commandId: string) { |
| 45 | +export function findObsidianCommand(app: App, commandId: string) { |
41 | 46 | // @ts-ignore
|
42 | 47 | return app.commands.findCommand(commandId);
|
43 | 48 | }
|
44 | 49 |
|
45 |
| -export function deleteObsidianCommand(commandId: string) { |
46 |
| - if (findObsidianCommand(commandId)) { |
| 50 | +export function deleteObsidianCommand(app: App, commandId: string) { |
| 51 | + if (findObsidianCommand(app, commandId)) { |
47 | 52 | // @ts-ignore
|
48 | 53 | delete app.commands.commands[commandId];
|
49 | 54 | // @ts-ignore
|
|
0 commit comments