Fix frame size problem caused by markdown separators (issue#68)
* eldoc-box.el: (eldoc-box--markdown-separator-display-props): New variable. (eldoc-box--update-childframe-geometry): New workaround. (eldoc-box--prettify-markdown-separator): Use the new variable.
This commit is contained in:
parent
a9d54abb6c
commit
73345daa47
32
eldoc-box.el
32
eldoc-box.el
@ -404,6 +404,8 @@ base on WIDTH and HEIGHT of childframe text window."
|
||||
(cons (or (eldoc-box--at-point-x-by-company) x)
|
||||
y)))
|
||||
|
||||
(defvar eldoc-box--markdown-separator-display-props)
|
||||
|
||||
(defun eldoc-box--update-childframe-geometry (frame window)
|
||||
"Update the size and the position of childframe.
|
||||
FRAME is the childframe, WINDOW is the primary window."
|
||||
@ -411,13 +413,18 @@ FRAME is the childframe, WINDOW is the primary window."
|
||||
;; property of (space :width text) -- which is what we apply onto
|
||||
;; markdown separators -- ‘window-text-pixel-size’ wouldn’t return
|
||||
;; the correct value. Instead, it returns the current window width.
|
||||
;; So now the childram only grows in size and never shrinks. For
|
||||
;; whatever reason, if we set the frame size very small before
|
||||
;; calculating window’s text size, it can return the right value.
|
||||
;; So now the childram only grows in size and never shrinks.
|
||||
;;
|
||||
;; (My guess is that the function takes (space :width text) at face
|
||||
;; value, but that can’t be the whole picture because it works fine
|
||||
;; when I manually evaluate the function in the childframe...)
|
||||
(set-frame-size frame 1 1 t)
|
||||
;;
|
||||
;; The original workaround of setting the frame size to something
|
||||
;; small before calling ‘window-text-pixel-size’ works, but brings
|
||||
;; other problems. Now we just set the display property to nil
|
||||
;; before calling ‘window-text-pixel-size’, and set them back after.
|
||||
(setcdr eldoc-box--markdown-separator-display-props nil)
|
||||
|
||||
(let* ((size
|
||||
(window-text-pixel-size
|
||||
window nil nil
|
||||
@ -430,6 +437,11 @@ FRAME is the childframe, WINDOW is the primary window."
|
||||
(frame-resize-pixelwise t)
|
||||
(pos (funcall eldoc-box-position-function width height)))
|
||||
(set-frame-size frame width height t)
|
||||
|
||||
;; Set the display property back.
|
||||
(setcdr eldoc-box--markdown-separator-display-props
|
||||
'(:width text))
|
||||
|
||||
;; move position
|
||||
(set-frame-position frame (car pos) (cdr pos))))
|
||||
|
||||
@ -689,6 +701,13 @@ instead."
|
||||
|
||||
;;;; Markdown compatibility
|
||||
|
||||
(defvar-local eldoc-box--markdown-separator-display-props
|
||||
'(space :width text)
|
||||
"Stores the display text property applied to markdown separators.
|
||||
|
||||
Due to a bug, in ‘eldoc-box--update-childframe-geometry’, we
|
||||
modify the display property temporarily and then set it back.")
|
||||
|
||||
(defun eldoc-box--prettify-markdown-separator ()
|
||||
"Prettify the markdown separator in doc returned by Eglot.
|
||||
Refontify the separator so they span exactly the width of the
|
||||
@ -697,9 +716,10 @@ childframe."
|
||||
(goto-char (point-min))
|
||||
(let (prop)
|
||||
(while (setq prop (text-property-search-forward 'markdown-hr))
|
||||
(add-text-properties (prop-match-beginning prop)
|
||||
(add-text-properties
|
||||
(prop-match-beginning prop)
|
||||
(prop-match-end prop)
|
||||
'( display (space :width text)
|
||||
`( display ,eldoc-box--markdown-separator-display-props
|
||||
face ( :strike-through t
|
||||
:height 0.4)))))))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user