diff options
| author | John Shahid | 2019-04-29 13:53:38 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-05-07 14:51:42 -0400 |
| commit | e44b56d16ad0749e599700a73509c16391ed973e (patch) | |
| tree | 30fa77764767cdd4a954d94383c703db0f1dac9d /test | |
| parent | 32cf07819ae8cfdbf14e00f351c7f520fff325c3 (diff) | |
| download | emacs-e44b56d16ad0749e599700a73509c16391ed973e.tar.gz emacs-e44b56d16ad0749e599700a73509c16391ed973e.zip | |
Fix setting and resetting of scroll-with-delete
The start and end lines of the scroll region must to be in the range
[0,term-height). There are few placees that incorrectly set the end
line of the scroll region to term-height which is outside the valid
range. Combined with another off-by-one error in
term-set-scroll-region's clamping logic, this would cause
term-scroll-with-delete to be unnecessarily turned on.
* lisp/term.el (term-scroll-start,term-scroll-end): Use defvar-local
to define the variables and document the valid range of values that
the variables can take.
(term--last-line): New function to calculate the 0-based index of the
last line.
(term--reset-scroll-region): New function to reset the scroll region
to the full height of the terminal.
(term-mode,term-reset-size,term-reset-terminal): Call
term--reset-scroll-region to reset the scroll region.
(term-set-scroll-region): Fix the off-by-one error in the clamping
logic which allowed term-scroll-end to have values outside the valid
range [0,term-height).
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/term-tests.el | 136 |
1 files changed, 135 insertions, 1 deletions
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el index 9f5dcd559eb..6923096d224 100644 --- a/test/lisp/term-tests.el +++ b/test/lisp/term-tests.el | |||
| @@ -119,7 +119,141 @@ line3\r | |||
| 119 | line4\r | 119 | line4\r |
| 120 | line5\r | 120 | line5\r |
| 121 | line6\r | 121 | line6\r |
| 122 | ")))) | 122 | "))) |
| 123 | |||
| 124 | ;; test reverse scrolling | ||
| 125 | (should (equal "line1 | ||
| 126 | line7 | ||
| 127 | line6 | ||
| 128 | line2 | ||
| 129 | line5" | ||
| 130 | (term-test-screen-from-input 40 5 | ||
| 131 | '("\e[0;0H" | ||
| 132 | "\e[J" | ||
| 133 | "line1\r | ||
| 134 | line2\r | ||
| 135 | line3\r | ||
| 136 | line4\r | ||
| 137 | line5" | ||
| 138 | "\e[2;4r" | ||
| 139 | "\e[2;0H" | ||
| 140 | "\e[2;0H" | ||
| 141 | "\eMline6" | ||
| 142 | "\e[2;0H" | ||
| 143 | "\eMline7")))) | ||
| 144 | |||
| 145 | ;; test scrolling down | ||
| 146 | (should (equal "line1 | ||
| 147 | line3 | ||
| 148 | line4 | ||
| 149 | line7 | ||
| 150 | line5" | ||
| 151 | (term-test-screen-from-input 40 5 | ||
| 152 | '("\e[0;0H" | ||
| 153 | "\e[J" | ||
| 154 | "line1\r | ||
| 155 | line2\r | ||
| 156 | line3\r | ||
| 157 | line4\r | ||
| 158 | line5" | ||
| 159 | "\e[2;4r" | ||
| 160 | "\e[2;0H" | ||
| 161 | "\e[4;5H" | ||
| 162 | "\n\rline7")))) | ||
| 163 | |||
| 164 | ;; setting the scroll region end beyond the max height should not | ||
| 165 | ;; turn on term-scroll-with-delete | ||
| 166 | (should (equal "line1 | ||
| 167 | line2 | ||
| 168 | line3 | ||
| 169 | line4 | ||
| 170 | line5 | ||
| 171 | line6 | ||
| 172 | line7" | ||
| 173 | (term-test-screen-from-input 40 5 | ||
| 174 | '("\e[1;10r" | ||
| 175 | "line1\r | ||
| 176 | line2\r | ||
| 177 | line3\r | ||
| 178 | line4\r | ||
| 179 | line5\r | ||
| 180 | line6\r | ||
| 181 | line7")))) | ||
| 182 | |||
| 183 | |||
| 184 | ;; resetting the terminal should set the scroll region end to (1- term-height). | ||
| 185 | (should (equal " | ||
| 186 | line1 | ||
| 187 | line2 | ||
| 188 | line3 | ||
| 189 | line4 | ||
| 190 | " | ||
| 191 | (term-test-screen-from-input 40 5 | ||
| 192 | '("\e[1;10r" | ||
| 193 | "\ec" ;reset | ||
| 194 | "line1\r | ||
| 195 | line2\r | ||
| 196 | line3\r | ||
| 197 | line4\r | ||
| 198 | line5" | ||
| 199 | "\e[1;1H" | ||
| 200 | "\e[L")))) | ||
| 201 | |||
| 202 | ;; scroll region should be limited to the (1- term-height). Note, | ||
| 203 | ;; this fixes an off by one error when comparing the scroll region | ||
| 204 | ;; end with term-height. | ||
| 205 | (should (equal " | ||
| 206 | line1 | ||
| 207 | line2 | ||
| 208 | line3 | ||
| 209 | line4 | ||
| 210 | " | ||
| 211 | (term-test-screen-from-input 40 5 | ||
| 212 | '("\e[1;6r" | ||
| 213 | "line1\r | ||
| 214 | line2\r | ||
| 215 | line3\r | ||
| 216 | line4\r | ||
| 217 | line5" | ||
| 218 | "\e[1;1H" ;go back to home | ||
| 219 | "\e[L" ;insert a new line at the top | ||
| 220 | )))) | ||
| 221 | |||
| 222 | ;; setting the scroll region to the entire height should not turn on | ||
| 223 | ;; term-scroll-with-delete | ||
| 224 | (should (equal "line1 | ||
| 225 | line2 | ||
| 226 | line3 | ||
| 227 | line4 | ||
| 228 | line5 | ||
| 229 | line6" | ||
| 230 | (term-test-screen-from-input 40 5 | ||
| 231 | '("\e[1;5r" | ||
| 232 | "line1\r | ||
| 233 | line2\r | ||
| 234 | line3\r | ||
| 235 | line4\r | ||
| 236 | line5\r | ||
| 237 | line6")))) | ||
| 238 | |||
| 239 | ;; reset should reset term-scroll-with-delete | ||
| 240 | (should (equal "line1 | ||
| 241 | line2 | ||
| 242 | line3 | ||
| 243 | line4 | ||
| 244 | line5 | ||
| 245 | line6 | ||
| 246 | line7" | ||
| 247 | (term-test-screen-from-input 40 5 | ||
| 248 | '("\e[2;5r" ;set the region | ||
| 249 | "\ec" ;reset | ||
| 250 | "line1\r | ||
| 251 | line2\r | ||
| 252 | line3\r | ||
| 253 | line4\r | ||
| 254 | line5\r | ||
| 255 | line6\r | ||
| 256 | line7"))))) | ||
| 123 | 257 | ||
| 124 | (ert-deftest term-set-directory () | 258 | (ert-deftest term-set-directory () |
| 125 | (let ((term-ansi-at-user (user-real-login-name))) | 259 | (let ((term-ansi-at-user (user-real-login-name))) |