diff --git a/org/channel-tui-view.org b/org/channel-tui-view.org index cfe4283..555c5fe 100644 --- a/org/channel-tui-view.org +++ b/org/channel-tui-view.org @@ -343,11 +343,7 @@ and current sidebar mode (:auto/:visible/:hidden)." (setf (st :dirty) (list nil nil nil)))) (defun position-cursor (fb w h) - "Draw cursor at the input insertion point using reverse video (Emacs-style). - - The character under the cursor is redrawn with foreground and background - swapped. If the cursor is past the end of the input string, a reversed - space is drawn." + "Draw cursor at the input insertion point using reverse video (Emacs-style)." (let* ((sw (if (sidebar-visible-p w) (or (st :sidebar-width) 42) 0)) (cw (- w sw)) (hpad 2) @@ -358,12 +354,18 @@ and current sidebar mode (:auto/:visible/:hidden)." (lines (cl-tty.box:word-wrap text prompt-w)) (n-lines (max 1 (length lines))) (cl 0) (cc 0) (accum 0)) - ;; Find which wrapped line the cursor is on + ;; Find which wrapped line the cursor falls on (dotimes (i n-lines) (let ((len (length (nth i lines)))) - (when (and (>= pos accum) (<= pos (+ accum len))) + (when (and (>= pos accum) (or (<= pos (+ accum len)) + (= i (1- n-lines)))) (setf cl i cc (- pos accum))) (incf accum (1+ len)))) + ;; If text exists but pos is 0, move cursor to end (recovery for pos reset) + (when (and (plusp text-len) (zerop pos)) + (setf pos text-len + cl (1- n-lines) + cc (length (car (last lines))))) (let* ((panel-rows (max 4 (+ n-lines 2))) (panel-top (- h 4 panel-rows -1)) (cx (+ hpad 2 cc))