|
2230 | 2230 | ;; to do the work |
2231 | 2231 | (define-struct data/chan (data to-insert-chan)) |
2232 | 2232 |
|
| 2233 | + (struct snip-special (snip name bytes)) |
| 2234 | + (define (make-snip-special snip) |
| 2235 | + (define base (new editor-stream-out-bytes-base%)) |
| 2236 | + (define stream (make-object editor-stream-out% base)) |
| 2237 | + (send snip write stream) |
| 2238 | + (snip-special snip |
| 2239 | + (send (send snip get-snipclass) get-classname) |
| 2240 | + (send base get-bytes))) |
| 2241 | + (define (snip-special->snip snip-special) |
| 2242 | + (define snipclass (send (get-the-snip-class-list) find (snip-special-name snip-special))) |
| 2243 | + (cond |
| 2244 | + [snipclass |
| 2245 | + (define base (make-object editor-stream-in-bytes-base% |
| 2246 | + (snip-special-bytes snip-special))) |
| 2247 | + (define es (make-object editor-stream-in% base)) |
| 2248 | + (or (send snipclass read es) |
| 2249 | + (snip-special-snip snip-special))] |
| 2250 | + [else |
| 2251 | + (snip-special-snip snip-special)])) |
| 2252 | + |
2233 | 2253 | (define ports-mixin |
2234 | 2254 | (mixin (wide-snip<%>) (ports<%>) |
2235 | 2255 | (inherit begin-edit-sequence |
|
2578 | 2598 | ;; do-insertion : (listof (cons (union string snip) style-delta)) boolean -> void |
2579 | 2599 | ;; thread: eventspace main thread |
2580 | 2600 | (define/private (do-insertion txts showing-input?) |
2581 | | - (let ([locked? (is-locked?)] |
2582 | | - [sf? (get-styles-fixed)]) |
2583 | | - (begin-edit-sequence) |
2584 | | - (lock #f) |
2585 | | - (set-styles-fixed #f) |
2586 | | - (set! allow-edits? #t) |
2587 | | - (let loop ([txts txts]) |
2588 | | - (cond |
2589 | | - [(null? txts) (void)] |
2590 | | - [else |
2591 | | - (let* ([fst (car txts)] |
2592 | | - [str/snp (car fst)] |
2593 | | - [style (cdr fst)]) |
2594 | | - |
2595 | | - (let ([inserted-count |
2596 | | - (if (is-a? str/snp snip%) |
2597 | | - (send str/snp get-count) |
2598 | | - (string-length str/snp))] |
2599 | | - [old-insertion-point insertion-point]) |
2600 | | - (set! insertion-point (+ insertion-point inserted-count)) |
2601 | | - (set! unread-start-point (+ unread-start-point inserted-count)) |
2602 | | - |
2603 | | - (insert (if (is-a? str/snp snip%) |
2604 | | - (let ([s (send str/snp copy)]) |
2605 | | - (if (is-a? s snip%) |
2606 | | - s |
2607 | | - (new snip%))) |
2608 | | - str/snp) |
2609 | | - old-insertion-point |
2610 | | - old-insertion-point |
2611 | | - #t) |
2612 | | - |
2613 | | - ;; the idea here is that if you made a string snip, you |
2614 | | - ;; could have made a string and gotten the style, so you |
2615 | | - ;; must intend to have your own style. |
2616 | | - (unless (is-a? str/snp string-snip%) |
2617 | | - (change-style style old-insertion-point insertion-point)))) |
2618 | | - (loop (cdr txts))])) |
2619 | | - (set-styles-fixed sf?) |
2620 | | - (set! allow-edits? #f) |
2621 | | - (lock locked?) |
2622 | | - (unless showing-input? |
2623 | | - (when box-input |
2624 | | - (adjust-box-input-width) |
2625 | | - (when (eq? box-input (get-focus-snip)) |
2626 | | - (scroll-to-position (last-position))))) |
2627 | | - (end-edit-sequence) |
2628 | | - (unless (null? txts) |
2629 | | - (after-io-insertion)))) |
| 2601 | + (define locked? (is-locked?)) |
| 2602 | + (define sf? (get-styles-fixed)) |
| 2603 | + (begin-edit-sequence) |
| 2604 | + (lock #f) |
| 2605 | + (set-styles-fixed #f) |
| 2606 | + (set! allow-edits? #t) |
| 2607 | + (let loop ([txts txts]) |
| 2608 | + (cond |
| 2609 | + [(null? txts) (void)] |
| 2610 | + [else |
| 2611 | + (define fst (car txts)) |
| 2612 | + (define str/snp |
| 2613 | + (cond |
| 2614 | + [(snip-special? (car fst)) |
| 2615 | + (snip-special->snip (car fst))] |
| 2616 | + [else (car fst)])) |
| 2617 | + (define style (cdr fst)) |
| 2618 | + |
| 2619 | + (define inserted-count |
| 2620 | + (if (is-a? str/snp snip%) |
| 2621 | + (send str/snp get-count) |
| 2622 | + (string-length str/snp))) |
| 2623 | + (define old-insertion-point insertion-point) |
| 2624 | + (set! insertion-point (+ insertion-point inserted-count)) |
| 2625 | + (set! unread-start-point (+ unread-start-point inserted-count)) |
| 2626 | + |
| 2627 | + (insert (if (is-a? str/snp snip%) |
| 2628 | + (let ([s (send str/snp copy)]) |
| 2629 | + (if (is-a? s snip%) |
| 2630 | + s |
| 2631 | + (new snip%))) |
| 2632 | + str/snp) |
| 2633 | + old-insertion-point |
| 2634 | + old-insertion-point |
| 2635 | + #t) |
| 2636 | + |
| 2637 | + ;; the idea here is that if you made a string snip, you |
| 2638 | + ;; could have made a string and gotten the style, so you |
| 2639 | + ;; must intend to have your own style. |
| 2640 | + (unless (is-a? str/snp string-snip%) |
| 2641 | + (change-style style old-insertion-point insertion-point)) |
| 2642 | + (loop (cdr txts))])) |
| 2643 | + (set-styles-fixed sf?) |
| 2644 | + (set! allow-edits? #f) |
| 2645 | + (lock locked?) |
| 2646 | + (unless showing-input? |
| 2647 | + (when box-input |
| 2648 | + (adjust-box-input-width) |
| 2649 | + (when (eq? box-input (get-focus-snip)) |
| 2650 | + (scroll-to-position (last-position))))) |
| 2651 | + (end-edit-sequence) |
| 2652 | + (unless (null? txts) |
| 2653 | + (after-io-insertion))) |
2630 | 2654 |
|
2631 | 2655 | (define/public (after-io-insertion) (void)) |
2632 | 2656 |
|
|
2762 | 2786 | (λ (special can-buffer? enable-breaks?) |
2763 | 2787 | (define str/snp (cond |
2764 | 2788 | [(string? special) special] |
| 2789 | + [(snip-special? special) special] |
2765 | 2790 | [(is-a? special snip%) special] |
2766 | 2791 | [else (format "~s" special)])) |
2767 | 2792 | (define to-send (cons str/snp style)) |
|
0 commit comments