>From 9564645a5b9e9abb5487094596a4d9a3b9279108 Mon Sep 17 00:00:00 2001 From: John Shahid Date: Mon, 29 Apr 2019 13:53:38 -0400 Subject: [PATCH] Fix setting and resetting of scroll-with-delete * lisp/term.el (term-mode): (term-reset-size): term-height. (term-reset-terminal): Set term-scroll-end to (1- term-height) instead of term-height. (term-set-scroll-region): Do not set term-scroll-with-delete when the region is set to the height of the terminal. Fix off by one error when checking if scroll-end exceeds the terminal height. * test/lisp/term-tests.el (term-scrolling-region): Add more tests to term mode handle scroll region properly. --- lisp/term.el | 13 ++-- test/lisp/term-tests.el | 136 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 8 deletions(-) diff --git a/lisp/term.el b/lisp/term.el index f051e63415..f849b38417 100644 --- a/lisp/term.el +++ b/lisp/term.el @@ -1076,7 +1076,7 @@ term-mode (make-local-variable 'term-current-row) (make-local-variable 'term-log-buffer) (make-local-variable 'term-scroll-start) - (set (make-local-variable 'term-scroll-end) term-height) + (set (make-local-variable 'term-scroll-end) (1- term-height)) (make-local-variable 'term-scroll-with-delete) (make-local-variable 'term-pager-count) (make-local-variable 'term-pager-old-local-map) @@ -1174,7 +1174,7 @@ term-reset-size (setq term-start-line-column nil) (setq term-current-row nil) (setq term-current-column nil) - (term-set-scroll-region 0 height) + (term-set-scroll-region 0 (1- height)) ;; `term-set-scroll-region' causes these to be set, we have to ;; clear them again since we're changing point (Bug#30544). (setq term-start-line-column nil) @@ -3213,8 +3213,7 @@ term-reset-terminal (term-ansi-reset) (setq term-current-row 0) (setq term-current-column 1) - (setq term-scroll-start 0) - (setq term-scroll-end term-height) + (term-set-scroll-region 0 (1- term-height)) (setq term-insert-mode nil) ;; FIXME: No idea why this is here, it looks wrong. --Stef (setq term-ansi-face-already-done nil)) @@ -3433,13 +3432,13 @@ term-set-scroll-region 0 top)) (setq term-scroll-end - (if (or (<= bottom term-scroll-start) (> bottom term-height)) - term-height + (if (or (<= bottom term-scroll-start) (> bottom (1- term-height))) + (1- term-height) bottom)) (setq term-scroll-with-delete (or (term-using-alternate-sub-buffer) (not (and (= term-scroll-start 0) - (= term-scroll-end term-height))))) + (= term-scroll-end (1- term-height)))))) (term-move-columns (- (term-current-column))) (term-goto 0 0)) diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el index 9f5dcd559e..6923096d22 100644 --- a/test/lisp/term-tests.el +++ b/test/lisp/term-tests.el @@ -119,7 +119,141 @@ term-test-screen-from-input line4\r line5\r line6\r -")))) +"))) + + ;; test reverse scrolling + (should (equal "line1 +line7 +line6 +line2 +line5" + (term-test-screen-from-input 40 5 + '("\e[0;0H" + "\e[J" + "line1\r +line2\r +line3\r +line4\r +line5" + "\e[2;4r" + "\e[2;0H" + "\e[2;0H" + "\eMline6" + "\e[2;0H" + "\eMline7")))) + + ;; test scrolling down + (should (equal "line1 +line3 +line4 +line7 +line5" + (term-test-screen-from-input 40 5 + '("\e[0;0H" + "\e[J" + "line1\r +line2\r +line3\r +line4\r +line5" + "\e[2;4r" + "\e[2;0H" + "\e[4;5H" + "\n\rline7")))) + + ;; setting the scroll region end beyond the max height should not + ;; turn on term-scroll-with-delete + (should (equal "line1 +line2 +line3 +line4 +line5 +line6 +line7" + (term-test-screen-from-input 40 5 + '("\e[1;10r" + "line1\r +line2\r +line3\r +line4\r +line5\r +line6\r +line7")))) + + + ;; resetting the terminal should set the scroll region end to (1- term-height). + (should (equal " +line1 +line2 +line3 +line4 +" + (term-test-screen-from-input 40 5 + '("\e[1;10r" + "\ec" ;reset + "line1\r +line2\r +line3\r +line4\r +line5" + "\e[1;1H" + "\e[L")))) + + ;; scroll region should be limited to the (1- term-height). Note, + ;; this fixes an off by one error when comparing the scroll region + ;; end with term-height. + (should (equal " +line1 +line2 +line3 +line4 +" + (term-test-screen-from-input 40 5 + '("\e[1;6r" + "line1\r +line2\r +line3\r +line4\r +line5" + "\e[1;1H" ;go back to home + "\e[L" ;insert a new line at the top + )))) + + ;; setting the scroll region to the entire height should not turn on + ;; term-scroll-with-delete + (should (equal "line1 +line2 +line3 +line4 +line5 +line6" + (term-test-screen-from-input 40 5 + '("\e[1;5r" + "line1\r +line2\r +line3\r +line4\r +line5\r +line6")))) + + ;; reset should reset term-scroll-with-delete + (should (equal "line1 +line2 +line3 +line4 +line5 +line6 +line7" + (term-test-screen-from-input 40 5 + '("\e[2;5r" ;set the region + "\ec" ;reset + "line1\r +line2\r +line3\r +line4\r +line5\r +line6\r +line7"))))) (ert-deftest term-set-directory () (let ((term-ansi-at-user (user-real-login-name))) -- 2.21.0