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:
@@ -351,26 +351,30 @@ 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))
|
||||||
(panel-top (- h 4 panel-rows -1))
|
;; Find which wrapped line the cursor is on
|
||||||
(cx (+ hpad 2 cc))
|
(dotimes (i n-lines)
|
||||||
(cy (+ panel-top 1 cl))
|
(let ((len (length (nth i lines))))
|
||||||
(bg-i (theme-color :bg-input))
|
(when (and (>= pos accum) (<= pos (+ accum len)))
|
||||||
(input-fg (theme-color :input-fg)))
|
(setf cl i cc (- pos accum)))
|
||||||
(if (< pos text-len)
|
(incf accum (1+ len))))
|
||||||
(let ((ch (char text pos)))
|
(let* ((panel-rows (max 4 (+ n-lines 2)))
|
||||||
(cl-tty.backend:draw-text fb cx cy (string ch) bg-i input-fg))
|
(panel-top (- h 4 panel-rows -1))
|
||||||
(cl-tty.backend:draw-text fb cx cy " " bg-i input-fg))
|
(cx (+ hpad 2 cc))
|
||||||
(finish-output (cl-tty.backend::backend-output-stream fb))))
|
(cy (+ panel-top 1 cl))
|
||||||
|
(bg-i (theme-color :bg-input))
|
||||||
|
(input-fg (theme-color :input-fg)))
|
||||||
|
(if (< pos text-len)
|
||||||
|
(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 " " bg-i input-fg))
|
||||||
|
(finish-output (cl-tty.backend::backend-output-stream fb)))))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
* v0.7.2 — Gate Trace
|
* v0.7.2 — Gate Trace
|
||||||
|
|||||||
Reference in New Issue
Block a user