|
216 | 216 | (mixin (text:basic<%>) (ml-tools-text<%>) |
217 | 217 | (inherit position-paragraph paragraph-start-position |
218 | 218 | delete insert |
| 219 | + set-position paragraph-end-position get-character |
219 | 220 | begin-edit-sequence end-edit-sequence) |
220 | 221 | (define/public (range-indent range-indentation-function start end) |
221 | 222 | (define substs (range-indentation-function this start end)) |
|
227 | 228 | (let loop ([substs substs] [line start-line]) |
228 | 229 | (unless (or (null? substs) |
229 | 230 | (line . > . end-line)) |
230 | | - (define pos (paragraph-start-position line)) |
| 231 | + (define para-start-pos (paragraph-start-position line)) |
231 | 232 | (define del-amt (caar substs)) |
232 | 233 | (define insert-str (cadar substs)) |
| 234 | + (define in-whitespace-before-edit? |
| 235 | + (cond |
| 236 | + [(= start end) |
| 237 | + (define para-end (paragraph-end-position start-line)) |
| 238 | + (let loop ([pos para-start-pos]) |
| 239 | + (cond |
| 240 | + [(< pos para-end) |
| 241 | + (define c (get-character pos)) |
| 242 | + (cond |
| 243 | + [(char-whitespace? c) (loop (+ pos 1))] |
| 244 | + [else |
| 245 | + (<= para-start-pos start pos)])] |
| 246 | + [else #f]))] |
| 247 | + [else #f])) |
233 | 248 | (unless (zero? del-amt) |
234 | | - (delete pos (+ pos del-amt))) |
| 249 | + (delete para-start-pos (+ para-start-pos del-amt))) |
235 | 250 | (unless (equal? insert-str "") |
236 | | - (insert insert-str pos)) |
| 251 | + (insert insert-str para-start-pos)) |
| 252 | + (when (and (= start end) |
| 253 | + in-whitespace-before-edit?) |
| 254 | + (define para-end (paragraph-end-position start-line)) |
| 255 | + (let loop ([pos para-start-pos]) |
| 256 | + (cond |
| 257 | + [(< pos para-end) |
| 258 | + (define c (get-character pos)) |
| 259 | + (cond |
| 260 | + [(char-whitespace? c) (loop (+ pos 1))] |
| 261 | + [else (set-position pos pos)])] |
| 262 | + [else (void)]))) |
237 | 263 | (loop (cdr substs) (add1 line)))) |
238 | 264 | (end-edit-sequence) |
239 | 265 | #t))) |
|
0 commit comments