mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-13 14:36:06 +09:00
zfm: navigating directories
This commit is contained in:
@@ -81,4 +81,102 @@ class WindowObject {
|
||||
|
||||
}
|
||||
|
||||
exports = { WindowObject }
|
||||
/**
|
||||
* @param dy cursor change (positive or negative)
|
||||
* @param listSize size of the list to scroll
|
||||
* @param listHeight size of the list window
|
||||
* @param currentCursorPos ABSOLUTE position of the cursor
|
||||
* @param currentScrollPos current scroll position of the list
|
||||
* @param scrollPeek size of the scroll "peek"
|
||||
* @return [new cursor pos, new scroll pos]
|
||||
*/
|
||||
function scrollVert(dy, listSize, listHeight, currentCursorPos, currentScrollPos, scrollPeek) {
|
||||
let peek = 1
|
||||
|
||||
// clamp dy
|
||||
if (currentCursorPos + dy > listSize - 1)
|
||||
dy = (listSize - 1) - currentCursorPos
|
||||
else if (currentCursorPos + dy < 0)
|
||||
dy = -currentCursorPos
|
||||
|
||||
let nextRow = currentCursorPos + dy
|
||||
|
||||
// update vertical scroll stats
|
||||
if (dy != 0) {
|
||||
let visible = listHeight - 1 - peek
|
||||
|
||||
if (nextRow - currentScrollPos > visible) {
|
||||
currentScrollPos = nextRow - visible
|
||||
}
|
||||
else if (nextRow - currentScrollPos < 0 + peek) {
|
||||
currentScrollPos = nextRow - peek // nextRow is less than zero
|
||||
}
|
||||
|
||||
// NOTE: future-proofing here -- scroll clamping is moved outside of go-up/go-down
|
||||
// if-statements above because horizontal movements can disrupt vertical scrolls as well because
|
||||
// "normally" when you go right at the end of the line, you appear at the start of the next line
|
||||
|
||||
// scroll to the bottom?
|
||||
if (listSize > listHeight && currentScrollPos > listSize - listHeight)
|
||||
// to make sure not show buncha empty lines
|
||||
currentScrollPos = listSize - listHeight
|
||||
// scroll to the top? (order is important!)
|
||||
if (currentScrollPos <= -1)
|
||||
currentScrollPos = 0 // scroll of -1 would result to show "Line 0" on screen
|
||||
}
|
||||
|
||||
// move editor cursor
|
||||
currentCursorPos = nextRow
|
||||
return [currentCursorPos, currentScrollPos]
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dx cursor change (positive or negative)
|
||||
* @param stringSize length of the string to scroll
|
||||
* @param stringViewSize size of the string view
|
||||
* @param currentCursorPos ABSOLUTE position of the cursor
|
||||
* @param currentScrollPos current scroll position of the list
|
||||
* @param scrollPeek size of the scroll "peek"
|
||||
* @return [new cursor pos, new scroll pos]
|
||||
*/
|
||||
function scrollHorz(dx, stringSize, stringViewSize, currentCursorPos, currentScrollPos, scrollPeek) {
|
||||
let peek = 1
|
||||
|
||||
// clamp dx
|
||||
if (currentCursorPos + dx > stringSize - 1)
|
||||
dx = (stringSize - 1) - currentCursorPos
|
||||
else if (currentCursorPos + dx < 0)
|
||||
dx = -currentCursorPos
|
||||
|
||||
let nextCol = currentCursorPos + dx
|
||||
|
||||
// update vertical scroll stats
|
||||
if (dx != 0) {
|
||||
let visible = stringViewSize - 1 - peek
|
||||
|
||||
if (nextCol - currentScrollPos > visible) {
|
||||
currentScrollPos = nextCol - visible
|
||||
}
|
||||
else if (nextCol - currentScrollPos < 0 + peek) {
|
||||
currentScrollPos = nextCol - peek // nextCol is less than zero
|
||||
}
|
||||
|
||||
// NOTE: future-proofing here -- scroll clamping is moved outside of go-up/go-down
|
||||
// if-statements above because horizontal movements can disrupt vertical scrolls as well because
|
||||
// "normally" when you go right at the end of the line, you appear at the start of the next line
|
||||
|
||||
// scroll to the bottom?
|
||||
if (stringSize > stringViewSize && currentScrollPos > stringSize - stringViewSize)
|
||||
// to make sure not show buncha empty lines
|
||||
currentScrollPos = stringSize - stringViewSize
|
||||
// scroll to the top? (order is important!)
|
||||
if (currentScrollPos <= -1)
|
||||
currentScrollPos = 0 // scroll of -1 would result to show "Line 0" on screen
|
||||
}
|
||||
|
||||
// move editor cursor
|
||||
currentCursorPos = nextCol
|
||||
return [currentCursorPos, currentScrollPos]
|
||||
}
|
||||
|
||||
exports = { WindowObject, scrollVert, scrollHorz }
|
||||
|
||||
Reference in New Issue
Block a user