@@ -52,7 +52,7 @@ export class AngularEditorComponent
52
52
53
53
focusInstance : any ;
54
54
blurInstance : any ;
55
-
55
+ currentCursorSelection : Range ;
56
56
@Input ( ) id = "" ;
57
57
@Input ( ) config : AngularEditorConfig = angularEditorConfig ;
58
58
@Input ( ) placeholder = "" ;
@@ -157,7 +157,7 @@ export class AngularEditorComponent
157
157
*/
158
158
public onTextAreaMouseOut ( event : MouseEvent ) : void {
159
159
this . editorService . saveSelection ( ) ;
160
- this . savedSelection = this . editorService . savedSelection ;
160
+ this . currentCursorSelection = this . editorService . savedSelection ;
161
161
}
162
162
163
163
/**
@@ -431,27 +431,15 @@ export class AngularEditorComponent
431
431
} ) ;
432
432
return tags . join ( "," ) ;
433
433
}
434
- insert ( value : string ) {
435
- this . focus ( ) ;
434
+ insertTextAtCursor ( text : string ) {
436
435
let selection = window . getSelection ( ) ;
437
- //let range = document.createRange();
438
- //range.setEndAfter(this.selectiedNode);
439
- //selection.addRange(range);
440
- //selection.setPosition(this.textArea.nativeElement, this.selectiedIndex);
441
- // this.selectiedIndex += value.length;
442
436
selection . removeAllRanges ( ) ;
443
- selection . addRange ( this . savedSelection ) ;
444
- this . editorService . insertHtml ( value ) ;
445
- selection . setPosition ( this . savedSelection . baseNode , 5 ) ;
446
- // selection.removeAllRanges();
447
- // let range = document.createRange();
448
- // selection.setPosition(
449
- // this.textArea.nativeElement,
450
- // this.savedSelection.baseOffet
451
- // );
452
- // this.savedSelection = selection.getRangeAt(0);
437
+ selection . addRange ( this . currentCursorSelection ) ;
438
+ this . editorService . insertHtml ( text ) ;
439
+ this . editorService . saveSelection ( ) ;
440
+ this . currentCursorSelection = this . editorService . savedSelection ;
453
441
}
454
- savedSelection ;
442
+
455
443
ngOnDestroy ( ) {
456
444
if ( this . blurInstance ) {
457
445
this . blurInstance ( ) ;
0 commit comments