Actions.gridScrollFocused: undo if already centered
This commit is contained in:
@@ -306,7 +306,7 @@ class Actions {
|
||||
if (firstColumn === null) {
|
||||
return;
|
||||
}
|
||||
grid.desktop.scrollToColumn(firstColumn);
|
||||
grid.desktop.scrollToColumn(firstColumn, false);
|
||||
}
|
||||
|
||||
public readonly gridScrollEnd = (cm: ClientManager, dm: DesktopManager) => {
|
||||
@@ -315,11 +315,16 @@ class Actions {
|
||||
if (lastColumn === null) {
|
||||
return;
|
||||
}
|
||||
grid.desktop.scrollToColumn(lastColumn);
|
||||
grid.desktop.scrollToColumn(lastColumn, false);
|
||||
}
|
||||
|
||||
public readonly gridScrollFocused = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
grid.desktop.scrollCenterRange(column);
|
||||
const scrollAmount = Range.minus(column, grid.desktop.getCurrentVisibleRange());
|
||||
if (scrollAmount !== 0) {
|
||||
grid.desktop.adjustScroll(scrollAmount, true);
|
||||
} else {
|
||||
grid.desktop.scrollToColumn(column, true);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly gridScrollLeftColumn = (cm: ClientManager, dm: DesktopManager) => {
|
||||
@@ -334,7 +339,7 @@ class Actions {
|
||||
return;
|
||||
}
|
||||
|
||||
grid.desktop.scrollToColumn(leftColumn);
|
||||
grid.desktop.scrollToColumn(leftColumn, false);
|
||||
}
|
||||
|
||||
public readonly gridScrollRightColumn = (cm: ClientManager, dm: DesktopManager) => {
|
||||
@@ -349,7 +354,7 @@ class Actions {
|
||||
return;
|
||||
}
|
||||
|
||||
grid.desktop.scrollToColumn(rightColumn);
|
||||
grid.desktop.scrollToColumn(rightColumn, false);
|
||||
}
|
||||
|
||||
public readonly screenSwitch = (cm: ClientManager, dm: DesktopManager) => {
|
||||
|
||||
@@ -73,9 +73,8 @@ class Desktop {
|
||||
}
|
||||
|
||||
public scrollCenterRange(range: Range) {
|
||||
const windowCenter = range.getLeft() + range.getWidth() / 2;
|
||||
const screenCenter = this.scrollX + this.tilingArea.width / 2;
|
||||
this.adjustScroll(Math.round(windowCenter - screenCenter), true);
|
||||
const scrollAmount = Range.minus(range, this.getCurrentVisibleRange());
|
||||
this.adjustScroll(scrollAmount, true);
|
||||
}
|
||||
|
||||
public scrollCenterVisible(focusedColumn: Column) {
|
||||
@@ -91,11 +90,11 @@ class Desktop {
|
||||
return;
|
||||
}
|
||||
|
||||
this.scrollToColumn(focusedColumn);
|
||||
this.scrollToColumn(focusedColumn, false);
|
||||
}
|
||||
|
||||
public scrollToColumn(column: Column) {
|
||||
if (this.dirtyScroll || !Range.contains(this.getCurrentVisibleRange(), column)) {
|
||||
public scrollToColumn(column: Column, force: boolean) {
|
||||
if (force || this.dirtyScroll || !Range.contains(this.getCurrentVisibleRange(), column)) {
|
||||
this.config.scroller.scrollToColumn(this, column);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ class Grid {
|
||||
lastFocusedColumn.restoreToTiled();
|
||||
}
|
||||
this.lastFocusedColumn = column;
|
||||
this.desktop.scrollToColumn(column);
|
||||
this.desktop.scrollToColumn(column, false);
|
||||
}
|
||||
|
||||
public onScreenSizeChanged() {
|
||||
|
||||
@@ -20,6 +20,12 @@ namespace Range {
|
||||
child.getRight() <= parent.getRight();
|
||||
}
|
||||
|
||||
export function minus(a: Range, b: Range) {
|
||||
const aCenter = a.getLeft() + a.getWidth() / 2;
|
||||
const bCenter = b.getLeft() + b.getWidth() / 2;
|
||||
return Math.round(aCenter - bCenter);
|
||||
}
|
||||
|
||||
class Basic {
|
||||
constructor(
|
||||
private readonly x: number,
|
||||
|
||||
@@ -11,13 +11,33 @@ tests.register("Center focused", 1, () => {
|
||||
Assert.assert(workspaceMock.activeWindow === client2);
|
||||
Assert.columnsFillTilingArea([client0, client1, client2]);
|
||||
|
||||
// center client2
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.centered(config, screen, client2);
|
||||
Assert.fullyVisible(client1.frameGeometry);
|
||||
Assert.fullyVisible(client2.frameGeometry);
|
||||
|
||||
// undo center client2
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.columnsFillTilingArea([client0, client1, client2]);
|
||||
|
||||
// center client2
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.centered(config, screen, client2);
|
||||
Assert.fullyVisible(client1.frameGeometry);
|
||||
Assert.fullyVisible(client2.frameGeometry);
|
||||
|
||||
// focus client1 (no scrolling should occur)
|
||||
qtMock.fireShortcut("karousel-focus-left");
|
||||
Assert.centered(config, screen, client2, { message: "No scrolling should have occured" });
|
||||
Assert.fullyVisible(client1.frameGeometry);
|
||||
Assert.fullyVisible(client2.frameGeometry);
|
||||
|
||||
// center client1
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.columnsFillTilingArea([client0, client1, client2]);
|
||||
|
||||
// undo center client1 (no scrolling should occur, because all clients are already visible and centered)
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.columnsFillTilingArea([client0, client1, client2]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user