Re: [racket-users] Strange behavior with highlight-range method from framework

2016-02-23 Thread Robby Findler
I think there are two things going on here. The first: when you type
"(define (f x)" and highlight between the parens and then type a
space, you are asking it to highlight "(f x) " and then you hit
return, you are asking for "(f x) \n" to be circled, and same with any
other characters you type. This is probably not what you want, given
the context you explained.

The second issue is that highlighting of ellipses may not be what you
want when text spans multiple lines. I'm not sure, but maybe this
snippet of code would help at least point out the issue

(send text-editor insert "abc\ndef\nghi")
(send text-editor highlight-range 2
  (- (send text-editor last-position) 2) "blue" #f 'low 'hollow-ellipse)
(send text-editor highlight-range 2
  (- (send text-editor last-position) 2) "lightblue")

That second issue is why you get the "jump down" behavior you describe.

I'm not sure of the best way to achieve these goals, but it might be
to add extra observers in color:text% to tell when the paren structure
of the buffer changes and then update the parens based on that,
without using #:adjust-on-insert/delete?.

Regardless, I'm pretty sure that using #:adjust-on-insert/delete?
isn't helpful here. Consider the case where someone types "(aa)" and
then uses the left arrow to type a paren between the two "a"s. Or,
even worse, where you have a lot of parens and strings then someone
types an open double quote somewhere in the middle of it all. The
colorer already tracks the paren structure for such things and so you
want to piggy back on that.

hth,
Robby

On Mon, Feb 22, 2016 at 11:30 PM, Alex Knauth  wrote:
> Hello,
>
> I'm trying to figure out how I would make a text editor or a DrRacket
> extension that circled nested s-expressions instead of displaying the
> parentheses. DrRacket circles text for the find/replace feature, so I looked
> at that and found that it uses the highlight-range method of text:basic<%>
> in framework.
>
> However, when I tried using it with the #:adjust-on-insert/delete argument
> as #true, I got strange behavior with my little toy editor.
>
> When I start typing something like "(define (f x)", it circles the (f x)
> like I expected. However, when I continue typing, that's when I get the
> weird behavior. For example, if I type a return, the beginning of the circle
> jumps backwards to the "(define", and the end of the circle jumps down with
> the cursor. Then if I press delete after more typing, that circle disappears
> and is replaced by a narrow ellipse that just follows my cursor around. This
> weird behavior goes away when the #:adjust-on-insert/delete argument is
> #false.
>
> Is there a way to stay on the positions of the open and close parentheses
> without jumping backwards or collapsing and following the cursor? To do
> that, it needs to shift positions when I insert or delete characters, but is
> there a way to tell it to stay where it is if I insert something right after
> the close parenthesis?
>
> #lang racket/base
>
> (require racket/class racket/gui/base framework)
>
> (define frame
>   (new frame% [label "circledit"] [width 500] [height 500]))
>
> (define text-editor
>   (new (class racket:text%
>  (super-new)
>  (inherit get-start-position get-backward-seep)
>  ;; when an s-expr is closed, this method will be called
>  (define/override (balance-parens key-event)
>(super balance-parens key-event)
>;; and it will circle the s-expr that was just closed
>(define end
>  (get-start-position))
>(define start
>  (get-backward-sexp end))
>(when start
>  (send text-editor highlight-range
>start end "dark green" #f 'low 'hollow-ellipse
>#:adjust-on-insert/delete? #t))
>
> (define canvas
>   (new editor-canvas% [parent frame] [editor text-editor]))
>
> (send frame show #true)
>
> Alex Knauth
>
> --
> 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.

-- 
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.


[racket-users] Strange behavior with highlight-range method from framework

2016-02-22 Thread Alex Knauth
Hello,

I'm trying to figure out how I would make a text editor or a DrRacket extension 
that circled nested s-expressions instead of displaying the parentheses. 
DrRacket circles text for the find/replace feature, so I looked at that and 
found that it uses the highlight-range method of text:basic<%> in framework.

However, when I tried using it with the #:adjust-on-insert/delete argument as 
#true, I got strange behavior with my little toy editor. 

When I start typing something like "(define (f x)", it circles the (f x) like I 
expected. However, when I continue typing, that's when I get the weird 
behavior. For example, if I type a return, the beginning of the circle jumps 
backwards to the "(define", and the end of the circle jumps down with the 
cursor. Then if I press delete after more typing, that circle disappears and is 
replaced by a narrow ellipse that just follows my cursor around. This weird 
behavior goes away when the #:adjust-on-insert/delete argument is #false.

Is there a way to stay on the positions of the open and close parentheses 
without jumping backwards or collapsing and following the cursor? To do that, 
it needs to shift positions when I insert or delete characters, but is there a 
way to tell it to stay where it is if I insert something right after the close 
parenthesis?

#lang racket/base

(require racket/class racket/gui/base framework)

(define frame
  (new frame% [label "circledit"] [width 500] [height 500]))

(define text-editor
  (new (class racket:text%
 (super-new)
 (inherit get-start-position get-backward-seep)
 ;; when an s-expr is closed, this method will be called
 (define/override (balance-parens key-event)
   (super balance-parens key-event)
   ;; and it will circle the s-expr that was just closed
   (define end
 (get-start-position))
   (define start
 (get-backward-sexp end))
   (when start
 (send text-editor highlight-range
   start end "dark green" #f 'low 'hollow-ellipse 
   #:adjust-on-insert/delete? #t))

(define canvas
  (new editor-canvas% [parent frame] [editor text-editor]))

(send frame show #true)

Alex Knauth

-- 
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.