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:
parent
6fdb288e00
commit
c249e3bc19
2 changed files with 13 additions and 12 deletions
|
@ -138,7 +138,7 @@ Returns a reference to the newly inserted image element.
|
||||||
|
|
||||||
### insertHTML
|
### 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:
|
The method takes one argument:
|
||||||
|
|
||||||
|
|
|
@ -2263,9 +2263,11 @@ proto.insertImage = function ( src ) {
|
||||||
return img;
|
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 ) {
|
proto.insertHTML = function ( html ) {
|
||||||
var self = this,
|
var range = this.getSelection(),
|
||||||
range = this.getSelection(),
|
|
||||||
frag = this._doc.createDocumentFragment(),
|
frag = this._doc.createDocumentFragment(),
|
||||||
div = this.createElement( 'DIV' );
|
div = this.createElement( 'DIV' );
|
||||||
|
|
||||||
|
@ -2274,9 +2276,8 @@ proto.insertHTML = function ( html ) {
|
||||||
frag.appendChild( empty( div ) );
|
frag.appendChild( empty( div ) );
|
||||||
|
|
||||||
// Record undo checkpoint
|
// Record undo checkpoint
|
||||||
self._recordUndoState( range );
|
this._recordUndoState( range );
|
||||||
self._getRangeAndRemoveBookmark( range );
|
this._getRangeAndRemoveBookmark( range );
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
frag.normalize();
|
frag.normalize();
|
||||||
|
@ -2293,17 +2294,17 @@ proto.insertHTML = function ( html ) {
|
||||||
|
|
||||||
insertTreeFragmentIntoRange( range, frag );
|
insertTreeFragmentIntoRange( range, frag );
|
||||||
if ( !canObserveMutations ) {
|
if ( !canObserveMutations ) {
|
||||||
self._docWasChanged();
|
this._docWasChanged();
|
||||||
}
|
}
|
||||||
range.collapse( false );
|
range.collapse( false );
|
||||||
self._ensureBottomLine();
|
this._ensureBottomLine();
|
||||||
|
|
||||||
self.setSelection( range );
|
|
||||||
self._updatePath( range, true );
|
|
||||||
|
|
||||||
|
this.setSelection( range );
|
||||||
|
this._updatePath( range, true );
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
self.didError( error );
|
this.didError( error );
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Formatting ---
|
// --- Formatting ---
|
||||||
|
|
Loading…
Reference in a new issue