@@ -7,9 +7,10 @@ import { storeConsumerMixin } from './store-consumer-mixin';
7
7
import { windowMixin , windowStyles } from './window-mixin' ;
8
8
9
9
import { seedTextViewContext } from "./seed-context" ;
10
- import { addAppListener } from "./redux/seed-store" ;
10
+ import { addAppListener , SeedState } from "./redux/seed-store" ;
11
11
import { initText , setText , TextState } from "./redux/textsSlice" ;
12
12
import { initTextView , setText as setTextViewText , scrolledTo , fetchAnnotationsPerSegment } from "./redux/textViewsSlice" ;
13
+ import { annotationSelected , annotationsPassedBy } from './redux/annotationsSlice' ;
13
14
import { selectAnnotationsAtSegmentThunk , passByAnnotationsAtSegmentThunk } from "./redux/selectAnnotations" ;
14
15
import { CSSDefinition } from './redux/cssTypes' ;
15
16
import { scrolled , syncOthers } from './redux/synopsisSlice' ;
@@ -18,8 +19,6 @@ import { setScrollTarget } from './redux/synopsisMiddleware';
18
19
19
20
import log from "./logging" ;
20
21
21
- import { SeedState } from './redux/seed-store' ;
22
-
23
22
24
23
25
24
// define the web component
@@ -47,6 +46,8 @@ export class SeedTextView extends windowMixin(storeConsumerMixin(LitElement)) {
47
46
@state ( )
48
47
doc : string | undefined ;
49
48
49
+ protected annotationSelected : string | null = null ;
50
+
50
51
protected docLoaded : boolean = false ;
51
52
52
53
protected msgQueue : Array < any > = [ ] ;
@@ -117,6 +118,37 @@ export class SeedTextView extends windowMixin(storeConsumerMixin(LitElement)) {
117
118
}
118
119
} ) ) ;
119
120
121
+ this . store ?. dispatch ( addAppListener ( {
122
+ actionCreator : annotationSelected ,
123
+ effect : ( _action , listenerApi ) : void => {
124
+ // reset highlighting of previously selected annotation
125
+ if ( this . annotationSelected ) {
126
+ this . colorizeAnnotation ( listenerApi . getState ( ) , this . annotationSelected , { "border" : "none" } ) ;
127
+ }
128
+ // highlight currently selected annotation
129
+ this . annotationSelected = listenerApi . getState ( ) . annotations . annotationSelected ?? "unknown" ;
130
+ // TODO: make CSS configurable
131
+ this . colorizeAnnotation ( listenerApi . getState ( ) , this . annotationSelected , { "border" : "1px solid red" } ) ;
132
+ }
133
+ } ) ) ;
134
+
135
+ this . store ?. dispatch ( addAppListener ( {
136
+ actionCreator : annotationsPassedBy ,
137
+ effect : ( _action , listenerApi ) : void => {
138
+ // reset highlighting of previously transient annotations:
139
+ // general annotation highlighting and transient
140
+ // highlighting are bound to the same visual category,
141
+ // so we can use the general highlighting for a reset
142
+ this . colorizeText ( listenerApi . getState ( ) . textViews [ this . id ] . cssPerSegment ) ;
143
+ // highlight transient annotations
144
+ const annotIds : Array < string > = listenerApi . getState ( ) . annotations . annotationsTransient ;
145
+ annotIds . forEach ( annotId => {
146
+ // TODO: make CSS configurable
147
+ this . colorizeAnnotation ( listenerApi . getState ( ) , annotId , { "background-color" : "silver" } ) ;
148
+ } ) ;
149
+ }
150
+ } ) ) ;
151
+
120
152
// this.storeUnsubscribeListeners.push(subsc);
121
153
}
122
154
@@ -147,7 +179,7 @@ export class SeedTextView extends windowMixin(storeConsumerMixin(LitElement)) {
147
179
}
148
180
149
181
/*
150
- * A callback for scrolling the text to `scrollTarget` position.
182
+ * A callback for scrolling the text to `scrollTarget` position.
151
183
*/
152
184
scrollTextTo ( scrollTarget : string ) : void {
153
185
if ( this . iframe ) {
@@ -308,6 +340,22 @@ export class SeedTextView extends windowMixin(storeConsumerMixin(LitElement)) {
308
340
}
309
341
}
310
342
343
+ /*
344
+ * Get the text segements included in an annotation given by
345
+ * `annotId` and colorize them with the given CSS.
346
+ */
347
+ protected colorizeAnnotation ( state : SeedState , annotId : string , css : CSSDefinition ) : void {
348
+ if ( state . textViews [ this . id ] . segmentsPerAnnotation . hasOwnProperty ( annotId ) ) {
349
+ log . debug ( "colorizing selected annotation in " + this . id + ": " + annotId ) ;
350
+ const segments : Array < string > = state . textViews [ this . id ] . segmentsPerAnnotation [ annotId ] ;
351
+ const cssPerSegments : { [ segmentId : string ] : CSSDefinition } = { } ;
352
+ segments . forEach ( seg => {
353
+ cssPerSegments [ seg ] = css ;
354
+ } ) ;
355
+ this . colorizeText ( cssPerSegments ) ;
356
+ }
357
+ }
358
+
311
359
static styles : CSSResultGroup = [
312
360
windowStyles ,
313
361
css `
0 commit comments