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.
This commit is contained in:
parent
66ac17289a
commit
4dc72dd9de
2 changed files with 36 additions and 2 deletions
|
@ -10649,9 +10649,10 @@ include the height of both, if present, in the return value. */)
|
|||
bpos = BEGV_BYTE;
|
||||
while (bpos < ZV_BYTE)
|
||||
{
|
||||
c = fetch_char_advance (&start, &bpos);
|
||||
c = FETCH_BYTE (bpos);
|
||||
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r'))
|
||||
break;
|
||||
inc_both (&start, &bpos);
|
||||
}
|
||||
while (bpos > BEGV_BYTE)
|
||||
{
|
||||
|
@ -10680,7 +10681,10 @@ include the height of both, if present, in the return value. */)
|
|||
dec_both (&end, &bpos);
|
||||
c = FETCH_BYTE (bpos);
|
||||
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r'))
|
||||
break;
|
||||
{
|
||||
inc_both (&end, &bpos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (bpos < ZV_BYTE)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue