Skip to content

Commit

Permalink
fix: open file or task
Browse files Browse the repository at this point in the history
  • Loading branch information
eatgrass committed Jan 13, 2024
1 parent 9418c66 commit 1f02816
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/TaskTracker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TaskItem } from 'Tasks'
import type PomodoroTimerPlugin from 'main'
import { TFile } from 'obsidian'
import { TFile, Keymap } from 'obsidian'
import {
writable,
type Readable,
Expand Down Expand Up @@ -138,19 +138,23 @@ export default class TaskTracker implements TaskTrackerStore {
})
}

public openFile() {
public openFile(event: MouseEvent) {
if (this.state.file) {
this.plugin.app.workspace.openLinkText(this.state.file.path, '')
const leaf = this.plugin.app.workspace.getLeaf(
Keymap.isModEvent(event),
)
leaf.openFile(this.state.file)
}
}

public openTask = (task: TaskItem) => {
let link = task.path
if (task.blockLink) {
link += `#${task.blockLink}`
public openTask = (event: MouseEvent, task: TaskItem) => {
let file = this.plugin.app.vault.getAbstractFileByPath(task.path)
if (file && file instanceof TFile && task.line >= 0) {
const leaf = this.plugin.app.workspace.getLeaf(
Keymap.isModEvent(event),
)
leaf.openFile(file, { eState: { line: task.line } })
}
console.log(link)
this.plugin.app.workspace.openLinkText(`${link}`, '')
}

get pinned() {
Expand Down
2 changes: 1 addition & 1 deletion src/TasksComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const showTaskMenu = (task: TaskItem) => (e: MouseEvent) => {
const menu = new Menu()
menu.addItem((item) => {
item.setTitle('Open').onClick(() => {
tracker.openTask(task)
tracker.openTask(e, task)
})
})
menu.showAtMouseEvent(e)
Expand Down

0 comments on commit 1f02816

Please sign in to comment.