Skip to content

Commit

Permalink
Merge pull request #817 from googlefonts/issue-807
Browse files Browse the repository at this point in the history
Sidebar width now default to minimum, should be wider, as before
  • Loading branch information
justvanrossum authored Sep 18, 2023
2 parents 29b0f35 + 8326519 commit 3237167
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/fontra/views/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export class EditorController {

const resizeObserver = new ResizeObserver(([element]) => {
const totalWidth = this.sidebars.reduce(
(total, sidebar) => total + sidebar.getStoredWidth(),
(total, sidebar) => total + sidebar.getDOMWidth(),
0
);
if (element.contentRect.width < totalWidth + MIN_CANVAS_SPACE) {
Expand Down
19 changes: 14 additions & 5 deletions src/fontra/views/editor/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,20 @@ export class Sidebar {
const sidebarWidth = localStorage.getItem(
`fontra-sidebar-width-${this.identifier}`
);
let width = clamp(parseInt(sidebarWidth), MIN_SIDEBAR_WIDTH, MAX_SIDEBAR_WIDTH);
if (isNaN(width)) {
width = MIN_SIDEBAR_WIDTH;

if (!sidebarWidth) {
return;
}
return width;

return clamp(parseInt(sidebarWidth), MIN_SIDEBAR_WIDTH, MAX_SIDEBAR_WIDTH);
}

getDOMWidth() {
return parseInt(
getComputedStyle(document.documentElement)
.getPropertyValue(`--sidebar-content-width-${this.identifier}`)
.replace("px", "")
);
}

initResizeGutter() {
Expand Down Expand Up @@ -157,7 +166,7 @@ export class Sidebar {
document.addEventListener("pointerup", onPointerUp, { once: true });
});
const sidebarWidth = this.getStoredWidth();
if (sidebarWidth) {
if (sidebarWidth !== undefined) {
this.applyWidth(sidebarWidth);
}
}
Expand Down

0 comments on commit 3237167

Please sign in to comment.