[plt-scheme] editor lockup in embedded editor-snip%

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Fri Aug 21 08:02:09 EDT 2009

Here is a 20 line problem that seems to indicate the bug is in the
show method of the vertical-alignment% class. Probably worth
submitting a PR now that the program is a manageable size.

hth,
Robby

#lang scheme/gui
(require embedded-gui)
(define f (new frame% [label ""][width 200] [height 200]))
(define pb (new aligned-pasteboard%))
(define ec2 (new editor-canvas% [parent f] [editor pb]))
(define code-editor (new text%))  ;; code box's editor
(define val (new vertical-alignment% [parent pb]))
(define code-view (new vertical-alignment%
                       [parent val]
                       [show? #t]))
(define code-snip (new stretchable-editor-snip%
                       [editor code-editor]
                       [with-border? #t]
                       [min-width 100]))
(make-object snip-wrapper% code-view code-snip)

(send code-view show #f) (send code-view show #t)

(send f show #t)


On Fri, Aug 21, 2009 at 3:49 AM, Jordan Johnson<jmj at fellowhuman.com> wrote:
> OK -- yeah, I didn't want to send out the whole thing unless needed, but
> here is a link to a version I've winnowed down to about half the program
> size, but that still exercises the bug:
>        http://www.fellowhuman.com/scheme/annotated-snip/
>
> I've been reproducing it by
>        1) putting the annotated-snip/ dir in my library path
>        2) "setup-plt'ing" it.
>        3) running DrScheme (using current nightly build,
> 4.2.1.7-svn20aug2009)
>        4) Insert menu -> Insert Annotated Code Box
>        5) right-click the code box's bitmap -> Hide program text
>        6) right-click the code box's bitmap -> Show program text
>
> ...after which I can no longer type into the snip's upper text editor.
>  (Yes, since my original post I've noticed in playing around further that it
> isn't even necessary to click "Run" to exercise this bug; merely hiding and
> showing the editor suffices.)
>
> Once again, many thanks for your time.
>
> Best,
> jmj
>
> On Aug 20, 2009, at 6:01 PM, Robby Findler wrote:
>
>> That code by itself isn't enough for me to see what's wrong and you
>> could certainly be running across a bug elsewhere in the system. The
>> most useful thing would be a (small!) program that illustrated the
>> problem, but if you can't seem to narrow down, send along what you've
>> got and I'll have a look.
>>
>> Robby
>>
>> On Thu, Aug 20, 2009 at 1:37 PM, Jordan Johnson<jmj at fellowhuman.com>
>> wrote:
>>>
>>> Hi all,
>>>
>>> The annotated-code snip I've been working on is now working (thanks in
>>> large
>>> part to help from Matthew & Robby), with the exception of one bug that
>>> has
>>> me baffled.  I suspect it involves the locking that happens in
>>> embedded-gui/aligned-pasteboard.
>>>
>>> The bug:  If I have a snip in the Definitions editor and click "Run"
>>> while
>>> the snip's code-view (defined below) is hidden, it becomes impossible to
>>> edit the text in the code-editor (also defined below).  By this I mean
>>> that
>>> when I click or tab into the code editor, the cursor does not appear, and
>>> typing has no effect.  Further, this only happens when the editor is not
>>> visible.
>>>
>>> Here is the relevant code:
>>>
>>> ;;;;;;;;;
>>> ;; anno-snip% is my snip's class.
>>>
>>> ;; code-editor is an instance of a subclass of
>>> ;;  ((drscheme:unit:get-program-editor-mixin) (tabbable-text-mixin
>>> scheme:text%))
>>> ;; that caches the result of (scheme:text-balanced? this) for display
>>> purposes.
>>>
>>> ;; anno-editor is an instance of (tabbable-text-mixin scheme:text%).
>>>
>>> ;; The following is from the definition of a subclass of
>>> ;; aligned-pasteboard% that is the editor for an anno-snip%:
>>>
>>>     (set-tabbing code-editor anno-editor)
>>>
>>>     ;;;;;;; Container snips for the two editors:
>>>     (define val (new vertical-alignment% [parent this]))
>>>     ;; Container for the code editor.  I'm using this for the ability to
>>>     ;; show/hide the editor:
>>>     (define code-view (new vertical-alignment%
>>>                            [parent val]
>>>                            [show? #f]))
>>>
>>>     ;; Installs stretchable editor snips, if none are already installed,
>>>     ;; to contain the code and anno editors.
>>>     ;; (Does nothing if they already are installed, and returns #f.)
>>>     ;; Returns #t if successful.
>>>     (define (init-snips)
>>>       (if (not (or (find-owner-snip code-editor)
>>>                    (find-owner-snip anno-editor)))
>>>           (let ([code-snip (new stretchable-editor-snip%
>>>                                 [editor code-editor]
>>>                                 [with-border? #t]
>>>                                 [min-width MIN-TEXT-WIDTH])]
>>>                 [anno-snip (new stretchable-editor-snip%
>>>                                 [editor anno-editor]
>>>                                 [with-border? #f]
>>>                                 [min-width MIN-TEXT-WIDTH])])
>>>             (make-object snip-wrapper% code-view code-snip)
>>>             (make-object hline% code-view)
>>>             (make-object snip-wrapper% val anno-snip)
>>>             #t)
>>>           #f))
>>>
>>>     (init-snips)
>>>
>>>     ;;;;;;;;; Interface for showing/hiding code ;;;;;;;;;
>>>     (define showing-code #f)
>>>
>>>     (define/public (showing-code?)
>>>       showing-code)
>>>     (define/public (show-code on/off)
>>>       (send code-view show on/off)
>>>       (set! showing-code on/off))
>>>
>>> ;;;;;;;;; end of program excerpt.
>>>
>>> I have verified that the code-editor is *not* locked for writing,
>>> reflowing,
>>> or reading.  Having looked at snip-wrapper.ss and aligned-pasteboard.ss
>>> in
>>> embedded-gui/private/, I am guessing something in the code-editor's or
>>> code-snip's state isn't getting properly restored when it is reinserted
>>> by
>>> show/hide (in snip-wrapper.ss), but I don't know what that piece of state
>>> would be.  Any pointers?
>>>
>>> Oh, and here's an extra question that may be related:  How can I give the
>>> caret to the code editor upon calling (show-code true)?  Calling
>>> set-caret-owner on the code-snip's snip-admin doesn't seem to work.
>>>
>>> Thanks again for your help.
>>>
>>> Best,
>>> jmj
>>>
>>> _________________________________________________
>>>  For list-related administrative tasks:
>>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>>
>
>


Posted on the users mailing list.