Skip to content

Commit

Permalink
try a little bit different organization of the helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rfindler committed Jan 5, 2025
1 parent 7c16fd3 commit 69523a0
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions drracket/drracket/private/unit.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3419,43 +3419,29 @@
(path->string (normal-case-path (normalize-path p2))))))

(define/override (make-visible filename #:start-pos [start-pos #f] #:end-pos [end-pos start-pos])
(define tab
(cond
[(path-string? filename)
(find-matching-tab filename)]
[else
;; MM-unsaved-editor
(and (symbol? filename)
(for*/first ([tab (in-list tabs)]
[ed (in-list (list (send tab get-defs) (send tab get-ints)))]
#:when (send ed port-name-matches? filename))
tab))]))
(when tab
(change-to-tab tab)
(when (and start-pos end-pos)
(define (set-the-position ed)
(when (send ed port-name-matches? filename)
(send (send ed get-canvas) focus)
(send ed set-caret-owner #f)
(send ed set-position start-pos end-pos)))
(set-the-position (send tab get-defs))
(set-the-position (send tab get-ints)))))
(match (find-matching-tab/which-editor filename)
[(cons tab ed)
(change-to-tab tab)
(when (and start-pos end-pos)
(send (send ed get-canvas) focus)
(send ed set-caret-owner #f)
(send ed set-position start-pos end-pos))]
[#f (void)]))

(define/public (find-matching-tab filename)
(define fn-path (if (string? filename)
(string->path filename)
filename))
(for/or ([tab (in-list tabs)])
(define tab-filename (send (send tab get-defs) get-filename))
(and tab-filename
(pathname-equal? fn-path tab-filename)
tab)))

(match-define (cons tab ed) (find-matching-tab/which-editor filename))
tab)

(define/override (editing-this-file? filename)
(ormap (λ (tab)
(or (send (send tab get-defs) port-name-matches? filename)
(send (send tab get-ints) port-name-matches? filename)))
tabs))
(and (find-matching-tab/which-editor filename) #t))

(define/private (find-matching-tab/which-editor filename)
(for/or ([tab (in-list tabs)])
(define (try ed)
(and (send ed port-name-matches? filename)
(cons tab ed)))
(or (try (send tab get-defs))
(try (send tab get-ints)))))

(define/override (get-all-open-files)
(filter
Expand Down

0 comments on commit 69523a0

Please sign in to comment.