feat: init
This commit is contained in:
commit
8a609da778
59 files changed
+10053
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import { Notice, TFile } from "obsidian";
|
||||
import ExternalLink from "@lucide/svelte/icons/external-link";
|
||||
import FileText from "@lucide/svelte/icons/file-text";
|
||||
import PenLine from "@lucide/svelte/icons/pen-line";
|
||||
import { STATUS_META } from "../lib/vocab";
|
||||
import { STATUS_ORDER } from "../model/types";
|
||||
import type { Task } from "../model/types";
|
||||
import { replaceRaw, setStatus } from "../vault/mutate";
|
||||
import { tasksApi, warnMissingTasks } from "../tasks-api";
|
||||
import type { MenuItem } from "./menu-body.svelte";
|
||||
import type { ViewContext } from "./context";
|
||||
|
||||
async function revealInFile(view: ViewContext, task: Task): Promise<void> {
|
||||
const file = view.app.vault.getAbstractFileByPath(task.path);
|
||||
if (!(file instanceof TFile)) return;
|
||||
const leaf = view.app.workspace.getLeaf("tab");
|
||||
await leaf.openFile(file);
|
||||
const editor = view.app.workspace.activeEditor?.editor;
|
||||
if (editor) {
|
||||
editor.setCursor({ line: task.line, ch: 0 });
|
||||
editor.scrollIntoView(
|
||||
{ from: { line: task.line, ch: 0 }, to: { line: task.line, ch: 0 } },
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function editInTasks(view: ViewContext, task: Task): Promise<void> {
|
||||
const api = tasksApi(view.app);
|
||||
if (!api) {
|
||||
warnMissingTasks();
|
||||
return;
|
||||
}
|
||||
const edited = await api.editTaskLineModal(task.raw);
|
||||
if (!edited || edited === task.raw) return;
|
||||
await replaceRaw(view.app, task, edited);
|
||||
}
|
||||
|
||||
export function taskMenu(view: ViewContext, task: Task): MenuItem[] {
|
||||
const statuses: MenuItem[] = STATUS_ORDER.filter(
|
||||
(symbol) => symbol !== task.status,
|
||||
).map((symbol) => ({
|
||||
dot: STATUS_META[symbol].color,
|
||||
label: STATUS_META[symbol].label,
|
||||
onselect: () => void setStatus(view.app, task, symbol),
|
||||
}));
|
||||
|
||||
return [
|
||||
...statuses,
|
||||
{
|
||||
icon: PenLine,
|
||||
label: "Edit in Tasks",
|
||||
onselect: () => void editInTasks(view, task),
|
||||
},
|
||||
{
|
||||
icon: FileText,
|
||||
label: "Reveal in file",
|
||||
hint: task.sphere,
|
||||
onselect: () => void revealInFile(view, task),
|
||||
},
|
||||
{
|
||||
icon: ExternalLink,
|
||||
label: "Copy raw line",
|
||||
onselect: () => {
|
||||
void navigator.clipboard.writeText(task.raw);
|
||||
new Notice("Beaver Calendar: line copied");
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
Reference in new issue
Block a user