Skip to content

Commit

Permalink
Improve up/down cursor movement
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Apr 4, 2019
1 parent 0889b96 commit acf0255
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions fx.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,16 @@ module.exports = function start(filename, source) {
box.key(['up', 'k'], function () {
hideStatusBar()
program.showCursor()
let rest = [...index.keys()]

const [n] = getLine(program.y)
if (typeof n !== 'undefined') {
rest = rest.filter(i => i < n)
}

if (rest.length > 0) {
const next = Math.max(...rest)
let next
for (let [i,] of index) {
if (i < n && (typeof next === 'undefined' || i > next)) {
next = i
}
}

if (typeof next !== 'undefined') {
let y = box.getScreenNumber(next) - box.childBase
if (y <= 0) {
box.scroll(-1)
Expand All @@ -309,16 +309,16 @@ module.exports = function start(filename, source) {
box.key(['down', 'j'], function () {
hideStatusBar()
program.showCursor()
let rest = [...index.keys()]

const [n] = getLine(program.y)
if (typeof n !== 'undefined') {
rest = rest.filter(i => i > n)
}

if (rest.length > 0) {
const next = Math.min(...rest)
let next
for (let [i,] of index) {
if (i > n && (typeof next === 'undefined' || i < next)) {
next = i
}
}

if (typeof next !== 'undefined') {
let y = box.getScreenNumber(next) - box.childBase
if (y >= box.height) {
box.scroll(1)
Expand Down

0 comments on commit acf0255

Please sign in to comment.