@@ -100,7 +100,7 @@ export const ReactEditor = {
100
100
}
101
101
102
102
throw new Error (
103
- `Unable to find the path for Slate node: ${ JSON . stringify ( node ) } `
103
+ `Unable to find the path for Slate node: ${ JSON . stringify ( node ) } ` ,
104
104
) ;
105
105
} ,
106
106
@@ -137,7 +137,12 @@ export const ReactEditor = {
137
137
* Focus the editor.
138
138
*/
139
139
140
- focus ( editor : ReactEditor , force : boolean = false ) : void {
140
+ focus (
141
+ editor : ReactEditor ,
142
+ force : boolean = false ,
143
+ preserveSelection : boolean = false ,
144
+ ) : void {
145
+ console . trace ( "focus!" , { force } ) ;
141
146
const { selection } = editor ;
142
147
const el = ReactEditor . toDOMNode ( editor , editor ) ;
143
148
IS_FOCUSED . set ( editor , true ) ;
@@ -151,8 +156,12 @@ export const ReactEditor = {
151
156
el . blur ( ) ;
152
157
el . focus ( { preventScroll : true } ) ;
153
158
}
154
- if ( selection != null ) {
155
- // I've changed the focus method to preserve the selection if there is one.
159
+ if ( selection != null && preserveSelection ) {
160
+ console . log ( "setting selection" , { selection } ) ;
161
+ // I've changed the focus method to optionally preserve the selection if there is one.
162
+ // However, doing this when not needed may be the cause of
163
+ // https://github.com/sagemathinc/cocalc/issues/6803
164
+ // hence the preserveSelection parameter.
156
165
// Often when the editor not focused there is no selection. However,
157
166
// in some cases, e.g., "set the selection, then focus", like we
158
167
// do when using commands to move the cursors out of editing a void element,
@@ -186,7 +195,7 @@ export const ReactEditor = {
186
195
hasDOMNode (
187
196
editor : ReactEditor ,
188
197
target : DOMNode ,
189
- options : { editable ?: boolean } = { }
198
+ options : { editable ?: boolean } = { } ,
190
199
) : boolean {
191
200
const { editable = false } = options ;
192
201
const editorEl = ReactEditor . toDOMNode ( editor , editor ) ;
@@ -245,7 +254,7 @@ export const ReactEditor = {
245
254
} catch ( err ) {
246
255
console . warn (
247
256
"SLATE: problem in setFragementData (invalid selection; so ignoring)" ,
248
- err
257
+ err ,
249
258
) ;
250
259
}
251
260
} ,
@@ -267,7 +276,7 @@ export const ReactEditor = {
267
276
268
277
if ( ! domNode ) {
269
278
throw new Error (
270
- `Cannot resolve a DOM node from Slate node: ${ JSON . stringify ( node ) } `
279
+ `Cannot resolve a DOM node from Slate node: ${ JSON . stringify ( node ) } ` ,
271
280
) ;
272
281
}
273
282
@@ -319,7 +328,7 @@ export const ReactEditor = {
319
328
320
329
if ( ! domPoint ) {
321
330
throw new Error (
322
- `Cannot resolve a DOM point from Slate point: ${ JSON . stringify ( point ) } `
331
+ `Cannot resolve a DOM point from Slate point: ${ JSON . stringify ( point ) } ` ,
323
332
) ;
324
333
}
325
334
@@ -398,7 +407,7 @@ export const ReactEditor = {
398
407
399
408
if ( x == null || y == null ) {
400
409
throw new Error (
401
- `Cannot resolve a Slate range from a DOM event: ${ event } `
410
+ `Cannot resolve a Slate range from a DOM event: ${ event } ` ,
402
411
) ;
403
412
}
404
413
@@ -446,7 +455,7 @@ export const ReactEditor = {
446
455
447
456
if ( ! domRange ) {
448
457
throw new Error (
449
- `Cannot resolve a Slate range from a DOM event: ${ event } `
458
+ `Cannot resolve a Slate range from a DOM event: ${ event } ` ,
450
459
) ;
451
460
}
452
461
@@ -521,7 +530,7 @@ export const ReactEditor = {
521
530
522
531
if ( ! textNode ) {
523
532
throw new Error (
524
- `Cannot resolve a Slate point from DOM point: ${ domPoint } `
533
+ `Cannot resolve a Slate point from DOM point: ${ domPoint } ` ,
525
534
) ;
526
535
}
527
536
@@ -539,7 +548,7 @@ export const ReactEditor = {
539
548
540
549
toSlateRange (
541
550
editor : ReactEditor ,
542
- domRange : DOMRange | DOMStaticRange | DOMSelection
551
+ domRange : DOMRange | DOMStaticRange | DOMSelection ,
543
552
) : Range {
544
553
const el =
545
554
domRange instanceof Selection
@@ -574,7 +583,7 @@ export const ReactEditor = {
574
583
focusOffset == null
575
584
) {
576
585
throw new Error (
577
- `Cannot resolve a Slate range from DOM range: ${ domRange } `
586
+ `Cannot resolve a Slate range from DOM range: ${ domRange } ` ,
578
587
) ;
579
588
}
580
589
0 commit comments