Clamp cursor to within the actual text
This commit is contained in:
parent
8fbeeccfdb
commit
f51617f774
|
@ -114,15 +114,27 @@
|
|||
(list-set! buf y
|
||||
(string-delete-kth (list-ref buf y) x)))
|
||||
|
||||
(define (clamp n lowest highest)
|
||||
(if (< n lowest)
|
||||
lowest
|
||||
(if (> n highest)
|
||||
highest
|
||||
n)))
|
||||
|
||||
(define* (move-cursor state #:key x y relative?)
|
||||
(if x (set! (curx state)
|
||||
(if relative?
|
||||
(+ x (curx state))
|
||||
x)))
|
||||
(if y (set! (cury state)
|
||||
(if relative?
|
||||
(+ y (cury state))
|
||||
y)))
|
||||
(define newx (if x
|
||||
(if relative?
|
||||
(+ x (curx state))
|
||||
x)
|
||||
(curx state)))
|
||||
(define newy (if y
|
||||
(if relative?
|
||||
(+ y (cury state))
|
||||
y)
|
||||
(cury state)))
|
||||
(set! (cury state) (clamp newy 0 (1- (length (buffer state)))))
|
||||
(set! (curx state) (clamp newx 0 (string-length
|
||||
(list-ref (buffer state) (cury state)))))
|
||||
(define scroll (lines-scrolled state))
|
||||
(define screen-height (height (get-frontend state)))
|
||||
(define relative-y (- (cury state) scroll))
|
||||
|
|
Loading…
Reference in New Issue