0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Document that if the current selection is not collapsed, that it will

be deleted and replaced by the html. Make style and consistency changes.
This commit is contained in:
Umer Farooq 2015-04-14 21:16:13 -04:00 committed by Neil Jenkins
parent 6fdb288e00
commit c249e3bc19
2 changed files with 13 additions and 12 deletions

View file

@ -138,7 +138,7 @@ Returns a reference to the newly inserted image element.
### insertHTML
Inserts an HTML fragment at the current cursor location. The value supplied should not contain `<body>` tags or anything outside of that.
Inserts an HTML fragment at the current cursor location, or replaces the selection if selected. The value supplied should not contain `<body>` tags or anything outside of that.
The method takes one argument:

View file

@ -2263,9 +2263,11 @@ proto.insertImage = function ( src ) {
return img;
};
// Insert HTML at the cursor location. If the selection is not collapsed
// insertTreeFragmentIntoRange will delete the selection so that it is replaced
// by the html being inserted.
proto.insertHTML = function ( html ) {
var self = this,
range = this.getSelection(),
var range = this.getSelection(),
frag = this._doc.createDocumentFragment(),
div = this.createElement( 'DIV' );
@ -2274,9 +2276,8 @@ proto.insertHTML = function ( html ) {
frag.appendChild( empty( div ) );
// Record undo checkpoint
self._recordUndoState( range );
self._getRangeAndRemoveBookmark( range );
this._recordUndoState( range );
this._getRangeAndRemoveBookmark( range );
try {
frag.normalize();
@ -2293,17 +2294,17 @@ proto.insertHTML = function ( html ) {
insertTreeFragmentIntoRange( range, frag );
if ( !canObserveMutations ) {
self._docWasChanged();
this._docWasChanged();
}
range.collapse( false );
self._ensureBottomLine();
self.setSelection( range );
self._updatePath( range, true );
this._ensureBottomLine();
this.setSelection( range );
this._updatePath( range, true );
} catch ( error ) {
self.didError( error );
this.didError( error );
}
return this;
};
// --- Formatting ---