From 1c2432e65443166b5094138e86c3ebbdfc0c888d Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Sun, 17 Feb 2013 20:09:09 -0600 Subject: [PATCH] improve the interactions history window a little --- collects/drracket/private/rep.rkt | 41 ++++++++++++++++++- .../scribblings/drracket/keybindings.scrbl | 1 + 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/collects/drracket/private/rep.rkt b/collects/drracket/private/rep.rkt index bc1407e19e..9f4d804aad 100644 --- a/collects/drracket/private/rep.rkt +++ b/collects/drracket/private/rep.rkt @@ -21,6 +21,7 @@ TODO racket/unit racket/list racket/port + racket/set string-constants setup/xref @@ -1818,10 +1819,13 @@ TODO [label (string-constant drscheme)] [width 600] [height 600])) - (define t (new racket:text%)) + (define t (new (draw-lines-mixin (text:hide-caret/selection-mixin racket:text%)))) (define ec (new editor-canvas% [parent (send f get-area-container)] [editor t])) - (for ([prev-expr (in-list (get-previous-exprs))]) + (for ([prev-expr (in-list (get-previous-exprs))] + [i (in-naturals)]) (define lp (send t last-position)) + (unless (zero? i) + (send t draw-along-line (- (send t position-paragraph lp) 1))) (for ([snip/string (in-list prev-expr)]) (send t insert (if (string? snip/string) @@ -1830,7 +1834,13 @@ TODO lp lp)) (let ([lp (send t last-position)]) (unless (equal? (send t get-character lp) #\newline) + (send t insert #\newline lp lp)) + (unless (equal? (send t get-character (- lp 1)) #\newline) (send t insert #\newline lp lp)))) + (send t delete (- (send t last-position) 2) (send t last-position)) + (send t set-position (send t paragraph-start-position (send t last-paragraph))) + (send t hide-caret #t) + (send t lock #t) (send f show #t)) ;; private fields @@ -2129,6 +2139,33 @@ TODO (text:normalize-paste-mixin text:clever-file-format%)))))))))))))) +(define (draw-lines-mixin text%) + (class text% + (define line-paras (set)) + (define/public (draw-along-line para) + (set! line-paras (set-add line-paras para))) + (inherit paragraph-start-position + paragraph-end-position + position-locations) + (define ty (box 0.0)) + (define by (box 0.0)) + (define/override (on-paint before? dc left top right bottom dx dy draw-caret) + (unless before? + (define pen (send dc get-pen)) + (for ([para (in-set line-paras)]) + (define sp (paragraph-start-position para)) + (define ep (paragraph-end-position para)) + (position-locations sp #f ty #f by) + (define y (/ (+ (unbox ty) (unbox by)) 2)) + (send dc set-pen "Lavender" (/ (- (unbox by) (unbox ty)) 3.0) 'solid) + (send dc draw-line + (+ dx left) + (+ dy y) + (+ dx right) + (+ dy y)))) + (super on-paint before? dc left top right bottom dx dy draw-caret)) + (super-new))) + (define (simplify-history-element s all-to-strings?) (cond [(null? s) '("")] diff --git a/collects/scribblings/drracket/keybindings.scrbl b/collects/scribblings/drracket/keybindings.scrbl index 1cb045b26a..7e894f3c8f 100644 --- a/collects/scribblings/drracket/keybindings.scrbl +++ b/collects/scribblings/drracket/keybindings.scrbl @@ -209,6 +209,7 @@ as the @tech{definitions window} plus a few more: @keybinding["M-p"]{bring the previously entered expression down to the prompt} @keybinding["M-n"]{bring the expression after the current expression in the expression history down to the prompt} +@keybinding["M-h"]{Show the current expression history in a separate window} ] @section{LaTeX and TeX inspired keybindings}