@@ -11,7 +11,7 @@ import {compare, type ITimestampStruct} from '../../../../json-crdt-patch';
11
11
import { SliceTypeCon } from '../../../../json-crdt-extensions/peritext/slice/constants' ;
12
12
import { NewSliceConfig } from './NewSliceConfig' ;
13
13
import type { UiLifeCycles } from '../../../web/types' ;
14
- import type { BufferDetail , PeritextEventDetailMap } from '../../../events/types' ;
14
+ import type { BufferDetail , PeritextCursorEvent , PeritextEventDetailMap } from '../../../events/types' ;
15
15
import type { PeritextSurfaceState } from '../../../web' ;
16
16
import type { MenuItem } from '../types' ;
17
17
import type { ToolbarPluginOpts } from '../ToolbarPlugin' ;
@@ -43,7 +43,7 @@ export class ToolbarState implements UiLifeCycles {
43
43
/** ------------------------------------------- {@link UiLifeCycles} */
44
44
45
45
public start ( ) {
46
- const { surface, showInlineToolbar} = this ;
46
+ const { surface, showInlineToolbar, newSliceConfig } = this ;
47
47
const { dom, events} = surface ;
48
48
const { et} = events ;
49
49
const mouseDown = dom ! . cursor . mouseDown ;
@@ -78,16 +78,27 @@ export class ToolbarState implements UiLifeCycles {
78
78
}
79
79
}
80
80
} ;
81
-
81
+ const onCursor = ( { detail} : PeritextCursorEvent ) => {
82
+ // Close config popup on non-focus cursor moves.
83
+ if ( newSliceConfig . value ) {
84
+ const isFocusMove = detail . move && detail . move . length === 1 && detail . move [ 0 ] [ 0 ] === 'focus' ;
85
+ if ( ! isFocusMove ) {
86
+ this . newSliceConfig . next ( void 0 ) ;
87
+ }
88
+ }
89
+ } ;
90
+
82
91
el . addEventListener ( 'mousedown' , mouseDownListener ) ;
83
92
el . addEventListener ( 'mouseup' , mouseUpListener ) ;
84
93
el . addEventListener ( 'keydown' , onKeyDown ) ;
94
+ et . addEventListener ( 'cursor' , onCursor ) ;
85
95
return ( ) => {
86
96
changeUnsubscribe ( ) ;
87
97
unsubscribeMouseDown ?.( ) ;
88
98
el . removeEventListener ( 'mousedown' , mouseDownListener ) ;
89
99
el . removeEventListener ( 'mouseup' , mouseUpListener ) ;
90
100
el . removeEventListener ( 'keydown' , onKeyDown ) ;
101
+ et . removeEventListener ( 'cursor' , onCursor ) ;
91
102
} ;
92
103
}
93
104
0 commit comments