·5 min read
I made the wheel pan a kanban board, then cut it down to Ctrl+wheel two months later
For two months, spinning the mouse wheel over the DailyBrief kanban board scrolled it sideways. I added that on purpose, with a handler built to be polite about it. Commit 8cf68ae deleted most of that code and left a much narrower rule: only Ctrl+wheel pans. The comment I wrote in its place says why: hijacking the plain wheel was disorienting.
- Project
- DailyBrief
- Date
- Oct 2026
- Stack
- Electron, JavaScript
- Commit
- 8cf68ae
The first version
The board is a row of columns, wider than the window once there are enough of them, and each column scrolls vertically on its own. I wanted a plain wheel to move across the board the way Shift+wheel does in a browser, so I wrote a handler that tried to be polite about it:
boardEl.addEventListener("wheel", function (e) {
if (e.ctrlKey) return; // Ctrl+wheel stays zoom
if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) return; // real trackpad pan
var max = boardEl.scrollWidth - boardEl.clientWidth;
if (max <= 0) return;
if (!e.shiftKey) {
// Let an inner vertical scroller consume the wheel if it still can.
var n = e.target;
while (n && n !== boardEl) {
if (n.scrollHeight > n.clientHeight + 1) {
var room = e.deltaY < 0 ? n.scrollTop : n.scrollHeight - n.clientHeight - n.scrollTop;
if (room > 1) return;
}
n = n.parentNode;
}
}
var next = Math.max(0, Math.min(max, boardEl.scrollLeft + e.deltaY));
if (next === boardEl.scrollLeft) return;
boardEl.scrollLeft = next;
e.preventDefault();
}, { passive: false });The comment above it described the intent: a plain wheel scrolls a column first and only spills into the horizontal pan once that column has nothing left to give. Everything in the handler exists to implement that sentence. The deltaX check leaves real trackpad swipes alone. The loop walks from the element under the cursor up to the board and asks each one whether it still has room in the scroll direction. room is the distance to the top when scrolling up, and to the bottom when scrolling down. The + 1 and > 1 are slack for fractional pixel positions.
Why it felt wrong
The logic was correct and the behaviour was still bad. The rule "the column scrolls until it runs out, then the board moves" means the same wheel gesture does two different things depending on where the scroll position happens to be. Scroll down a long column and the moment you reach the bottom, the next notch of the wheel slides the board sideways. You did nothing differently, but the screen jumped. The same thing happens at the top when you scroll back up.
The comment I left in the replacement says it plainly: hijacking the plain wheel to pan sideways was disorienting. I did not measure anything here. This is a behaviour problem, and the evidence is the old handler's logic and the code comment that replaced it.
The replacement
boardEl.addEventListener("wheel", function (e) {
if (!e.ctrlKey) return;
e.preventDefault();
var max = boardEl.scrollWidth - boardEl.clientWidth;
if (max <= 0) return;
var d = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;
boardEl.scrollLeft = Math.max(0, Math.min(max, boardEl.scrollLeft + d));
}, { passive: false });A plain wheel now returns on the first line and never touches the board, so columns scroll vertically and nothing else. Shift+wheel keeps the browser's own sideways scroll, which I no longer need to emulate. Ctrl+wheel is the only gesture the handler owns. The loop, the room arithmetic and the "did the position actually change" check are gone, because the handler no longer has to decide whether it is the right moment to act.
I kept the deltaX-versus-deltaY choice for the delta, so a trackpad that reports horizontal movement still pans in the direction the fingers moved.
The cost: zoom
Ctrl+wheel was not free. The app has its own zoom ladder in main.js, and it listens for Chromium's zoom-changed event, which is what Ctrl+wheel produces:
wc.on('zoom-changed', (ev, direction) => { stepZoom(direction === 'in' ? 1 : -1); });My new handler calls preventDefault() on the wheel event, and the comment next to it notes that this also stops Chromium's Ctrl+wheel zoom there. So over the board, Ctrl+wheel pans; everywhere else, it zooms. Ctrl+plus, Ctrl+minus and Ctrl+0 still work everywhere because they go through before-input-event, not the wheel.
The comment's own summary is that zoom still works everywhere except over the board. It is a real inconsistency, so the zoom hint in the app now says so:
"Ctrl with +/− or Ctrl+mouse wheel (over the board, Ctrl+wheel scrolls sideways instead); Ctrl+0 goes back to normal."What I took from it
The first handler was careful in the way that makes you think the design is right: it handled trackpads, nested scrollers, fractional pixels and edge clamping. All of that care went into making an ambiguous gesture behave well, when the real fix was to make the gesture unambiguous. A modifier key costs the user one finger and removes a whole class of surprises. I will pick the explicit gesture first next time, and add cleverness only if explicit turns out not to be enough.
#electron#javascript#ux#scrolling
Keep reading
Have a project in mind?