Skip to content

Commit

Permalink
keep order consistent when Alt_Qing windows
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-src-client-keys.js,AUTO-COMMIT-src-components-widgets-lively-window.js,
  • Loading branch information
onsetsu committed Oct 29, 2024
1 parent 4998b32 commit 4ae6374
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/client/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LivelyWindowSwitcher {
this.clear();

this.memorizeCurrentWindows()

// no windows?
if (this.windowOrder.length === 0) {
return;
Expand Down Expand Up @@ -54,17 +54,17 @@ class LivelyWindowSwitcher {
memorizeCurrentWindows() {
const windows = [...document.querySelectorAll('lively-window')]
this.windowOrder = windows.sortBy(win => win.style.zIndex, false)
this.currentIndex = this.windowOrder.findIndex(win => win.matches(':focus-within'))
this.currentIndex = this.windowOrder.findIndex(win => win.matches('[active]'))

// debugDraw
// this.windowOrder.forEach((win, i) => {
// lively.showElement(win).innerHTML = `${i}: ${win.style.zIndex}`
// lively.showElement(win).innerHTML = `${this.currentIndex}:${i}: ${win.style.zIndex}`
// })
// lively.notify(this.currentIndex)
}

switchToNextWindow(offset, evt) {
lively.notify(offset)
// lively.notify(offset)
evt.stopPropagation();
evt.preventDefault();

Expand All @@ -79,13 +79,20 @@ class LivelyWindowSwitcher {
}

switchToWindow(win) {
// lively.showElement(win)
if (!win) {
lively.warn('no window to switch to')
}

// preserve original order when doing multiple Alt-Q-Q-Qs...
const allWindowsButThis = [...this.windowOrder]
let thisIdx = allWindowsButThis.indexOf(win);
allWindowsButThis.splice(thisIdx, 1);
allWindowsButThis.reverse()

// lively.showElement(win).innerHTML = `${win.style.zIndex}`
lively.gotoWindow(win.parentElement, true);
win.focus();
win.reorderWindowsWithThisFocussed(allWindowsButThis)
}

clear() {
Expand Down
4 changes: 4 additions & 0 deletions src/components/widgets/lively-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ export default class Window extends Morph {
return parseInt(a.style['z-index']) - parseInt(b.style['z-index']);
});

this.reorderWindowsWithThisFocussed(allWindowsButThis)
}

reorderWindowsWithThisFocussed(allWindowsButThis) {
allWindowsButThis.forEach((win, index) => {
win.style['z-index'] = this.minZIndex + index;
if (win.window)
Expand Down

0 comments on commit 4ae6374

Please sign in to comment.