correct insertion of spaces at the beginning of a line and indent first line in para too, after all

This commit is contained in:
Robby Findler 2016-08-25 08:36:57 -05:00
parent 0ae0a5b804
commit 01c665e6e9

View File

@ -87,11 +87,22 @@
;; reindent at newly inserted newlines ;; reindent at newly inserted newlines
(let ([end-para (send txt position-paragraph new-new-end-position)]) (let ([end-para (send txt position-paragraph new-new-end-position)])
(let loop ([para (+ (send txt position-paragraph start-position) 1)]) (let loop ([para (send txt position-paragraph start-position)])
(when (<= para end-para) (when (<= para end-para)
(define sp (send txt paragraph-start-position para)) (define sp (send txt paragraph-start-position para))
(define ep (send txt paragraph-end-position para))
(define s (determine-spaces txt sp)) (define s (determine-spaces txt sp))
(when s (send txt insert (make-string s #\space) sp sp)) (when s
(define to-delete
(let loop ([pos sp]
[amt 0])
(cond
[(= pos ep) amt]
[(char-whitespace? (send txt get-character pos))
(loop (+ pos 1) (+ amt 1))]
[else amt])))
(send txt delete sp (+ sp to-delete))
(send txt insert (make-string s #\space) sp sp))
(loop (+ para 1))))) (loop (+ para 1)))))
(send txt end-edit-sequence))) (send txt end-edit-sequence)))
@ -1010,6 +1021,17 @@
"lorem ipsum hello world lorem ipsum hi world lorem ipsum\n" "lorem ipsum hello world lorem ipsum hi world lorem ipsum\n"
"hello world lorem ipsum hello world lorem ipsum hello\n")) "hello world lorem ipsum hello world lorem ipsum hello\n"))
(check-equal? (let ([t (new racket:text%)])
(send t insert "#lang scribble/base\n")
(send t insert "\n")
(send t insert " aa bb cc\n")
(paragraph-indentation t 23 60)
(send t get-text))
(string-append
"#lang scribble/base\n"
"\n"
"aa bb cc\n"))
(check-equal? (let ([t (new racket:text%)]) (check-equal? (let ([t (new racket:text%)])
(send t insert "#lang scribble/base\n@a{b\n } \n") (send t insert "#lang scribble/base\n@a{b\n } \n")
(determine-spaces t 26)) (determine-spaces t 26))