X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/d03daa19edde54d43693dca896f6fabade18d326..23be73e31d2e432bb56323937bab90fafba13b91:/vopamoi.ts diff --git a/vopamoi.ts b/vopamoi.ts index 59c2875..3042add 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -125,16 +125,28 @@ const BrowserUI = { event.preventDefault(); }, - moveCursor: function (offset: number): boolean { - var active = document.activeElement; - if (offset === 1 && active) { - active = active.nextElementSibling; - } - if (offset === -1 && active) { - active = active.previousElementSibling; + visibleTaskAtOffset(task: Element, offset: number): Element { + var cursor: Element | null = task; + var valid_cursor = cursor; + const increment = offset / Math.abs(offset); + while (true) { + cursor = increment > 0 ? cursor.nextElementSibling : cursor.previousElementSibling; + if (!cursor || !(cursor instanceof HTMLElement)) break; + if (cursor.style.display !== "none") { + offset -= increment; + valid_cursor = cursor; + } + if (Math.abs(offset) < 0.5) break; } - if (active && active instanceof HTMLElement) { - active.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;