That will work for newly typed text. Other code might changed the style and
copying and pasting styled text may change it. You can use after-insert to
change the style for those cases. Or maybe you want to allow that.

There is also, in the framework, editor:standard-style-list which uses a
global style list and drracket mutates its "Stabdard" style for font
selection and sizes and whatnot.

Robby

On Monday, October 12, 2015, David T. Pierson <d...@mindstory.com> wrote:

> I have a text% instance for which I want to optionally set the default
> style (font face and size).  I want it to persist even if all text
> within the editor is erased.  (My first attempt using the change-style
> method failed this requirement.)  I've come up with the following, but
> is this the simplest/best way?
>
> ;; editor: (is-a/c text%)
> ;; face: (or/c string? #f)
> ;; size: (or/c real? #f)
> (define (set-default-style editor face size)
>   (when (or face size)
>     (define (make-delta)
>       (define delta (make-object racket:style-delta%))
>       (when face
>         (send delta set-face face))
>       (when size
>         (send delta set-delta 'change-size size))
>       delta)
>     (define style-list (send editor get-style-list))
>     (define root-style (send style-list basic-style))
>     (define new-default (send style-list find-or-create-style root-style
> (make-delta)))
>     (send style-list replace-named-style "Standard" new-default)))
>
> Thanks.
>
> David
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com <javascript:;>.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to