From 9a508a8f443d7297cb53a57b1a223d160eb8f995 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 13 Oct 2015 09:08:51 -0700 Subject: [PATCH] only find `adjacents` for nodes in pagetree --- pagetree.rkt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pagetree.rkt b/pagetree.rkt index 39efd13..1dc6378 100644 --- a/pagetree.rkt +++ b/pagetree.rkt @@ -163,12 +163,20 @@ (define (adjacents side pnish [pt (current-pagetree)]) + #;(symbol? pagenodeish? pagetree? . -> . pagenodes?) (and pt pnish (let* ([pagenode (->pagenode pnish)] [proc (if (equal? side 'left) takef takef-right)] - [result (proc (pagetree->list pt) (λ(x) (not (equal? pagenode x))))]) + [pagetree-nodes (pagetree->list pt)] + [in-tree? (member pagenode pagetree-nodes)] + [result (and in-tree? (proc pagetree-nodes (λ(x) (not (equal? pagenode x)))))]) (and (not (empty? result)) result)))) +(module-test-internal + (require rackunit) + (check-equal? (adjacents 'right 'one '(pagetree-index one two three)) '(two three)) + (check-false (adjacents 'right 'node-not-in-pagetree '(pagetree-index one two three)))) + (define+provide/contract (previous* pnish [pt (current-pagetree)]) (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?))