Skip to content

Commit

Permalink
Stop file explorer reveals from stealing focus
Browse files Browse the repository at this point in the history
  • Loading branch information
pjeby committed Jul 23, 2022
1 parent 20d67ad commit eabe596
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 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.2.4",
"version": "0.2.5",
"minAppVersion": "0.14.5",
"description": "Per-pane history, hotkeys for pane movement + navigation, and more",
"author": "PJ Eby",
Expand Down
31 changes: 29 additions & 2 deletions src/focus-lock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { around } from "monkey-around";
import { Notice, Plugin, setIcon, Workspace, WorkspaceLeaf } from "obsidian";
import { LayoutSetting, Service } from "@ophidian/core";
import { defer, LayoutSetting, Service } from "@ophidian/core";
import { addCommands, command } from "./commands";
import { setTooltip } from "./Navigator";

Expand Down Expand Up @@ -52,7 +52,34 @@ export class FocusLock extends Service {
return old.call(this) && (!self.isLocked || isMain(this));
}
}
}))
}));
this.register(around((app as any).internalPlugins.plugins["file-explorer"].instance, {
init(old) { return function init(...args: any[]) {
try { return old.apply(this, args); } finally { self.blockFileExplorerReveal(); }
}}
}));
this.blockFileExplorerReveal();
}

blockFileExplorerReveal() {
const self = this;
const raf = (app.commands as any).commands["file-explorer:reveal-active-file"];
if (raf) this.register(around(raf, {
checkCallback(old) {
return function (...args: any[]) {
if (self.isLocked) for (const leaf of app.workspace.getLeavesOfType("file-explorer")) {
if (!isMain(leaf)) {
const el: HTMLElement = (leaf.view as any).dom?.navFileContainerEl;
el && defer(around(el, {focus(old) {
// Block focus stealing
return function() {};
}}));
}
}
return old?.apply(this, args);
}
}
}));
}

toggle() {
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.2.4": "0.14.5",
"0.2.5": "0.14.5",
"0.2.0": "0.14.5",
"0.1.15": "0.14.5",
"0.0.26": "0.14.5",
Expand Down

0 comments on commit eabe596

Please sign in to comment.