Skip to content

Commit

Permalink
Don't replace calendar with note when tab is pinned (#235)
Browse files Browse the repository at this point in the history
fixes #126
  • Loading branch information
davish authored Dec 23, 2022
1 parent 894f5bf commit 0e33ba1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/models/DailyNoteEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
MetadataCache,
TFile,
Vault,
Workspace,
WorkspaceLeaf,
} from "obsidian";
import {
Expand Down Expand Up @@ -50,7 +51,10 @@ export class DailyNoteEvent extends LocalEvent {
this.heading = heading;
}

async openIn(leaf: WorkspaceLeaf): Promise<void> {
async openIn(leaf: WorkspaceLeaf, workspace: Workspace): Promise<void> {
if (leaf.getViewState().pinned) {
leaf = workspace.getLeaf("tab");
}
await leaf.openFile(this.file);
if (leaf.view instanceof MarkdownView) {
leaf.view.editor.setCursor({
Expand Down
10 changes: 8 additions & 2 deletions src/models/Event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Calendar, EventInput } from "@fullcalendar/core";
import { dir } from "console";
import { MetadataCache, TFile, Vault, WorkspaceLeaf } from "obsidian";
import {
MetadataCache,
TFile,
Vault,
Workspace,
WorkspaceLeaf,
} from "obsidian";
import { toEventInput } from "src/fullcalendar_interop";
import { CalendarSource, OFCEvent, FCError } from "src/types";
import { getColors } from "./util";
Expand Down Expand Up @@ -111,7 +117,7 @@ export abstract class LocalEvent extends EditableEvent {
this.filename = filename;
}

abstract openIn(leaf: WorkspaceLeaf): Promise<void>;
abstract openIn(leaf: WorkspaceLeaf, workspace: Workspace): Promise<void>;
abstract get path(): string;

get file(): TFile {
Expand Down
13 changes: 11 additions & 2 deletions src/models/NoteEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { MetadataCache, TFile, Vault, WorkspaceLeaf } from "obsidian";
import {
MetadataCache,
TFile,
Vault,
Workspace,
WorkspaceLeaf,
} from "obsidian";
import { modifyFrontmatter } from "src/serialization/frontmatter";
import { OFCEvent, FCError, validateEvent } from "src/types";
import { basenameFromEvent, LocalEvent } from "./Event";
Expand Down Expand Up @@ -97,7 +103,10 @@ export class NoteEvent extends LocalEvent {
return event;
}

async openIn(leaf: WorkspaceLeaf): Promise<void> {
async openIn(leaf: WorkspaceLeaf, workspace: Workspace): Promise<void> {
if (leaf.getViewState().pinned) {
leaf = workspace.getLeaf("tab");
}
await leaf.openFile(this.file);
}
async delete(): Promise<void> {
Expand Down
5 changes: 4 additions & 1 deletion src/ui/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ export class EventModal extends Modal {
let leaf =
this.app.workspace.getMostRecentLeaf();
if (leaf) {
await this.event.openIn(leaf);
await this.event.openIn(
leaf,
this.app.workspace
);
this.close();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class CalendarView extends ItemView {
}
let leaf = this.app.workspace.getMostRecentLeaf();
if (leaf) {
await leaf.openFile(event.file);
event.openIn(leaf, this.app.workspace);
}
} else {
new EventModal(
Expand Down Expand Up @@ -287,7 +287,7 @@ export class CalendarView extends ItemView {
item.setTitle("Go to note").onClick(() => {
let leaf = this.app.workspace.getMostRecentLeaf();
if (leaf) {
event.openIn(leaf);
event.openIn(leaf, this.app.workspace);
new Notice(`Opening "${e.title}"`);
}
})
Expand Down

0 comments on commit 0e33ba1

Please sign in to comment.