Skip to content

Commit f165919

Browse files
committed
improve position adjustment after hitting tab
Specifically, after indentation, if move the insertion point to the first nonwhitespace on the line (in the case that there is an insertion point instead of a selection), when the insertion point was already in the whitespace at the start of the line
1 parent 45baccf commit f165919

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

drracket-core-lib/drracket/private/module-language-tools.rkt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
(mixin (text:basic<%>) (ml-tools-text<%>)
217217
(inherit position-paragraph paragraph-start-position
218218
delete insert
219+
set-position paragraph-end-position get-character
219220
begin-edit-sequence end-edit-sequence)
220221
(define/public (range-indent range-indentation-function start end)
221222
(define substs (range-indentation-function this start end))
@@ -227,13 +228,38 @@
227228
(let loop ([substs substs] [line start-line])
228229
(unless (or (null? substs)
229230
(line . > . end-line))
230-
(define pos (paragraph-start-position line))
231+
(define para-start-pos (paragraph-start-position line))
231232
(define del-amt (caar substs))
232233
(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]))
233248
(unless (zero? del-amt)
234-
(delete pos (+ pos del-amt)))
249+
(delete para-start-pos (+ para-start-pos del-amt)))
235250
(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)])))
237263
(loop (cdr substs) (add1 line))))
238264
(end-edit-sequence)
239265
#t)))

0 commit comments

Comments
 (0)