From 6a69da76e2f9e5b2105dee89535d5ace4defed92 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Mon, 24 Dec 2012 13:49:32 -0600 Subject: [PATCH] adjust ascii-box => unicode-box algorithm so that it only looks left and right at hyphens and only up and down at pipes, etc. This better handles the case where you have something like this: +--------------+ | (<= a-x b-y) | +--------------+ Before this commit, it would have adjusted the hypens inside the identifiers --- collects/framework/private/keymap.rkt | 44 +++++++++++++++++++++------ collects/tests/framework/keys.rkt | 8 +++++ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/collects/framework/private/keymap.rkt b/collects/framework/private/keymap.rkt index f628a41ffa..8ebefc5457 100644 --- a/collects/framework/private/keymap.rkt +++ b/collects/framework/private/keymap.rkt @@ -1499,14 +1499,15 @@ (unless (hash-ref visited pos #f) (hash-set! visited pos #t) (define-values (x y) (pos->xy t pos)) + (define c (send t get-character pos)) (define up (xy->pos t x (- y 1))) (define dn (xy->pos t x (+ y 1))) (define lt (xy->pos t (- x 1) y)) (define rt (xy->pos t (+ x 1) y)) - (define i-up? (i? t up)) - (define i-dn? (i? t dn)) - (define i-lt? (i? t lt)) - (define i-rt? (i? t rt)) + (define i-up? (and (i? t up) (member c up-chars))) + (define i-dn? (and (i? t dn) (member c dn-chars))) + (define i-lt? (and (i? t lt) (member c lt-chars))) + (define i-rt? (and (i? t rt) (member c rt-chars))) (cond [(and i-up? i-dn? i-lt? i-rt?) (set t pos "╬")] [(and i-dn? i-lt? i-rt?) (set t pos "╦")] @@ -1539,12 +1540,37 @@ (define start (send text paragraph-start-position para)) (values (- pos start) para)) -(define adjustable-chars +(define up-chars '(#\╬ - #\╩ #\╦ #\╣ #\╠ - #\╝ #\╗ #\╔ #\╚ - #\═ #\║ - #\+ #\- #\|)) + #\╩ #\╣ #\╠ + #\╝ #\╚ + #\║ + #\+ #\|)) + +(define dn-chars + '(#\╬ + #\╦ #\╣ #\╠ + #\╗ #\╔ + #\║ + #\+ #\|)) + +(define lt-chars + '(#\╬ + #\╩ #\╦ #\╣ + #\╝ #\╗ + #\═ + #\+ #\-)) + +(define rt-chars + '(#\╬ + #\╩ #\╦ #\╠ + #\╔ #\╚ + #\═ + #\+ #\-)) + +(define adjustable-chars + (remove-duplicates + (append up-chars dn-chars lt-chars rt-chars))) (define (xy->pos text x y) diff --git a/collects/tests/framework/keys.rkt b/collects/tests/framework/keys.rkt index 0dd91a0958..2e85908586 100644 --- a/collects/tests/framework/keys.rkt +++ b/collects/tests/framework/keys.rkt @@ -290,6 +290,14 @@ (string-append "╔═╗\n" "║ ║\n" "╚═╝\n")) + (ascii-art-box-spec (string-append "+---+\n" + "| - |\n" + "|+ ||\n" + "+---+\n") + (string-append "╔═══╗\n" + "║ - ║\n" + "║+ |║\n" + "╚═══╝\n")) (ascii-art-box-spec (string-append "+-+-+\n" "| | |\n" "+-+-+\n"