From 46cac554ab15dc1821b0b12260c06d087b5a3245 Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Mon, 18 May 2026 14:38:22 -0400 Subject: [PATCH] =?UTF-8?q?v0.8.0:=20fix=20multiline=20cursor=20=E2=80=94?= =?UTF-8?q?=20position-cursor=20now=20computes=20its=20own=20word-wrap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- org/channel-tui-view.org | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/org/channel-tui-view.org b/org/channel-tui-view.org index e5d96ee..cfe4283 100644 --- a/org/channel-tui-view.org +++ b/org/channel-tui-view.org @@ -351,26 +351,30 @@ 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)) - (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) - (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)))) + (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)) + (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) + (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 * v0.7.2 — Gate Trace