v0.8.0: fix cursor position on multi-line input
view-input now stores cursor-line and cursor-col in state after word-wrapping. position-cursor uses these to place the cursor on the correct wrapped line, instead of the hardcoded row (- h 6) which always put the cursor on the first line.
This commit is contained in:
@@ -219,7 +219,7 @@ and current sidebar mode (:auto/:visible/:hidden)."
|
||||
(dotimes (r panel-rows)
|
||||
(cl-tty.backend:draw-text fb hpad (+ panel-top r) "│" (theme-color :input-prompt) nil))
|
||||
;; Draw each wrapped input line
|
||||
(let ((accum 0) (cursor-line 0) (cursor-col 0))
|
||||
(let ((accum 0) (cl 0) (cc 0))
|
||||
(dotimes (i n-lines)
|
||||
(let* ((line (nth i lines))
|
||||
(row (+ panel-top 1 i))
|
||||
@@ -227,9 +227,9 @@ and current sidebar mode (:auto/:visible/:hidden)."
|
||||
(when (>= row (- h 4)) (return))
|
||||
(cl-tty.backend:draw-text fb (+ hpad 2) row line input-fg nil)
|
||||
(when (and (>= pos accum) (<= pos (+ accum len)))
|
||||
(setf cursor-line i
|
||||
cursor-col (- pos accum)))
|
||||
(setf cl i cc (- pos accum)))
|
||||
(incf accum (1+ len))))
|
||||
(setf (st :cursor-line) cl (st :cursor-col) cc))
|
||||
;; Hint bar at h-2: F:/MCP: on left, token gauge + keybindings on right
|
||||
(let* ((focal (or (st :foveal-id) "-"))
|
||||
(focal-str (format nil "F:~a" focal))
|
||||
@@ -351,13 +351,19 @@ and current sidebar mode (:auto/:visible/:hidden)."
|
||||
(let* ((sw (if (sidebar-visible-p w) (or (st :sidebar-width) 42) 0))
|
||||
(cw (- w sw))
|
||||
(hpad 2)
|
||||
(chat-w (- w sw))
|
||||
(text (input-string))
|
||||
(text-len (length text))
|
||||
(pos (or (st :cursor-pos) 0))
|
||||
(prompt-w (- cw (* 2 hpad) 2))
|
||||
(display-start (max 0 (- pos (1- prompt-w))))
|
||||
(cx (+ hpad 2 (- pos display-start)))
|
||||
(cy (- h 6))
|
||||
(cl (or (st :cursor-line) 0))
|
||||
(cc (or (st :cursor-col) 0))
|
||||
(lines (cl-tty.box:word-wrap text prompt-w))
|
||||
(n-lines (max 1 (length lines)))
|
||||
(panel-rows (max 4 (+ n-lines 2)))
|
||||
(panel-top (- h 4 panel-rows -1))
|
||||
(cx (+ hpad 2 cc))
|
||||
(cy (+ panel-top 1 cl))
|
||||
(bg-i (theme-color :bg-input))
|
||||
(input-fg (theme-color :input-fg)))
|
||||
(if (< pos text-len)
|
||||
|
||||
Reference in New Issue
Block a user