From: Scott Worley Date: Wed, 26 Jan 2022 18:59:16 +0000 (-0800) Subject: Factor out task offset logic X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/23be73e31d2e432bb56323937bab90fafba13b91?ds=inline Factor out task offset logic --- diff --git a/vopamoi.ts b/vopamoi.ts index b90b895..3042add 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -125,10 +125,8 @@ const BrowserUI = { event.preventDefault(); }, - moveCursor: function (offset: number): boolean { - var initial_cursor = document.activeElement; - if (!initial_cursor) return false; - var cursor: Element | null = initial_cursor; + visibleTaskAtOffset(task: Element, offset: number): Element { + var cursor: Element | null = task; var valid_cursor = cursor; const increment = offset / Math.abs(offset); while (true) { @@ -140,8 +138,15 @@ const BrowserUI = { } if (Math.abs(offset) < 0.5) break; } - if (valid_cursor !== initial_cursor && valid_cursor instanceof HTMLElement) { - valid_cursor.focus(); + return valid_cursor; + }, + + moveCursor: function (offset: number): boolean { + const active = document.activeElement; + if (!active) return false; + const dest = this.visibleTaskAtOffset(active, offset); + if (dest !== active && dest instanceof HTMLElement) { + dest.focus(); return true; } return false;