@@ -417,12 +417,21 @@ const Editor = Module("editor", {
417
417
let textbox = Editor . getEditor ( ) ;
418
418
if ( ! textbox )
419
419
return false ;
420
- let text = textbox . value ;
420
+ let text = '' ;
421
+ let currStart = 0 ;
422
+ let currEnd = 0 ;
423
+ if ( textbox instanceof Window ) {
424
+ text = textbox . getSelection ( ) . getRangeAt ( 0 ) . startContainer . data ;
425
+ currStart = textbox . getSelection ( ) . getRangeAt ( 0 ) . startOffset ;
426
+ currEnd = textbox . getSelection ( ) . getRangeAt ( 0 ) . endOffset ;
427
+ } else {
428
+ text = textbox . value ;
429
+ currStart = textbox . selectionStart ;
430
+ currEnd = textbox . selectionEnd ;
431
+ }
421
432
if ( typeof text !== "string" )
422
433
return false ;
423
434
424
- let currStart = textbox . selectionStart ;
425
- let currEnd = textbox . selectionEnd ;
426
435
let foundWord = text . substring ( 0 , currStart ) . replace ( / .* [ \s \n ] / gm, '' ) . match ( RegExp ( '(' + abbreviations . _match + ')$' ) ) ;
427
436
if ( ! foundWord )
428
437
return true ;
@@ -432,10 +441,20 @@ const Editor = Module("editor", {
432
441
if ( abbrev ) {
433
442
let len = foundWord . length ;
434
443
let abbrText = abbrev . text ;
435
- text = text . substring ( 0 , currStart - len ) + abbrText + text . substring ( currStart ) ;
436
- textbox . value = text ;
437
- textbox . selectionStart = currStart - len + abbrText . length ;
438
- textbox . selectionEnd = currEnd - len + abbrText . length ;
444
+ if ( textbox instanceof Window ) {
445
+ let r = textbox . getSelection ( ) . getRangeAt ( 0 ) ;
446
+ r . setStart ( r . startContainer , currStart - len ) ;
447
+ r . deleteContents ( ) ;
448
+ let textNode = document . createTextNode ( abbrText ) ;
449
+ r . insertNode ( textNode ) ;
450
+ r . selectNodeContents ( textNode ) ;
451
+ textbox . getSelection ( ) . collapseToEnd ( ) ;
452
+ } else {
453
+ text = text . substring ( 0 , currStart - len ) + abbrText + text . substring ( currStart ) ;
454
+ textbox . value = text ;
455
+ textbox . selectionStart = currStart - len + abbrText . length ;
456
+ textbox . selectionEnd = currEnd - len + abbrText . length ;
457
+ }
439
458
}
440
459
441
460
return true ;
0 commit comments