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