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

Swap Next/Prev for time-based ordering to match Obsidian #21

Open
wants to merge 2 commits into
base: master
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
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Default Commands:
Commands:
- Navigate to next file (alphabetical)
- Navigate to prev file (alphabetical)
- Navigate to next file (creation timestamp)
- Navigate to prev file (creation timestamp)
- Navigate to next file (modified timestamp)
- Navigate to prev file (modified timestamp)
- Navigate to older file (creation timestamp)
- Navigate to newer file (creation timestamp)
- Navigate to older file (modified timestamp)
- Navigate to newer file (modified timestamp)

Supported Sorting Modes:
- Alphabetical: Ordered by file names.
Expand All @@ -42,15 +42,16 @@ Or use the [obsidian-vimrc-support](https://github.com/esm7/obsidian-vimrc-suppo
Example `.obsidian.vimrc`.

```vimrc
" navigation to neighbouring files
exmap next_file obcommand neighbouring-files:next
exmap prev_file obcommand neighbouring-files:prev
" define navigation commands
exmap next_file obcommand neighbouring-files:next
exmap prev_file obcommand neighbouring-files:prev
exmap next_file_alphabetical obcommand neighbouring-files:next-alphabetical
exmap prev_file_alphabetical obcommand neighbouring-files:prev-alphabetical
exmap next_file_created obcommand neighbouring-files:next-created
exmap prev_file_created obcommand neighbouring-files:prev-created
exmap next_file_modified obcommand neighbouring-files:next-modified
exmap prev_file_modified obcommand neighbouring-files:prev-modified
exmap older_file_created obcommand neighbouring-files:older-created
exmap newer_file_created obcommand neighbouring-files:newer-created
exmap older_file_modified obcommand neighbouring-files:older-modified
exmap newer_file_modified obcommand neighbouring-files:newer-modified
" add navigation mappings
nmap gn :next_file<cr>
nmap gp :prev_file<cr>
```
16 changes: 8 additions & 8 deletions src/NeighbouringFileNavigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ export class NeighbouringFileNavigator {
this.navigateToNeighbouringFile(workspace, this.sorters.alphabeticalReverse);
}

public static navigateToNextCreatedFile(workspace: Workspace) {
console.debug("navigateToNextCreatedFile");
public static navigateToOlderCreatedFile(workspace: Workspace) {
console.debug("navigateToOlderCreatedFile");
this.navigateToNeighbouringFile(workspace, this.sorters.byCreatedTime);
}

public static navigateToPrevCreatedFile(workspace: Workspace) {
console.debug("navigateToPrevCreatedFile");
public static navigateToNewerCreatedFile(workspace: Workspace) {
console.debug("navigateToNewerCreatedFile");
this.navigateToNeighbouringFile(workspace, this.sorters.byCreatedTimeReverse);
}

public static navigateToNextModifiedFile(workspace: Workspace) {
console.debug("navigateToNextModifiedFile");
public static navigateToOlderModifiedFile(workspace: Workspace) {
console.debug("navigateToOlderModifiedFile");
this.navigateToNeighbouringFile(workspace, this.sorters.byModifiedTime);
}

public static navigateToPrevModifiedFile(workspace: Workspace) {
console.debug("navigateToPrevModifiedFile");
public static navigateToNewerModifiedFile(workspace: Workspace) {
console.debug("navigateToNewerModifiedFile");
this.navigateToNeighbouringFile(workspace, this.sorters.byModifiedTimeReverse);
}

Expand Down
46 changes: 26 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,33 @@ export default class NeighbouringFileNavigatorPlugin extends Plugin {
callback: () => NeighbouringFileNavigator.navigateToPrevAlphabeticalFile(this.app.workspace),
});

this.addCommand({
id: "next-created",
name: "Navigate to next file (creation timestamp)",
callback: () => NeighbouringFileNavigator.navigateToNextCreatedFile(this.app.workspace),
});
this.addCommand({
id: "prev-created",
name: "Navigate to prev file (creation timestamp)",
callback: () => NeighbouringFileNavigator.navigateToPrevCreatedFile(this.app.workspace),
});
const olderCreatedCommand = {
name: "Navigate to older file (creation timestamp)",
callback: () => NeighbouringFileNavigator.navigateToOlderCreatedFile(this.app.workspace),
};
this.addCommand({ ...olderCreatedCommand, id: "older-created" });
this.addCommand({ ...olderCreatedCommand, id: "prev-created" });

this.addCommand({
id: "next-modified",
name: "Navigate to next file (modification timestamp)",
callback: () => NeighbouringFileNavigator.navigateToNextModifiedFile(this.app.workspace),
});
this.addCommand({
id: "prev-modified",
name: "Navigate to prev file (modification timestamp)",
callback: () => NeighbouringFileNavigator.navigateToPrevModifiedFile(this.app.workspace),
});
const newerCreatedCommand = {
name: "Navigate to newer file (creation timestamp)",
callback: () => NeighbouringFileNavigator.navigateToNewerCreatedFile(this.app.workspace),
};
this.addCommand({ ...newerCreatedCommand, id: "next-created" });
this.addCommand({ ...newerCreatedCommand, id: "newer-created" });

const olderModifiedCommand = {
name: "Navigate to older file (modification timestamp)",
callback: () => NeighbouringFileNavigator.navigateToOlderModifiedFile(this.app.workspace),
};
this.addCommand({ ...olderModifiedCommand, id: "older-modified" });
this.addCommand({ ...olderModifiedCommand, id: "prev-modified" });

const newerModifiedCommand = {
name: "Navigate to newer file (modification timestamp)",
callback: () => NeighbouringFileNavigator.navigateToNewerModifiedFile(this.app.workspace),
};
this.addCommand({ ...newerModifiedCommand, id: "next-modified" });
this.addCommand({ ...newerModifiedCommand, id: "newer-modified" });
}

onunload() { }
Expand Down