v0.8.0: fix multiline cursor — position-cursor now computes its own word-wrap

Removed dependency on (st :cursor-line) and (st :cursor-col) state.
position-cursor now does its own word-wrap and accum tracking to
determine which wrapped line and column the cursor is on. This makes
it independent of view-input's rendering state.
This commit is contained in:
2026-05-18 14:38:22 -04:00
parent b1aafc56b2
commit 46cac554ab

View File

@@ -351,16 +351,20 @@ and current sidebar mode (:auto/:visible/:hidden)."
(let* ((sw (if (sidebar-visible-p w) (or (st :sidebar-width) 42) 0)) (let* ((sw (if (sidebar-visible-p w) (or (st :sidebar-width) 42) 0))
(cw (- w sw)) (cw (- w sw))
(hpad 2) (hpad 2)
(chat-w (- w sw))
(text (input-string)) (text (input-string))
(text-len (length text)) (text-len (length text))
(pos (or (st :cursor-pos) 0)) (pos (or (st :cursor-pos) 0))
(prompt-w (- cw (* 2 hpad) 2)) (prompt-w (- cw (* 2 hpad) 2))
(cl (or (st :cursor-line) 0))
(cc (or (st :cursor-col) 0))
(lines (cl-tty.box:word-wrap text prompt-w)) (lines (cl-tty.box:word-wrap text prompt-w))
(n-lines (max 1 (length lines))) (n-lines (max 1 (length lines)))
(panel-rows (max 4 (+ n-lines 2))) (cl 0) (cc 0) (accum 0))
;; Find which wrapped line the cursor is on
(dotimes (i n-lines)
(let ((len (length (nth i lines))))
(when (and (>= pos accum) (<= pos (+ accum len)))
(setf cl i cc (- pos accum)))
(incf accum (1+ len))))
(let* ((panel-rows (max 4 (+ n-lines 2)))
(panel-top (- h 4 panel-rows -1)) (panel-top (- h 4 panel-rows -1))
(cx (+ hpad 2 cc)) (cx (+ hpad 2 cc))
(cy (+ panel-top 1 cl)) (cy (+ panel-top 1 cl))
@@ -370,7 +374,7 @@ and current sidebar mode (:auto/:visible/:hidden)."
(let ((ch (char text pos))) (let ((ch (char text pos)))
(cl-tty.backend:draw-text fb cx cy (string ch) bg-i input-fg)) (cl-tty.backend:draw-text fb cx cy (string ch) bg-i input-fg))
(cl-tty.backend:draw-text fb cx cy " " bg-i input-fg)) (cl-tty.backend:draw-text fb cx cy " " bg-i input-fg))
(finish-output (cl-tty.backend::backend-output-stream fb)))) (finish-output (cl-tty.backend::backend-output-stream fb)))))
#+END_SRC #+END_SRC
* v0.7.2 — Gate Trace * v0.7.2 — Gate Trace