Skip to content

Commit

Permalink
Misc. Fixes
Browse files Browse the repository at this point in the history
- Improved unmaximize/slide behaviors w/newer Obsidians
- Restored view header pane numbering for Obsidian 1.6+ (which
  removed the view header icon from the app HTML)
  • Loading branch information
pjeby committed Sep 3, 2024
1 parent 0258c5e commit 4ce29ad
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 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.4",
"version": "0.5.5",
"minAppVersion": "1.5.8",
"description": "Per-tab history, hotkeys for pane/tab movement, navigation, sliding workspace, and more",
"author": "PJ Eby",
Expand Down
38 changes: 17 additions & 21 deletions src/maximizing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Maximizer extends Service {

const self = this
this.register(around(app.workspace, {
setActiveLeaf(old) { return function setActiveLeaf(leaf, pushHistory, focus) {
setActiveLeaf(old) { return function setActiveLeaf(leaf, ...args: any[]) {
// We have to do this here so that MarkdownView can be focused in the new pane
const parent = self.parentForLeaf(leaf), oldParent = self.parentForLeaf(app.workspace.activeLeaf);
if (
Expand All @@ -46,17 +46,9 @@ export class Maximizer extends Service {
app.commands.executeCommandById("obsidian-hover-editor:restore-active-popover");
}
if (isMain(leaf) && parent) self.refresh(parent, parent.hasClass("should-maximize") ? leaf.containerEl : null);
return old.call(this, leaf, pushHistory, focus);
return old.call(this, leaf, ...args);
}}
}));
this.register(around(WorkspaceTabs.prototype, {
onContainerScroll(old) {
return function() {
// Don't hide tabs while we're switching modes
if (!self.changing && this.containerEl.isShown()) return old.call(this)
}
}
}))

// Replace the right sidebar toggle that gets hidden during maximize
app.workspace.onLayoutReady(() => {
Expand Down Expand Up @@ -106,18 +98,22 @@ export class Maximizer extends Service {
return;
}
}
if (parent) this.refresh(parent, toggleClass(parent, "should-maximize") ? leaf.containerEl : null);
let hadMax = !toggleClass(parent, "should-maximize");
if (parent) this.refresh(parent, hadMax ? null : leaf.containerEl, hadMax);
}

lastMaximized(parent: Element) {
return parent.find(".workspace-leaf.is-maximized") || app.workspace.getMostRecentLeaf().containerEl;
}

fixSlidingPanes = debounce(() => {
const parent = app.workspace.activeLeaf.parentSplit;
if (requireApiVersion("0.16.2") && parent instanceof WorkspaceTabs && parent.isStacked) {
parent.containerEl.win.requestAnimationFrame(() => {
activeWindow.requestAnimationFrame(() => {
const {activeLeaf} = app.workspace;
if (!activeLeaf) return;
const parent = activeLeaf.parentSplit;
if (requireApiVersion("0.16.2") && parent instanceof WorkspaceTabs && parent.isStacked) {
const remove = around(parent.tabsContainerEl, {
// Kill .behavior flag so that the *whole* tab scrolls to position
scrollTo(old) { return function(optionsOrX, y?: number) {
if (typeof optionsOrX === "object") {
delete optionsOrX.behavior;
Expand All @@ -127,20 +123,20 @@ export class Maximizer extends Service {
}}
});
try { parent.scrollIntoView(parent.currentTab); } finally { remove(); this.changing = false; }
});
} else {
app.workspace.requestActiveLeafEvents();
this.changing = false;
}
} else {
this.changing = false;
}
activeLeaf.containerEl.scrollIntoView();
});
}, 1, true);

refresh(
parent: Element,
leafEl: Element =
parent.hasClass("should-maximize") ? this.lastMaximized(parent) : null
parent.hasClass("should-maximize") ? this.lastMaximized(parent) : null,
hadMax = parent.hasClass("has-maximized")
) {
this.changing = true;
const hadMax = parent.hasClass("has-maximized");
parent.findAllSelf(".workspace-split, .workspace-tabs").forEach(split => {
if (split === parent || this.parentFor(split) === parent)
toggleClass(split, "has-maximized", leafEl ? split.contains(leafEl): false);
Expand Down
2 changes: 1 addition & 1 deletion src/sliding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class SlidingPanes extends PerWindowComponent {
this.container.focus();
}
if (options.active) {
(leaf.containerEl.matchParent(".workspace-tabs") ?? leaf.containerEl).scrollIntoView({behavior: "smooth"});
(leaf.containerEl.matchParent(".workspace-tabs") ?? leaf.containerEl).scrollIntoView();
}
this.manager.options.defaultValue = options;
}
Expand Down
6 changes: 4 additions & 2 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,17 @@ body.obsidian-themepocalypse { --pr-pane-number-bottom: 0px; }
body.pane-relief-pane-numbering {
/* Number panes in their headers */
.workspace-split .workspace-leaf .view-header-icon { min-width: fit-content; display: inherit; }
.workspace-split .workspace-leaf .view-header-icon::before
.workspace-split .workspace-leaf .view-header-icon::before,
.workspace-split .workspace-leaf .view-header-left .view-header-nav-buttons::before
{
content: "";
display: inline-flex;
position: relative;
min-inline-size: 1em;
bottom: var(--pr-pane-number-bottom);
}
.workspace-split .workspace-leaf.has-pane-relief-label .view-header-icon::before
.workspace-split .workspace-leaf.has-pane-relief-label .view-header-icon::before,
.workspace-split .workspace-leaf.has-pane-relief-label .view-header-left .view-header-nav-buttons::before
{
counter-reset: pane-number var(--pane-relief-label);
content: counter(pane-number);
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"0.5.5": "1.5.8",
"0.5.4": "1.5.8",
"0.5.3": "1.5.8",
"0.5.2": "1.3.5",
Expand Down

0 comments on commit 4ce29ad

Please sign in to comment.