0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Ensure there is always a normal block at the bottom of the page.

This commit is contained in:
Neil Jenkins 2014-06-02 10:32:21 +10:00
parent f0bd5138e1
commit e108c18c38
3 changed files with 28 additions and 6 deletions

View file

@ -2570,6 +2570,14 @@ var cleanupBRs = function ( root ) {
}
};
proto._ensureBottomLine = function () {
var body = this._body,
div = body.lastChild;
if ( !div || div.nodeName !== 'DIV' || !isBlock( div ) ) {
body.appendChild( this.createDefaultBlock() );
}
};
// --- Cut and Paste ---
proto._onCut = function () {
@ -2582,7 +2590,7 @@ proto._onCut = function () {
setTimeout( function () {
try {
// If all content removed, ensure div at start of body.
fixCursor( self._body );
self._ensureBottomLine();
} catch ( error ) {
self.didError( error );
}
@ -2689,8 +2697,8 @@ proto._onPaste = function ( event ) {
if ( doPaste ) {
insertTreeFragmentIntoRange( range, frag );
self._docWasChanged();
range.collapse( false );
self._ensureBottomLine();
}
}
@ -2768,6 +2776,7 @@ var afterDelete = function ( self ) {
self.setSelection( range );
self._updatePath( range );
}
self._ensureBottomLine();
} catch ( error ) {
self.didError( error );
}
@ -2940,6 +2949,7 @@ var keyHandlers = {
self._getRangeAndRemoveBookmark( range );
event.preventDefault();
deleteContentsOfRange( range );
self._ensureBottomLine();
self.setSelection( range );
self._updatePath( range, true );
}
@ -3006,6 +3016,7 @@ var keyHandlers = {
self._getRangeAndRemoveBookmark( range );
event.preventDefault();
deleteContentsOfRange( range );
self._ensureBottomLine();
self.setSelection( range );
self._updatePath( range, true );
}

File diff suppressed because one or more lines are too long

View file

@ -1457,6 +1457,14 @@ var cleanupBRs = function ( root ) {
}
};
proto._ensureBottomLine = function () {
var body = this._body,
div = body.lastChild;
if ( !div || div.nodeName !== 'DIV' || !isBlock( div ) ) {
body.appendChild( this.createDefaultBlock() );
}
};
// --- Cut and Paste ---
proto._onCut = function () {
@ -1469,7 +1477,7 @@ proto._onCut = function () {
setTimeout( function () {
try {
// If all content removed, ensure div at start of body.
fixCursor( self._body );
self._ensureBottomLine();
} catch ( error ) {
self.didError( error );
}
@ -1576,8 +1584,8 @@ proto._onPaste = function ( event ) {
if ( doPaste ) {
insertTreeFragmentIntoRange( range, frag );
self._docWasChanged();
range.collapse( false );
self._ensureBottomLine();
}
}
@ -1655,6 +1663,7 @@ var afterDelete = function ( self ) {
self.setSelection( range );
self._updatePath( range );
}
self._ensureBottomLine();
} catch ( error ) {
self.didError( error );
}
@ -1827,6 +1836,7 @@ var keyHandlers = {
self._getRangeAndRemoveBookmark( range );
event.preventDefault();
deleteContentsOfRange( range );
self._ensureBottomLine();
self.setSelection( range );
self._updatePath( range, true );
}
@ -1893,6 +1903,7 @@ var keyHandlers = {
self._getRangeAndRemoveBookmark( range );
event.preventDefault();
deleteContentsOfRange( range );
self._ensureBottomLine();
self.setSelection( range );
self._updatePath( range, true );
}