Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Select to the beginning of the line" is wrong in DrRacket #2446

Closed
sorawee opened this issue Jan 6, 2019 · 2 comments
Closed

"Select to the beginning of the line" is wrong in DrRacket #2446

sorawee opened this issue Jan 6, 2019 · 2 comments

Comments

@sorawee
Copy link
Collaborator

sorawee commented Jan 6, 2019

Consider:

(define (f x)
  (+ x x)|
  (+ x x))

where | is the caret. Press shift+home. This will select (+ x x)

(define (f x)
  [(+ x x)]
  (+ x x))

then delete it via backspace or cut (ctrl-x) but not the delete key. Now, we are in this state:

(define (f x)
  |
  (+ x x))

Everything so far is as expected. However, if we shift+home again, DrRacket selects incorrectly:

(define (f x)
[  
  (+ x] x))

Note however that if we move around (e.g., press left key and then right key) first before shift+home, the selection will be correct.

(define (f x)
[  ]
  (+ x x))

Also note that the length of the deleted (+ x x) which is 7 characters matches with the length of the over-selection \n (+ x

@lexi-lambda
Copy link
Member

I’ve bumped into this bug—or at least a related bug—many times, but I’ve never taken the time to figure out exactly what steps I took to report it. Specifically, this part

Note however that if we move around (e.g., press left key and then right key) first before shift+home, the selection will be correct.

rings true for me. Something about certain sequences of move and delete actions seem to make DrRacket lose track of some piece of information, causing future actions to behave strangely, but just pressing left then right always seems to fix that strange desync.

@rfindler
Copy link
Member

This appears to be a bug in extend-position. Here's two programs that should behave the same, but don't. (I'll keep poking around here, but this seemed like a useful piece to share.)

The property is that if you do (begin (send t set-position x) (send t extend-position y)) that should be the same as (send t set-position (min x y) (max x y)) and the other code is just revealing the difference between the two. At least, I think that's a valid property.

#lang racket/gui

(define lines
  (list
   "(define (f x)\n"
   "  (+ x x)\n"
   "  (+ x x))\n"))

(define (show t label)
  (define f (new frame% [label label] [width 400] [height 200]))
  (new editor-canvas% [parent f] [editor t])
  (send f show #t))

(let ()
  (define t (new text%))

  (send t insert (apply string-append lines))
  (send t set-position
        (+ (string-length (list-ref lines 0))
           (string-length (list-ref lines 1))
           -1 ;; before the newline
           ))
  (send t extend-position
        (+ (string-length (list-ref lines 0))
           2 ;; after the leading space
           ))
  (send t cut)
  (send t extend-position (string-length (list-ref lines 0)))
  (show t "1")
  (values (send t get-start-position)
          (send t get-end-position)))

(let ()
  (define t (new text%))

  (send t insert (apply string-append lines))
  (send t set-position
        (+ (string-length (list-ref lines 0))
           2 ;; after the leading space
           )
        (+ (string-length (list-ref lines 0))
           (string-length (list-ref lines 1))
           -1 ;; before the newline
           ))
  (send t cut)
  (send t extend-position (string-length (list-ref lines 0)))
  (show t "2")
  (values (send t get-start-position)
          (send t get-end-position)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants