add 'snip-special's to text:ports<%> in the framework
related to PR 15049
This commit is contained in:
parent
f9870b0a4f
commit
469add8d57
|
@ -157,6 +157,32 @@
|
||||||
@{Returns the editor instance whose port-name matches the given symbol.
|
@{Returns the editor instance whose port-name matches the given symbol.
|
||||||
If no editor can be found, then returns @racket[false].})
|
If no editor can be found, then returns @racket[false].})
|
||||||
|
|
||||||
|
(proc-doc/names
|
||||||
|
text:make-snip-special
|
||||||
|
(-> (is-a?/c snip%) text:snip-special?)
|
||||||
|
(snip)
|
||||||
|
@{Returns a @racket[snip-special] to be used as a
|
||||||
|
@tech[#:doc '(lib "scribblings/reference/reference.scrbl")]{special}
|
||||||
|
with the ports in @racket[text:ports<%>].
|
||||||
|
|
||||||
|
When a snip is sent as a special, if it has a @racket[snip-class%]
|
||||||
|
from a different @tech[#:doc '(lib "scribblings/gui/gui.scrbl")]{eventspace},
|
||||||
|
it may not work properly
|
||||||
|
in the @racket[text%] object connected to the ports in a @racket[text:port<%>]
|
||||||
|
object. This function, when it is called, constructs the bytes
|
||||||
|
corresponding to the result of using the @racket[snip]'s
|
||||||
|
@method[snip% write] method and saves them in it's result. Then,
|
||||||
|
when the result is used as a special, the snip will rebuild from
|
||||||
|
the bytes, but now using the @racket[snip-class%] from the
|
||||||
|
@tech[#:doc '(lib "scribblings/gui/gui.scrbl")]{eventspace}
|
||||||
|
where the @racket[text:ports<%>] operates.})
|
||||||
|
|
||||||
|
(proc-doc/names
|
||||||
|
text:snip-special?
|
||||||
|
(-> any/c boolean?)
|
||||||
|
(v)
|
||||||
|
@{Recognizes the result of @racket[text:make-snip-special].})
|
||||||
|
|
||||||
(proc-doc/names
|
(proc-doc/names
|
||||||
number-snip:make-repeating-decimal-snip
|
number-snip:make-repeating-decimal-snip
|
||||||
(real? boolean? . -> . (is-a?/c snip%))
|
(real? boolean? . -> . (is-a?/c snip%))
|
||||||
|
|
|
@ -251,7 +251,10 @@
|
||||||
range-end
|
range-end
|
||||||
range-caret-space?
|
range-caret-space?
|
||||||
range-style
|
range-style
|
||||||
range-color))
|
range-color
|
||||||
|
|
||||||
|
make-snip-special
|
||||||
|
snip-special?))
|
||||||
|
|
||||||
(define-signature canvas-class^
|
(define-signature canvas-class^
|
||||||
(basic<%>
|
(basic<%>
|
||||||
|
|
|
@ -2230,6 +2230,26 @@
|
||||||
;; to do the work
|
;; to do the work
|
||||||
(define-struct data/chan (data to-insert-chan))
|
(define-struct data/chan (data to-insert-chan))
|
||||||
|
|
||||||
|
(struct snip-special (snip name bytes))
|
||||||
|
(define (make-snip-special snip)
|
||||||
|
(define base (new editor-stream-out-bytes-base%))
|
||||||
|
(define stream (make-object editor-stream-out% base))
|
||||||
|
(send snip write stream)
|
||||||
|
(snip-special snip
|
||||||
|
(send (send snip get-snipclass) get-classname)
|
||||||
|
(send base get-bytes)))
|
||||||
|
(define (snip-special->snip snip-special)
|
||||||
|
(define snipclass (send (get-the-snip-class-list) find (snip-special-name snip-special)))
|
||||||
|
(cond
|
||||||
|
[snipclass
|
||||||
|
(define base (make-object editor-stream-in-bytes-base%
|
||||||
|
(snip-special-bytes snip-special)))
|
||||||
|
(define es (make-object editor-stream-in% base))
|
||||||
|
(or (send snipclass read es)
|
||||||
|
(snip-special-snip snip-special))]
|
||||||
|
[else
|
||||||
|
(snip-special-snip snip-special)]))
|
||||||
|
|
||||||
(define ports-mixin
|
(define ports-mixin
|
||||||
(mixin (wide-snip<%>) (ports<%>)
|
(mixin (wide-snip<%>) (ports<%>)
|
||||||
(inherit begin-edit-sequence
|
(inherit begin-edit-sequence
|
||||||
|
@ -2578,55 +2598,59 @@
|
||||||
;; do-insertion : (listof (cons (union string snip) style-delta)) boolean -> void
|
;; do-insertion : (listof (cons (union string snip) style-delta)) boolean -> void
|
||||||
;; thread: eventspace main thread
|
;; thread: eventspace main thread
|
||||||
(define/private (do-insertion txts showing-input?)
|
(define/private (do-insertion txts showing-input?)
|
||||||
(let ([locked? (is-locked?)]
|
(define locked? (is-locked?))
|
||||||
[sf? (get-styles-fixed)])
|
(define sf? (get-styles-fixed))
|
||||||
(begin-edit-sequence)
|
(begin-edit-sequence)
|
||||||
(lock #f)
|
(lock #f)
|
||||||
(set-styles-fixed #f)
|
(set-styles-fixed #f)
|
||||||
(set! allow-edits? #t)
|
(set! allow-edits? #t)
|
||||||
(let loop ([txts txts])
|
(let loop ([txts txts])
|
||||||
(cond
|
(cond
|
||||||
[(null? txts) (void)]
|
[(null? txts) (void)]
|
||||||
[else
|
[else
|
||||||
(let* ([fst (car txts)]
|
(define fst (car txts))
|
||||||
[str/snp (car fst)]
|
(define str/snp
|
||||||
[style (cdr fst)])
|
(cond
|
||||||
|
[(snip-special? (car fst))
|
||||||
(let ([inserted-count
|
(snip-special->snip (car fst))]
|
||||||
(if (is-a? str/snp snip%)
|
[else (car fst)]))
|
||||||
(send str/snp get-count)
|
(define style (cdr fst))
|
||||||
(string-length str/snp))]
|
|
||||||
[old-insertion-point insertion-point])
|
(define inserted-count
|
||||||
(set! insertion-point (+ insertion-point inserted-count))
|
(if (is-a? str/snp snip%)
|
||||||
(set! unread-start-point (+ unread-start-point inserted-count))
|
(send str/snp get-count)
|
||||||
|
(string-length str/snp)))
|
||||||
(insert (if (is-a? str/snp snip%)
|
(define old-insertion-point insertion-point)
|
||||||
(let ([s (send str/snp copy)])
|
(set! insertion-point (+ insertion-point inserted-count))
|
||||||
(if (is-a? s snip%)
|
(set! unread-start-point (+ unread-start-point inserted-count))
|
||||||
s
|
|
||||||
(new snip%)))
|
(insert (if (is-a? str/snp snip%)
|
||||||
str/snp)
|
(let ([s (send str/snp copy)])
|
||||||
old-insertion-point
|
(if (is-a? s snip%)
|
||||||
old-insertion-point
|
s
|
||||||
#t)
|
(new snip%)))
|
||||||
|
str/snp)
|
||||||
;; the idea here is that if you made a string snip, you
|
old-insertion-point
|
||||||
;; could have made a string and gotten the style, so you
|
old-insertion-point
|
||||||
;; must intend to have your own style.
|
#t)
|
||||||
(unless (is-a? str/snp string-snip%)
|
|
||||||
(change-style style old-insertion-point insertion-point))))
|
;; the idea here is that if you made a string snip, you
|
||||||
(loop (cdr txts))]))
|
;; could have made a string and gotten the style, so you
|
||||||
(set-styles-fixed sf?)
|
;; must intend to have your own style.
|
||||||
(set! allow-edits? #f)
|
(unless (is-a? str/snp string-snip%)
|
||||||
(lock locked?)
|
(change-style style old-insertion-point insertion-point))
|
||||||
(unless showing-input?
|
(loop (cdr txts))]))
|
||||||
(when box-input
|
(set-styles-fixed sf?)
|
||||||
(adjust-box-input-width)
|
(set! allow-edits? #f)
|
||||||
(when (eq? box-input (get-focus-snip))
|
(lock locked?)
|
||||||
(scroll-to-position (last-position)))))
|
(unless showing-input?
|
||||||
(end-edit-sequence)
|
(when box-input
|
||||||
(unless (null? txts)
|
(adjust-box-input-width)
|
||||||
(after-io-insertion))))
|
(when (eq? box-input (get-focus-snip))
|
||||||
|
(scroll-to-position (last-position)))))
|
||||||
|
(end-edit-sequence)
|
||||||
|
(unless (null? txts)
|
||||||
|
(after-io-insertion)))
|
||||||
|
|
||||||
(define/public (after-io-insertion) (void))
|
(define/public (after-io-insertion) (void))
|
||||||
|
|
||||||
|
@ -2762,6 +2786,7 @@
|
||||||
(λ (special can-buffer? enable-breaks?)
|
(λ (special can-buffer? enable-breaks?)
|
||||||
(define str/snp (cond
|
(define str/snp (cond
|
||||||
[(string? special) special]
|
[(string? special) special]
|
||||||
|
[(snip-special? special) special]
|
||||||
[(is-a? special snip%) special]
|
[(is-a? special snip%) special]
|
||||||
[else (format "~s" special)]))
|
[else (format "~s" special)]))
|
||||||
(define to-send (cons str/snp style))
|
(define to-send (cons str/snp style))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user