Commit b0177da7 authored by Luke Yen-Xun Lee's avatar Luke Yen-Xun Lee Committed by Eli Zaretskii
Browse files

Fix ruler-mode text-scaling issues

* lisp/ruler-mode.el (ruler-mode-text-scaled-width): New function
for computing scaled text width.
(ruler-mode-text-scaled-window-hscroll)
(ruler-mode-text-scaled-window-width): Compute text scaled
`window-width' value.
(ruler-mode-mouse-grab-any-column, ruler-mode-mouse-add-tab-stop)
(ruler-mode-ruler): Change `window-hscroll' into
`ruler-mode-text-scaled-window-hscroll', and change `window-width'
into `ruler-mode-text-scaled-window-width'.
parent 704fea97
......@@ -360,6 +360,20 @@ START-EVENT is the mouse click event."
That is `fill-column', `comment-column', `goal-column', or nil when
nothing is dragged.")
(defun ruler-mode-text-scaled-width (width)
"Compute scaled text width according to current font scaling.
Convert a width of char units into a text-scaled char width units,
Ex. `window-hscroll'."
(/ (* width (frame-char-width)) (default-font-width)))
(defun ruler-mode-text-scaled-window-hscroll ()
"Text scaled `window-hscroll'."
(ruler-mode-text-scaled-width (window-hscroll)))
(defun ruler-mode-text-scaled-window-width ()
"Text scaled `window-width'."
(ruler-mode-text-scaled-width (window-width)))
(defun ruler-mode-mouse-grab-any-column (start-event)
"Drag a column symbol on the ruler.
Start dragging on mouse down event START-EVENT, and update the column
......@@ -372,9 +386,9 @@ dragging. See also the variable `ruler-mode-dragged-symbol'."
(save-selected-window
(select-window (posn-window start))
(setq col (ruler-mode-window-col (car (posn-col-row start)))
newc (+ col (window-hscroll)))
newc (+ col (ruler-mode-text-scaled-window-hscroll)))
(and
(>= col 0) (< col (window-width))
(>= col 0) (< col (ruler-mode-text-scaled-window-width))
(cond
;; Handle the fill column.
......@@ -457,8 +471,8 @@ Called on each mouse motion event START-EVENT."
(save-selected-window
(select-window (posn-window start))
(setq col (ruler-mode-window-col (car (posn-col-row end)))
newc (+ col (window-hscroll)))
(when (and (>= col 0) (< col (window-width)))
newc (+ col (ruler-mode-text-scaled-window-hscroll)))
(when (and (>= col 0) (< col (ruler-mode-text-scaled-window-width)))
(set ruler-mode-dragged-symbol newc)))))
(defun ruler-mode-mouse-add-tab-stop (start-event)
......@@ -473,8 +487,8 @@ START-EVENT is the mouse click event."
(save-selected-window
(select-window (posn-window start))
(setq col (ruler-mode-window-col (car (posn-col-row start)))
ts (+ col (window-hscroll)))
(and (>= col 0) (< col (window-width))
ts (+ col (ruler-mode-text-scaled-window-hscroll)))
(and (>= col 0) (< col (ruler-mode-text-scaled-window-width))
(not (member ts tab-stop-list))
(progn
(message "Tab stop set to %d" ts)
......@@ -494,8 +508,8 @@ START-EVENT is the mouse click event."
(save-selected-window
(select-window (posn-window start))
(setq col (ruler-mode-window-col (car (posn-col-row start)))
ts (+ col (window-hscroll)))
(and (>= col 0) (< col (window-width))
ts (+ col (ruler-mode-text-scaled-window-hscroll)))
(and (>= col 0) (< col (ruler-mode-text-scaled-window-width))
(member ts tab-stop-list)
(progn
(message "Tab stop at %d deleted" ts)
......@@ -648,11 +662,11 @@ Optional argument PROPS specifies other text properties to apply."
(defun ruler-mode-ruler ()
"Compute and return a header line ruler."
(let* ((w (window-width))
(let* ((w (ruler-mode-text-scaled-window-width))
(m (window-margins))
(f (window-fringes))
(i 0)
(j (window-hscroll))
(j (ruler-mode-text-scaled-window-hscroll))
;; Setup the scrollbar, fringes, and margins areas.
(lf (ruler-mode-space
'left-fringe
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment