Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
set cursor position for input-method
  • Loading branch information
cxxxr committed Jul 30, 2023
commit 4175d6f3a627a3993d4e11df9afa92e815411bfb
24 changes: 21 additions & 3 deletions frontends/sdl2/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,25 @@
:reader view-use-modeline)
(texture
:initarg :texture
:accessor view-texture)))
:accessor view-texture)
(last-cursor-x
:initform nil
:accessor view-last-cursor-x)
(last-cursor-y
:initform nil
:accessor view-last-cursor-y)))

(defmethod last-cursor-x ((view view))
(or (view-last-cursor-x view)
;; fallback to v1
(* (lem:last-print-cursor-x (view-window view))
(char-width))))

(defmethod last-cursor-y ((view view))
(or (view-last-cursor-y view)
;; fallback to v1
(* (lem:last-print-cursor-y (view-window view))
(char-height))))

(defun create-view (window x y width height use-modeline)
(when use-modeline (incf height))
Expand Down Expand Up @@ -998,8 +1016,8 @@

(defun set-input-method ()
(let* ((view (lem:window-view (lem:current-window)))
(cursor-x (* (lem:last-print-cursor-x (lem:current-window)) (char-width)))
(cursor-y (* (lem:last-print-cursor-y (lem:current-window)) (char-height)))
(cursor-x (last-cursor-x view))
(cursor-y (last-cursor-y view))
(text lem-sdl2/keyboard::*textediting-text*)
(x (+ (* (view-x view) (char-width))
cursor-x))
Expand Down
21 changes: 16 additions & 5 deletions frontends/sdl2/text-buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@
(attribute-foreground-color attribute)
(attribute-background-color attribute)))

(defun set-cursor-position (window x y)
(let ((view (lem:window-view window)))
(setf (view-last-cursor-x view) x
(view-last-cursor-y view) y)))

(defstruct logical-line
string
attributes
Expand Down Expand Up @@ -262,6 +267,9 @@
(current-renderer)
(text-object-surface drawing-object)))
(y (- bottom-y surface-height)))
(when (and attribute (cursor-attribute-p attribute))
(setf (view-last-cursor-x (lem:window-view window)) x
(view-last-cursor-y (lem:window-view window)) y))
(sdl2:with-rects ((rect x y surface-width surface-height))
(set-color background)
(sdl2:render-fill-rect (current-renderer) rect))
Expand All @@ -286,11 +294,14 @@

(defmethod draw-object ((drawing-object eol-cursor-object) x bottom-y window)
(set-color (eol-cursor-object-color drawing-object))
(sdl2:with-rects ((rect x
(- bottom-y (object-height drawing-object))
(char-width)
(object-height drawing-object)))
(sdl2:render-fill-rect (current-renderer) rect)))
(let ((y (- bottom-y (object-height drawing-object))))
(setf (view-last-cursor-x (lem:window-view window)) x
(view-last-cursor-y (lem:window-view window)) y)
(sdl2:with-rects ((rect x
y
(char-width)
(object-height drawing-object)))
(sdl2:render-fill-rect (current-renderer) rect))))

(defmethod draw-object ((drawing-object extend-to-eol-object) x bottom-y window)
(set-color (extend-to-eol-object-color drawing-object))
Expand Down