diff --git a/org/text-input.org b/org/text-input.org index 944b0dd..a1a3f02 100644 --- a/org/text-input.org +++ b/org/text-input.org @@ -1590,12 +1590,26 @@ width, it's clamped to the last visible position. (x (if ln (layout-node-x ln) 0)) (y (if ln (layout-node-y ln) 0)) (w (if ln (layout-node-width ln) 80)) (value (text-input-value in)) (cursor (text-input-cursor in)) - (display (if (plusp (length value)) value (or (text-input-placeholder in) ""))) - (truncated (subseq display 0 (min (length display) w)))) - (draw-text backend x y truncated nil nil) - (when (plusp (length value)) - (let ((cursor-col (min cursor (length truncated)))) - (draw-text backend (+ x cursor-col) y "█" :bright-white nil))))) + (display (if (plusp (length value)) value (or (text-input-placeholder in) "")))) + (when (zerop (length display)) (return-from render (values))) + (let* ((lines (cl-tty.box:word-wrap display w)) + (n-lines (length lines))) + ;; Draw each wrapped line + (loop for line in lines + for row from 0 + do (let ((fg (if (plusp (length value)) nil :dim))) + (draw-text backend x (+ y row) line fg nil))) + ;; Draw block cursor at the right position when value is non-empty + (when (plusp (length value)) + (let ((cl 0) (cc 0) (accum 0)) + (dotimes (i n-lines) + (let ((len (length (nth i lines)))) + (when (and (>= cursor accum) (or (< cursor (+ accum len)) (= i (1- n-lines)))) + (setf cl i cc (- cursor accum))) + (incf accum (1+ len)))) + (let ((cx (+ x cc)) + (cy (+ y cl))) + (draw-text backend cx cy "█" :bright-white nil))))))) #+END_SRC * Keybinding System