summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAaron Jensen <aaronjensen@gmail.com>2021-01-09 20:43:32 -0600
committerEli Zaretskii <eliz@gnu.org>2021-01-15 14:04:25 +0200
commit4dc72dd9deb1c3394ada3de3f52bc7c1ff831ab6 (patch)
tree2f6adb25275363194fc4fe35d565c8396c168586 /test
parent66ac17289a5d04366a6b05eb5a105dff408b16b8 (diff)
downloademacs-4dc72dd9deb1c3394ada3de3f52bc7c1ff831ab6.tar.gz
Fix 'window-text-pixel-size' when there are leading/trailing spaces
First, scan to find the first non-whitespace character and then backtrack to find the beginning of the line. The previous algorithm always started on the non-whitespace character during the backtrack, causing it to stop immediately and not actually find the beginning of the line. The same applies to the end of line calculation. * src/xdisp.c: (Fwindow_text_pixel_size): Fix off by one error. (Bug#45748) * test/src/xdisp-tests.el (xdisp-tests--window-text-pixel-size) (xdisp-tests--window-text-pixel-size-leading-space) (xdisp-tests--window-text-pixel-size-trailing-space): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/src/xdisp-tests.el30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/src/xdisp-tests.el b/test/src/xdisp-tests.el
index d13ce77a997..ec96d777ffb 100644
--- a/test/src/xdisp-tests.el
+++ b/test/src/xdisp-tests.el
@@ -72,4 +72,34 @@
(should (equal (nth 0 posns) (nth 1 posns)))
(should (equal (nth 1 posns) (nth 2 posns)))))
+(ert-deftest xdisp-tests--window-text-pixel-size () ;; bug#45748
+ (with-temp-buffer
+ (insert "xxx")
+ (let* ((window
+ (display-buffer (current-buffer) '(display-buffer-in-child-frame . nil)))
+ (char-width (frame-char-width))
+ (size (window-text-pixel-size nil t t)))
+ (delete-frame (window-frame window))
+ (should (equal (/ (car size) char-width) 3)))))
+
+(ert-deftest xdisp-tests--window-text-pixel-size-leading-space () ;; bug#45748
+ (with-temp-buffer
+ (insert " xx")
+ (let* ((window
+ (display-buffer (current-buffer) '(display-buffer-in-child-frame . nil)))
+ (char-width (frame-char-width))
+ (size (window-text-pixel-size nil t t)))
+ (delete-frame (window-frame window))
+ (should (equal (/ (car size) char-width) 3)))))
+
+(ert-deftest xdisp-tests--window-text-pixel-size-trailing-space () ;; bug#45748
+ (with-temp-buffer
+ (insert "xx ")
+ (let* ((window
+ (display-buffer (current-buffer) '(display-buffer-in-child-frame . nil)))
+ (char-width (frame-char-width))
+ (size (window-text-pixel-size nil t t)))
+ (delete-frame (window-frame window))
+ (should (equal (/ (car size) char-width) 3)))))
+
;;; xdisp-tests.el ends here