only find `adjacents` for nodes in pagetree

pull/102/head
Matthew Butterick 9 years ago
parent 6b6b91dbc8
commit 9a508a8f44

@ -163,12 +163,20 @@
(define (adjacents side pnish [pt (current-pagetree)]) (define (adjacents side pnish [pt (current-pagetree)])
#;(symbol? pagenodeish? pagetree? . -> . pagenodes?)
(and pt pnish (and pt pnish
(let* ([pagenode (->pagenode pnish)] (let* ([pagenode (->pagenode pnish)]
[proc (if (equal? side 'left) takef takef-right)] [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)))) (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)]) (define+provide/contract (previous* pnish [pt (current-pagetree)])
(((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?)) (((or/c #f pagenodeish?)) (pagetree?) . ->* . (or/c #f pagenodes?))

Loading…
Cancel
Save