Skip to content

Commit

Permalink
fix sidebar collapsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ra3orblade committed Apr 26, 2024
1 parent a779bdb commit 5ff30ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/ts/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Page, SelectionProvider, DragProvider, Progress, Toast, Preview as Prev
import { commonStore, authStore, blockStore, detailStore, dbStore, menuStore, popupStore, notificationStore } from 'Store';
import {
I, C, UtilCommon, UtilRouter, UtilFile, UtilData, UtilObject, UtilMenu, keyboard, Storage, analytics, dispatcher, translate, Renderer,
focus, Preview, Mark, Animation, Onboarding, Survey, UtilDate, UtilSmile, Encode, Decode, UtilSpace,
focus, Preview, Mark, Animation, Onboarding, Survey, UtilDate, UtilSmile, Encode, Decode, UtilSpace, sidebar
} from 'Lib';

require('pdfjs-dist/build/pdf.worker.entry.js');
Expand Down Expand Up @@ -115,6 +115,7 @@ if (!electron.isPackaged) {
Encode,
Decode,
translate,
sidebar,
},
};
};
Expand Down
30 changes: 7 additions & 23 deletions src/ts/lib/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ class Sidebar {
};

const { autoSidebar } = commonStore;
const { x, y, width, height, snap } = this.data;
const { x, y, width, snap } = this.data;
const css: any = { top: 0, height: '100%' };
const mouse = keyboard.mouse.page;

const height = 0;

let tx = 0;
if (snap == I.MenuDirection.Left) {
Expand All @@ -179,7 +181,7 @@ class Sidebar {
(autoSidebar && (mouse.x >= x) && (mouse.x <= x + width))
) {
css.top = y;
css.height = this.limitHeight(height);
css.height = this.getMaxHeight();
css.transform = `translate3d(0px,0px,0px)`;
} else {
css.top = 0;
Expand Down Expand Up @@ -405,13 +407,12 @@ class Sidebar {
set (v: Partial<SidebarData>, force?: boolean): void {
v = Object.assign(this.data, v);

let { width, height, x, y } = v;
let { width, x, y } = v;

if (!force) {
width = this.limitWidth(width);
height = this.limitHeight(height);

const coords = this.limitCoords(v.x, v.y, width, height);
const coords = this.limitCoords(v.x, v.y, width, this.getMaxHeight());
x = coords.x;
y = coords.y;
};
Expand All @@ -420,7 +421,6 @@ class Sidebar {
x,
y,
width,
height,
snap: this.getSnap(x, width),
});

Expand Down Expand Up @@ -489,16 +489,9 @@ class Sidebar {
* Get the side to snap the sidebar to
*/
private getSnap (x: number, width: number): I.MenuDirection.Left | I.MenuDirection.Right | null {
const { ww } = UtilCommon.getWindowDimensions();

if (x <= SNAP_THRESHOLD) {
return I.MenuDirection.Left;
} else
/*
if (x + width >= ww - SNAP_THRESHOLD) {
return I.MenuDirection.Right;
} else
*/
if (commonStore.isSidebarFixed) {
return I.MenuDirection.Left;
} else {
Expand All @@ -510,8 +503,7 @@ class Sidebar {
* Get max height allowed
*/
private getMaxHeight (): number {
const { wh } = UtilCommon.getWindowDimensions();
return wh - UtilCommon.sizeHeader() * 2;
return UtilCommon.getWindowDimensions().wh - UtilCommon.sizeHeader() * 2;
};

/**
Expand Down Expand Up @@ -540,14 +532,6 @@ class Sidebar {
return Math.max(min, Math.min(max, Number(width) || 0));
};

/**
* Limit the sidebar height to the max and min bounds
*/
private limitHeight (height: number): number {
const { min } = Constant.size.sidebar.height;
return Math.max(min, Math.min(this.getMaxHeight(), Number(height) || 0));
};

};

export const sidebar: Sidebar = new Sidebar();

0 comments on commit 5ff30ef

Please sign in to comment.