From 88b976b252799dce9bb3aa8db5ec985d55308fc7 Mon Sep 17 00:00:00 2001 From: Peter Fajdiga Date: Thu, 8 Jun 2023 10:09:07 +0200 Subject: [PATCH] add shortcut and action karousel-column-expand-visible --- src/actions.ts | 6 ++++++ src/layout/Grid.ts | 25 +++++++++++++++++++++++++ src/shortcuts.ts | 1 + 3 files changed, 32 insertions(+) diff --git a/src/actions.ts b/src/actions.ts index b0aa305..a88b43a 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -175,6 +175,12 @@ function initActions(world: World) { }); }, + columnExpandVisible: () => { + const grid = world.getCurrentGrid(); + grid.expandColumnsVisible(); + grid.arrange(); + }, + gridScrollLeft: () => { gridScroll(world, -world.config.manualScrollStep); }, diff --git a/src/layout/Grid.ts b/src/layout/Grid.ts index aa56150..97e0807 100644 --- a/src/layout/Grid.ts +++ b/src/layout/Grid.ts @@ -114,6 +114,31 @@ class Grid { return last; } + expandColumnsVisible() { + const startColumn = this.getLeftmostVisibleColumn(true); + const endColumn = this.getRightmostVisibleColumn(true); + if (startColumn === null || endColumn === null) { + return; + } + + const startX = startColumn.gridX; + const endX = endColumn.gridX + endColumn.width; + const width = endX - startX; + const scaleRatio = this.tilingArea.width / width; + let remainingWidth = this.tilingArea.width; + + for (const column of this.columns.iteratorFrom(startColumn)) { + if (column !== endColumn) { + const newWidth = Math.round(column.width * scaleRatio); + column.setWidth(newWidth, true); + remainingWidth -= newWidth + this.world.config.gapsInnerHorizontal; + } else { + column.setWidth(remainingWidth, true); + break; + } + } + } + scrollToColumn(column: Column) { const left = column.gridX - this.scrollX; // in screen space const right = left + column.width; // in screen space diff --git a/src/shortcuts.ts b/src/shortcuts.ts index a0a4c78..a21a5c7 100644 --- a/src/shortcuts.ts +++ b/src/shortcuts.ts @@ -45,6 +45,7 @@ function registerShortcuts(world: World) { registerShortcutDbg("karousel-column-move-start", "Karousel: Move column to start", "Meta+Ctrl+Shift+Home", actions.columnMoveStart); registerShortcutDbg("karousel-column-move-end", "Karousel: Move column to end", "Meta+Ctrl+Shift+End", actions.columnMoveEnd); registerShortcutDbg("karousel-column-expand", "Karousel: Expand column", "Meta+Ctrl+X", actions.columnExpand); + registerShortcutDbg("karousel-column-expand-visible", "Karousel: Expand visible columns", "Meta+Ctrl+Alt+X", actions.columnExpandVisible) registerShortcutDbg("karousel-grid-scroll-focused", "Karousel: Scroll to focused window", "Meta+Alt+Return", actions.gridScrollFocused); registerShortcutDbg("karousel-grid-scroll-left-column", "Karousel: Scroll one column to the left", "Meta+Alt+A", actions.gridScrollLeftColumn);