Skip to content

Commit

Permalink
rich-text-view: skip updates when content hasn't changed
Browse files Browse the repository at this point in the history
Close #73.

This caches the "previous content" on the view's implementation so that
it can be compared later. See the issue notes for more details on why
this is needed.

RE: `#:transparent`. For `equal?` to work, this is the simplest possible
change. I could also (I think) implement `gen:equal+hash`, but there's
nothing really private about `pict/alt-text` anyway. I only provide the
constructor and predicate, so code that sneakily manipulates the
transparent values would jump out.
  • Loading branch information
benknoble committed Feb 4, 2024
1 parent 8d514e1 commit 8e6da62
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions gui/rich-text-display.rkt
Expand Up @@ -65,7 +65,7 @@
(define (newline? x)
(eq? x newline))

(struct pict/alt-text [p alt-text])
(struct pict/alt-text [p alt-text] #:transparent)

(define (draw editor content font)
(send editor begin-edit-sequence)
Expand Down Expand Up @@ -121,7 +121,7 @@
(match-define (list h-m v-m) (peek @margin))
(match-define (list h-i v-i) (peek @inset))
(define canvas
(new editor-canvas%
(new (context-mixin editor-canvas%)
[parent parent]
[style style]
[horizontal-inset h-i]
Expand All @@ -143,6 +143,7 @@
(send* editor
(scroll-to-position 0)
(lock #t))
(send canvas set-context 'content (peek @content))
canvas)

(define (redraw v content font)
Expand All @@ -155,8 +156,11 @@

(define/public (update v what val)
(case/dep what
[@content (redraw v val (peek @font))]
[@font (redraw v (peek @content) val)]
[@content
(unless (equal? val (send v get-context 'content))
(redraw v val (peek @font))
(send v set-context 'content val))]
[@font (redraw v (peek @content) val)]
[@min-size
(match-define (list min-w min-h) val)
(send* v
Expand Down

0 comments on commit 8e6da62

Please sign in to comment.