resume in shy

main
Matthew Butterick 6 years ago
parent 3613946395
commit edab49eba3

@ -136,10 +136,8 @@
current-wrap current-wrap
(cons q current-wrap)) (cdr qs)))) (cons q current-wrap)) (cdr qs))))
(define dist (and (quad? q) (printable? q (and at-start? 'start)) (distance q)))
(cond (cond
[at-start? ; assume printing char [at-start?
(cond (cond
[(and (soft-break? q) (nonprinting-at-start? q)) [(and (soft-break? q) (nonprinting-at-start? q))
(debug-report q 'skipping-soft-break-at-beginning) (debug-report q 'skipping-soft-break-at-beginning)
@ -149,14 +147,16 @@
current-partial current-partial
current-dist current-dist
(cdr qs))] (cdr qs))]
[else [else ; printing quad
(debug-report 'at-start) (debug-report 'hard-quad-at-start)
(loop wraps (loop wraps
current-wrap current-wrap
(cons q current-partial) (cons q current-partial)
dist (distance q)
(cdr qs))])] (cdr qs))])]
[else [else
(define dist (and (quad? q) (or (printable? q) (printable? q 'end)) (distance q)))
(debug-report dist)
(define would-overflow? (> (+ dist current-dist) target-size)) (define would-overflow? (> (+ dist current-dist) target-size))
(cond (cond
[would-overflow? [would-overflow?
@ -173,7 +173,7 @@
[else [else
(debug-report 'would-overflow-hard) (debug-report 'would-overflow-hard)
;; finish the wrap & reset the line without consuming a quad ;; finish the wrap & reset the line without consuming a quad
(if (empty? current-wrap) (if (empty? current-wrap) ; means we have not captured a soft break
(loop (list* (list break-val) current-partial wraps) (loop (list* (list break-val) current-partial wraps)
current-wrap ; which is empty current-wrap ; which is empty
null null
@ -286,7 +286,6 @@
(check-equal? (linewrap (list x x x x x) 1) (list x 'lb x 'lb x 'lb x 'lb x)) (check-equal? (linewrap (list x x x x x) 1) (list x 'lb x 'lb x 'lb x 'lb x))
(check-equal? (linewrap (list x x x x x) 10) (list x x x x x)))) (check-equal? (linewrap (list x x x x x) 10) (list x x x x x))))
(module+ test (module+ test
(test-case (test-case
"chars and spaces" "chars and spaces"
@ -318,20 +317,24 @@
(check-equal? (linewrap (list x x hyph x x) 4) (list x x hyph 'lb x x)) (check-equal? (linewrap (list x x hyph x x) 4) (list x x hyph 'lb x x))
(check-equal? (linewrap (list x x hyph x x) 5) (list x x hyph x x)))) (check-equal? (linewrap (list x x hyph x x) 5) (list x x hyph x x))))
#;(module+ test (linewrap (list a b shy c d) 4 #t)
(test-case ;(check-equal? (linewrap (list x x shy x x) 4) (list x x x x))
"soft hyphens"
(check-equal? (linewrap (list shy) 1) (list)) (module+ test
(check-equal? (linewrap (list shy shy) 2) (list)) (test-case
(check-equal? (linewrap (list shy shy shy) 2) (list)) "soft hyphens"
(check-equal? (linewrap (list x shy) 1) (list x)) (check-equal? (linewrap (list shy) 1) (list))
(check-equal? (linewrap (list x shy shy shy shy) 1) (list x)) (check-equal? (linewrap (list shy shy) 2) (list))
(check-equal? (linewrap (list x x shy x x) 1) (list x 'lb x 'lb x 'lb x)) (check-equal? (linewrap (list shy shy shy) 2) (list))
(check-equal? (linewrap (list x x shy x x) 2) (list x x 'lb x x)) (check-equal? (linewrap (list x shy) 1) (list x))
(check-equal? (linewrap (list x x shy x x) 3) (list x x shy 'lb x x)) (check-equal? (linewrap (list x shy shy shy shy) 1) (list x))
(check-equal? (linewrap (list x x shy x x) 4) (list x x x x)) (check-equal? (linewrap (list x x shy x x) 1) (list x 'lb x 'lb x 'lb x))
(check-equal? (linewrap (list x x shy x x) 5) (list x x x x)) (check-equal? (linewrap (list x x shy x x) 2) (list x x 'lb x x))
(check-equal? (linewrap (list x x shy x sp x) 4) (list x x x 'lb x)))) (check-equal? (linewrap (list x x shy x x) 3) (list x x shy 'lb x x))
;(check-equal? (linewrap (list x x shy x x) 4) (list x x x x))
;(check-equal? (linewrap (list x x shy x x) 5) (list x x x x))
;(check-equal? (linewrap (list x x shy x sp x) 4) (list x x x 'lb x))
))
#;(module+ test #;(module+ test
(test-case (test-case

Loading…
Cancel
Save