@@ -9,17 +9,15 @@ import { opts } from '../../connect';
9
9
class SelectionControl {
10
10
dom : HTMLDivElement ;
11
11
12
- constructor ( view : EditorView , stateKey : string ) {
12
+ constructor ( view : EditorView , stateKey : any ) {
13
13
this . dom = document . createElement ( 'div' ) ;
14
14
this . dom . className = 'selection-control' ;
15
15
ReactDOM . render (
16
16
< Card style = { { borderRadius : '50%' } } >
17
17
< IconButton
18
18
color = "primary"
19
- aria-label = "add comment"
20
- onClick = { ( ) => {
21
- opts . addComment ( stateKey , view ) ;
22
- } }
19
+ aria-label = "Add Comment"
20
+ onClick = { ( ) => opts . addComment ( stateKey , view ) }
23
21
>
24
22
< CommentIcon />
25
23
</ IconButton >
@@ -31,27 +29,26 @@ class SelectionControl {
31
29
}
32
30
33
31
update ( view : EditorView , lastState : EditorState | null ) {
34
- const { state } = view ;
35
- if ( lastState && lastState . selection . eq ?.( state . selection ) ) return ;
32
+ const { selection } = view . state ;
33
+ if ( lastState ? .selection . eq ?.( selection ) ) return ;
36
34
37
35
// Hide the tooltip if the selection is empty
38
- if ( state . selection . empty ) {
36
+ if ( selection . empty ) {
39
37
this . dom . style . display = 'none' ;
40
38
return ;
41
39
}
42
40
43
41
// Otherwise, reposition it and update its content
44
42
this . dom . style . display = '' ;
45
- const { from, to } = state . selection ;
43
+ // Use the first place you put the anchor, so the selection doesn't jump around
44
+ const { anchor } = selection ;
46
45
// These are in screen coordinates
47
- const start = view . coordsAtPos ( from ) ;
46
+ const start = view . coordsAtPos ( anchor ) ;
48
47
// The box in which the tooltip is positioned, to use as base
49
48
if ( ! this . dom . offsetParent ) {
50
49
return ;
51
50
}
52
51
const box = this . dom . offsetParent . getBoundingClientRect ( ) ;
53
- // Find a center-ish x position from the selection endpoints (when
54
- // crossing lines, end may be more to the left)
55
52
this . dom . style . bottom = `${ box . bottom - start . top - 30 } px` ;
56
53
}
57
54
0 commit comments