@@ -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 } 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,19 @@ 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 highlightning of priviously 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
+ this . colorizeAnnotation ( listenerApi . getState ( ) , this . annotationSelected , { "border" : "1px solid red" } ) ;
131
+ }
132
+ } ) ) ;
133
+
120
134
// this.storeUnsubscribeListeners.push(subsc);
121
135
}
122
136
@@ -147,7 +161,7 @@ export class SeedTextView extends windowMixin(storeConsumerMixin(LitElement)) {
147
161
}
148
162
149
163
/*
150
- * A callback for scrolling the text to `scrollTarget` position.
164
+ * A callback for scrolling the text to `scrollTarget` position.
151
165
*/
152
166
scrollTextTo ( scrollTarget : string ) : void {
153
167
if ( this . iframe ) {
@@ -308,6 +322,22 @@ export class SeedTextView extends windowMixin(storeConsumerMixin(LitElement)) {
308
322
}
309
323
}
310
324
325
+ /*
326
+ * Get the text segements included in an annotation given by
327
+ * `annotId` and colorize them with the given CSS.
328
+ */
329
+ protected colorizeAnnotation ( state : SeedState , annotId : string , css : CSSDefinition ) : void {
330
+ if ( state . textViews [ this . id ] . segmentsPerAnnotation . hasOwnProperty ( annotId ) ) {
331
+ log . debug ( "colorizing selected annotation in " + this . id + ": " + annotId ) ;
332
+ const segments : Array < string > = state . textViews [ this . id ] . segmentsPerAnnotation [ annotId ] ;
333
+ const cssPerSegments : { [ segmentId : string ] : CSSDefinition } = { } ;
334
+ segments . forEach ( seg => {
335
+ cssPerSegments [ seg ] = css ;
336
+ } ) ;
337
+ this . colorizeText ( cssPerSegments ) ;
338
+ }
339
+ }
340
+
311
341
static styles : CSSResultGroup = [
312
342
windowStyles ,
313
343
css `
0 commit comments