Avoiding duplicate clears in edit-line, which cause unintended scroll up for multi-line inputs.

This commit is contained in:
Alex Shinn 2014-05-05 16:31:49 +09:00
parent ce24f67224
commit bb54932b5a

View file

@ -126,10 +126,11 @@
;; buffers ;; buffers
(define-record-type Buffer (define-record-type Buffer
(%make-buffer refresh? min pos row max-row col gap start width string (%make-buffer refresh? cleared? min pos row max-row col gap start width
history complete? single-line?) string history complete? single-line?)
buffer? buffer?
(refresh? buffer-refresh? buffer-refresh?-set!) (refresh? buffer-refresh? buffer-refresh?-set!)
(cleared? buffer-cleared? buffer-cleared?-set!)
(min buffer-min buffer-min-set!) (min buffer-min buffer-min-set!)
(pos buffer-pos buffer-pos-set!) (pos buffer-pos buffer-pos-set!)
(row buffer-row buffer-row-set!) (row buffer-row buffer-row-set!)
@ -148,7 +149,7 @@
(define default-buffer-width 80) (define default-buffer-width 80)
(define (make-buffer) (define (make-buffer)
(%make-buffer #f 0 0 0 0 0 default-buffer-size 0 default-buffer-width (%make-buffer #f #f 0 0 0 0 0 default-buffer-size 0 default-buffer-width
(make-string default-buffer-size) '() #f #f)) (make-string default-buffer-size) '() #f #f))
(define (buffer->string buf) (define (buffer->string buf)
@ -362,12 +363,15 @@
(lp (+ i 1) row (+ col off))))))))))) (lp (+ i 1) row (+ col off)))))))))))
(define (buffer-clear buf out) (define (buffer-clear buf out)
;; goto start of input (cond
(terminal-goto-col out 0) ((not (buffer-cleared? buf))
(if (positive? (buffer-row buf)) ;; goto start of input
(terminal-up out (buffer-row buf))) (terminal-goto-col out 0)
;; clear below (if (positive? (buffer-row buf))
(terminal-clear-below out)) (terminal-up out (buffer-row buf)))
;; clear below
(terminal-clear-below out)
(buffer-cleared?-set! buf #t))))
(define (buffer-draw buf out) (define (buffer-draw buf out)
(let* ((gap (buffer-gap buf)) (let* ((gap (buffer-gap buf))
@ -398,7 +402,8 @@
(if (< (buffer-row buf) (buffer-max-row buf)) (if (< (buffer-row buf) (buffer-max-row buf))
(terminal-up out (- (buffer-max-row buf) (buffer-row buf)))))) (terminal-up out (- (buffer-max-row buf) (buffer-row buf))))))
(terminal-goto-col out (buffer-col buf)) (terminal-goto-col out (buffer-col buf))
(flush-output out))) (flush-output out)
(buffer-cleared?-set! buf #f)))
(define (buffer-refresh buf out) (define (buffer-refresh buf out)
(cond ((buffer-refresh? buf) (cond ((buffer-refresh? buf)
@ -449,7 +454,8 @@
;; fast path - append to end of buffer w/o wrapping to next line ;; fast path - append to end of buffer w/o wrapping to next line
(display x out) (display x out)
(flush-output out) (flush-output out)
(buffer-col-set! buf (+ (buffer-col buf) len))) (buffer-col-set! buf (+ (buffer-col buf) len))
(buffer-cleared?-set! buf #f))
(else (else
(buffer-refresh?-set! buf #t))))) (buffer-refresh?-set! buf #t)))))