Skip to content

Commit

Permalink
Workaround 0.15.x issues with page preview
Browse files Browse the repository at this point in the history
  • Loading branch information
pjeby committed Jun 18, 2022
1 parent 0d66eb0 commit de82c43
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 109 deletions.
218 changes: 121 additions & 97 deletions main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "quick-explorer",
"name": "Quick Explorer",
"version": "0.1.25",
"version": "0.1.26",
"description": "Perform file explorer operations (and see your current file path) from the title bar, using the mouse or keyboard",
"minAppVersion": "0.14.5",
"isDesktopOnly": true
Expand Down
17 changes: 16 additions & 1 deletion src/FolderMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { hoverSource, startDrag } from "./Explorer";
import { PopupMenu, MenuParent } from "./menus";
import { ContextMenu } from "./ContextMenu";
import { around } from "monkey-around";
import { windowForDom } from "./PerWindowComponent";

declare module "obsidian" {
interface HoverPopover {
Expand All @@ -11,6 +12,9 @@ declare module "obsidian" {
onHover: boolean
isPinned?: boolean
abortController?: Component
targetEl?: HTMLElement
onMouseIn(event: MouseEvent): void;
onMouseOut(event: MouseEvent): void;
}
interface App {
viewRegistry: {
Expand Down Expand Up @@ -341,7 +345,10 @@ export class FolderMenu extends PopupMenu implements HoverParent {
showPopover = debounce(() => {
this.hidePopover();
if (!autoPreview) return;
this.maybeHover(this.currentItem()?.dom, file => this.app.workspace.trigger('link-hover', this, null, file.path, ""));
this.maybeHover(this.currentItem()?.dom, file => this.app.workspace.trigger(
// Use document.body as targetEl so 0.15.x won't crash on preview
'link-hover', this, windowForDom(this.dom).document.body, file.path, ""
));
}, 50, true)

onItemHover = (event: MouseEvent, targetEl: HTMLDivElement) => {
Expand Down Expand Up @@ -385,6 +392,14 @@ export class FolderMenu extends PopupMenu implements HoverParent {
popover = null;
}
this._popover = popover;

/* Work around 0.15.x null targetEl bug using document.body */
const targetEl: HTMLElement = (popover as any)?.targetEl;
if (targetEl && targetEl === targetEl.ownerDocument.body) {
targetEl.removeEventListener("mouseover", popover.onMouseIn);
targetEl.removeEventListener("mouseout", popover.onMouseOut);
}

if (autoPreview && popover && this.currentItem()) {
// Override auto-pinning if we are generating auto-previews, to avoid
// generating huge numbers of popovers
Expand Down
15 changes: 6 additions & 9 deletions src/quick-explorer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {MenuItem, Plugin, TAbstractFile, TFolder} from "obsidian";
import {Explorer, hoverSource} from "./Explorer";
import {WindowManager} from "./PerWindowComponent";

import "./redom-jsx";
import "./styles.scss"
Expand All @@ -14,11 +13,7 @@ declare module "obsidian" {

export default class QE extends Plugin {
statusbarItem: HTMLElement
explorers = new WindowManager(this, Explorer);

get explorer(): Explorer {
return this.explorers.forWindow();
}
explorers = Explorer.perWindow(this, false);

updateCurrent(leaf = this.app.workspace.activeLeaf, file = this.app.workspace.getActiveFile()) {
this.explorers.forLeaf(leaf).update(file);
Expand All @@ -32,13 +27,15 @@ export default class QE extends Plugin {
this.registerEvent(this.app.workspace.on("file-open", () => this.updateCurrent()));
this.registerEvent(this.app.workspace.on("active-leaf-change", leaf => this.updateCurrent(leaf)));

this.addCommand({ id: "browse-vault", name: "Browse vault", callback: () => { this.explorer?.browseVault(); }, });
this.addCommand({ id: "browse-current", name: "Browse current folder", callback: () => { this.explorer?.browseCurrent(); }, });
this.app.workspace.onLayoutReady(() => this.updateCurrent());

this.addCommand({ id: "browse-vault", name: "Browse vault", callback: () => { this.explorers.forWindow()?.browseVault(); }, });
this.addCommand({ id: "browse-current", name: "Browse current folder", callback: () => { this.explorers.forWindow()?.browseCurrent(); }, });

this.registerEvent(this.app.workspace.on("file-menu", (menu, file, source) => {
let item: MenuItem
if (source !== "quick-explorer") menu.addItem(i => {
i.setIcon("folder").setTitle("Show in Quick Explorer").onClick(e => { this.explorer?.browseFile(file); });
i.setIcon("folder").setTitle("Show in Quick Explorer").onClick(e => { this.explorers.forWindow()?.browseFile(file); });
item = i;
})
if (item) {
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.1.25": "0.14.5",
"0.1.26": "0.14.5",
"0.1.23": "0.14.2",
"0.1.19": "0.13.23",
"0.1.9": "0.12.12",
Expand Down

0 comments on commit de82c43

Please sign in to comment.