Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interactions with tab, split and window per recent obsidian updates #142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"@popperjs/core": "2.11.5",
"lodash": "4.17.21",
"obsidian": "0.14.4",
"obsidian": "0.16.3",
"svelte": "3.47.0",
"svelte-writable-derived": "^2.1.3",
"tslib": "2.3.1"
Expand All @@ -36,7 +36,7 @@
"esbuild-svelte": "0.7.0",
"eslint": "8.13.0",
"eslint-plugin-import": "^2.26.0",
"moment": "2.29.2",
"moment": "2.29.4",
"sass": "^1.50.0",
"standard-version": "^9.3.2",
"svelte-check": "2.7.0",
Expand Down
10 changes: 6 additions & 4 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Command, App, TFile, Notice } from "obsidian";
import { type Command, App, TFile, Notice, Keymap } from "obsidian";
import type PeriodicNotesPlugin from "src/main";

import type { Granularity } from "./types";
Expand Down Expand Up @@ -56,7 +56,7 @@ async function jumpToAdjacentNote(
if (adjacentNoteMeta) {
const file = app.vault.getAbstractFileByPath(adjacentNoteMeta.filePath);
if (file && file instanceof TFile) {
const leaf = app.workspace.getUnpinnedLeaf();
const leaf = app.workspace.getLeaf(Keymap.isModEvent(app.lastEvent));
await leaf.openFile(file, { active: true });
}
} else {
Expand Down Expand Up @@ -84,8 +84,10 @@ async function openAdjacentNote(
.clone()
.add(offset, activeFileMeta.granularity);

plugin.openPeriodicNote(activeFileMeta.granularity, adjacentDate);
}
plugin.openPeriodicNote(activeFileMeta.granularity, adjacentDate, {
leaftype: Keymap.isModEvent(this.app.lastEvent)
})
};

export function getCommands(
app: App,
Expand Down
11 changes: 6 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Moment } from "moment";
import { addIcon, Plugin, TFile } from "obsidian";
import { addIcon, Plugin, TFile, Keymap } from "obsidian";
import type { PaneType } from "obsidian";
import { writable, type Writable } from "svelte/store";

import { PeriodicNotesCache, type PeriodicNoteCachedMetadata } from "./cache";
Expand Down Expand Up @@ -46,7 +47,7 @@ import {
} from "./utils";

interface IOpenOpts {
inNewSplit?: boolean;
leaftype?: boolean | PaneType;
calendarSet?: string;
}

Expand Down Expand Up @@ -134,7 +135,7 @@ export default class PeriodicNotesPlugin extends Plugin {
(e: MouseEvent) => {
if (e.type !== "auxclick") {
this.openPeriodicNote(granularity, window.moment(), {
inNewSplit: isMetaPressed(e),
leaftype: Keymap.isModEvent(e),
});
}
}
Expand Down Expand Up @@ -271,7 +272,7 @@ export default class PeriodicNotesPlugin extends Plugin {
date: Moment,
opts?: IOpenOpts
): Promise<void> {
const { inNewSplit = false, calendarSet } = opts ?? {};
const { leaftype=false, calendarSet } = opts ?? {};
const { workspace } = this.app;
let file = this.cache.getPeriodicNote(
calendarSet ?? this.calendarSetManager.getActiveId(),
Expand All @@ -282,7 +283,7 @@ export default class PeriodicNotesPlugin extends Plugin {
file = await this.createPeriodicNote(granularity, date);
}

const leaf = inNewSplit ? workspace.splitActiveLeaf() : workspace.getUnpinnedLeaf();
const leaf = workspace.getLeaf(leaftype);
await leaf.openFile(file, { active: true });
}
}
4 changes: 2 additions & 2 deletions src/switcher/switcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Moment } from "moment";
import { type NLDatesPlugin, setIcon, App, SuggestModal } from "obsidian";
import { type NLDatesPlugin, setIcon, App, SuggestModal, Keymap } from "obsidian";
import type { MatchType } from "src/cache";
import type PeriodicNotesPlugin from "src/main";
import {
Expand Down Expand Up @@ -231,7 +231,7 @@ export class NLDNavigator extends SuggestModal<DateNavigationItem> {

async onChooseSuggestion(item: DateNavigationItem, evt: MouseEvent | KeyboardEvent) {
this.plugin.openPeriodicNote(item.granularity, item.date, {
inNewSplit: isMetaPressed(evt),
leaftype: Keymap.isModEvent(evt),
});
}
}
17 changes: 9 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3242,7 +3242,7 @@ __metadata:
eslint-plugin-import: ^2.26.0
lodash: 4.17.21
moment: 2.29.2
obsidian: 0.14.4
obsidian: 0.16.3
sass: ^1.50.0
standard-version: ^9.3.2
svelte: 3.47.0
Expand All @@ -3254,15 +3254,16 @@ __metadata:
languageName: unknown
linkType: soft

"obsidian@npm:0.14.4":
version: 0.14.4
resolution: "obsidian@npm:0.14.4"
"obsidian@npm:0.16.3":
version: 0.16.3
resolution: "obsidian@npm:0.16.3"
dependencies:
"@codemirror/state": ^0.19.6
"@codemirror/view": ^0.19.31
"@types/codemirror": 0.0.108
moment: 2.29.1
checksum: b0ee32972aacd2b26a4fd134abc01b437c3d193a3f6c4efeb9a4d262f2230cbf83d9633525d76240017460fba44983156afc8784489a379e3ca7863427a70d3f
moment: 2.29.4
peerDependencies:
"@codemirror/state": ^6.0.0
"@codemirror/view": ^6.0.0
checksum: 48e82e011bc1904587cb681c4a98e27ab130f0d8130888141ebb9394ddf6b943453320be93882f97500061dba7695bf44305e069dee60cdb55bddcaf97dee996
languageName: node
linkType: hard

Expand Down