Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions Extensions/keyboardShortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@
Spicetify.CosmosAsync.post("sp://desktop/v1/shutdown"),
},

// Rotate through sidebar items using Ctrl+Tab and Ctrl+Shift+Tab
// Rotate through sidebar items using Ctrl+Tab and Ctrl+Shift+Tab or Shift+J and Shift+K
"ctrl+tab": { callback: () => rotateSidebar(1) },
"ctrl+shift+tab": { callback: () => rotateSidebar(-1) },

"shift+j": { callback: () => rotateSidebar(1) },
"shift+k": { callback: () => rotateSidebar(-1) },

// Focus on the app content before scrolling using Shift+PageUp and Shift+PageDown
"shift+pageup": { callback: () => focusOnApp() },
"shift+pagedown": { callback: () => focusOnApp() },

// Scroll actions using 'j' and 'k' keys
j: { callback: () => createScrollCallback(SCROLL_STEP) },
k: { callback: () => createScrollCallback(-SCROLL_STEP) },


// Scroll half-page using 'u' and 'd' keys
d: { callback: () => scrollHalfPage(1) },
u: { callback: () => scrollHalfPage(-1) },

// Scroll to the top ('gg') or bottom ('Shift+g') of the page
"g g": { callback: () => scrollToPosition(0) },
"shift+g": { callback: () => scrollToPosition(1) },
Expand Down Expand Up @@ -127,7 +133,17 @@
const app = focusOnApp();
app.scroll(0, position === 0 ? 0 : app.scrollHeight);
}


function scrollHalfPage(direction /* 1 | -1 */) {
const app = focusOnApp();
if (!app) return;
const delta = Math.floor(app.clientHeight / 2) * direction;
const targetTop = Math.max(0,
Math.min(app.scrollTop + delta, app.scrollHeight)
);
app.scroll(0, targetTop);
}

/**
* @returns {number | undefined}
* @param {NodeListOf<Element>} allItems
Expand Down
Loading