Skip to content

Commit

Permalink
Fix Obsidian 1.8 hijacking nav arrow right-clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
pjeby committed Feb 9, 2025
1 parent 100fb56 commit 1c8ac63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pane-relief",
"name": "Pane Relief",
"version": "0.5.7",
"version": "0.5.8",
"minAppVersion": "1.5.8",
"description": "Per-tab history, hotkeys for pane/tab movement, navigation, sliding workspace, and more",
"author": "PJ Eby",
Expand Down
20 changes: 14 additions & 6 deletions src/Navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,15 @@ export class Navigator extends Component {
}
this.register(() => this.containerEl.removeEventListener("click", onClick, true));
this.containerEl.addEventListener("click", onClick, true);

const matchButton = `.view-header > .view-actions > .view-action[class*="app:go-${this.kind}"],
.view-header-left > .view-header-nav-buttons > button:${this.dir < 0 ? "first" : "last"}-child,
.view-header > .view-header-nav-buttons > button:${this.dir < 0 ? "first" : "last"}-child`
this.register(
// Support "Customizable Page Header and Title Bar" buttons (0.15+)
// and built-in per-tab history (0.16.3+)
onElement(
this.owner.win.document.body,
"contextmenu",
`.view-header > .view-actions > .view-action[class*="app:go-${this.kind}"],
.view-header-left > .view-header-nav-buttons > button:${this.dir < 0 ? "first" : "last"}-child,
.view-header > .view-header-nav-buttons > button:${this.dir < 0 ? "first" : "last"}-child`,
(evt, target) => {
this.owner.win.document.body, "contextmenu", matchButton, (evt, target) => {
const el = target.matchParent(".workspace-leaf");
const leaf = this.owner.leaves().filter(leaf => leaf.containerEl === el).pop();
if (!leaf) return;
Expand All @@ -290,6 +289,15 @@ export class Navigator extends Component {
}, {capture: true}
)
);
// 1.8 treats *any* button click as navigation, even right-click :-(
if (requireApiVersion("1.8")) this.register(
onElement(
this.owner.win.document.body, "auxclick", matchButton, (evt) => {
// Block right-click from triggering navigation
if (evt.button === 2) evt.stopImmediatePropagation();
}, {capture: true}
)
);
}

onunload() {
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"0.5.7": "1.5.8",
"0.5.8": "1.5.8",
"0.5.2": "1.3.5",
"0.5.1": "1.2.8",
"0.4.2": "0.15.9",
Expand Down

0 comments on commit 1c8ac63

Please sign in to comment.