mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 13:16:31 -05:00
Enter press at end of PRE will break line.
This commit is contained in:
parent
8a8285560e
commit
29fffdccd0
5 changed files with 23 additions and 13 deletions
|
@ -1327,10 +1327,14 @@ var keyHandlers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( /^PRE|CODE|SAMP$/.test( block.nodeName ) ) {
|
if ( /^PRE|CODE|SAMP$/.test( block.nodeName ) ) {
|
||||||
|
if ( !getNodeAfter( range.endContainer, range.endOffset ).nodeValue[ range.endOffset ] ) {
|
||||||
|
insertNodeInRange( range, self._doc.createTextNode( '\n\n' ) );
|
||||||
|
} else {
|
||||||
|
insertNodeInRange( range, self._doc.createTextNode( '\n' ) );
|
||||||
|
}
|
||||||
// Inside a preformatted block, insert a linebreak, and done.
|
// Inside a preformatted block, insert a linebreak, and done.
|
||||||
insertNodeInRange( range, self._doc.createTextNode( '\n' ) );
|
|
||||||
range.collapse( false );
|
|
||||||
block.normalize();
|
block.normalize();
|
||||||
|
range.collapse( false );
|
||||||
self.setSelection( range );
|
self.setSelection( range );
|
||||||
self._updatePath( range, true );
|
self._updatePath( range, true );
|
||||||
return;
|
return;
|
||||||
|
@ -3545,7 +3549,7 @@ var getTextFromHTMLFragment = function ( self, frag ) {
|
||||||
// Strip down to text only
|
// Strip down to text only
|
||||||
lines.push( node.textContent );
|
lines.push( node.textContent );
|
||||||
}
|
}
|
||||||
return self._doc.createTextNode( lines.join( '\n' ) || '\n' );
|
return self._doc.createTextNode( lines.join( '\n' ) || '' );
|
||||||
};
|
};
|
||||||
|
|
||||||
var makePreformatted = function ( frag ) {
|
var makePreformatted = function ( frag ) {
|
||||||
|
@ -3553,7 +3557,8 @@ var makePreformatted = function ( frag ) {
|
||||||
this._config.tagAttributes.pre, [
|
this._config.tagAttributes.pre, [
|
||||||
this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' } ),
|
this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' } ),
|
||||||
getTextFromHTMLFragment( this, frag ),
|
getTextFromHTMLFragment( this, frag ),
|
||||||
this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' } )
|
this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' } ),
|
||||||
|
this._doc.createTextNode( '\n' )
|
||||||
] );
|
] );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1346,7 +1346,7 @@ var getTextFromHTMLFragment = function ( self, frag ) {
|
||||||
// Strip down to text only
|
// Strip down to text only
|
||||||
lines.push( node.textContent );
|
lines.push( node.textContent );
|
||||||
}
|
}
|
||||||
return self._doc.createTextNode( lines.join( '\n' ) || '\n' );
|
return self._doc.createTextNode( lines.join( '\n' ) || '' );
|
||||||
};
|
};
|
||||||
|
|
||||||
var makePreformatted = function ( frag ) {
|
var makePreformatted = function ( frag ) {
|
||||||
|
@ -1354,7 +1354,8 @@ var makePreformatted = function ( frag ) {
|
||||||
this._config.tagAttributes.pre, [
|
this._config.tagAttributes.pre, [
|
||||||
this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' } ),
|
this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' } ),
|
||||||
getTextFromHTMLFragment( this, frag ),
|
getTextFromHTMLFragment( this, frag ),
|
||||||
this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' } )
|
this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' } ),
|
||||||
|
this._doc.createTextNode( '\n' )
|
||||||
] );
|
] );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -176,10 +176,14 @@ var keyHandlers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( /^PRE|CODE|SAMP$/.test( block.nodeName ) ) {
|
if ( /^PRE|CODE|SAMP$/.test( block.nodeName ) ) {
|
||||||
|
if ( !getNodeAfter( range.endContainer, range.endOffset ).nodeValue[ range.endOffset ] ) {
|
||||||
|
insertNodeInRange( range, self._doc.createTextNode( '\n\n' ) );
|
||||||
|
} else {
|
||||||
|
insertNodeInRange( range, self._doc.createTextNode( '\n' ) );
|
||||||
|
}
|
||||||
// Inside a preformatted block, insert a linebreak, and done.
|
// Inside a preformatted block, insert a linebreak, and done.
|
||||||
insertNodeInRange( range, self._doc.createTextNode( '\n' ) );
|
|
||||||
range.collapse( false );
|
|
||||||
block.normalize();
|
block.normalize();
|
||||||
|
range.collapse( false );
|
||||||
self.setSelection( range );
|
self.setSelection( range );
|
||||||
self._updatePath( range, true );
|
self._updatePath( range, true );
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -204,7 +204,7 @@ describe('Squire RTE', function () {
|
||||||
expect(editor, 'to contain HTML', startHTML);
|
expect(editor, 'to contain HTML', startHTML);
|
||||||
editor.moveCursorToStart();
|
editor.moveCursorToStart();
|
||||||
editor.makePreformatted();
|
editor.makePreformatted();
|
||||||
expect(editor, 'to contain HTML', '<pre>one two three four five</pre>');
|
expect(editor, 'to contain HTML', '<pre>one two three four five\n</pre>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds an empty PRE element', function () {
|
it('adds an empty PRE element', function () {
|
||||||
|
@ -222,7 +222,7 @@ describe('Squire RTE', function () {
|
||||||
expect(editor, 'to contain HTML', startHTML);
|
expect(editor, 'to contain HTML', startHTML);
|
||||||
selectAll(editor);
|
selectAll(editor);
|
||||||
editor.makePreformatted();
|
editor.makePreformatted();
|
||||||
expect(editor, 'to contain HTML', '<pre>one two\nthree four\nfive</pre>');
|
expect(editor, 'to contain HTML', '<pre>one two\nthree four\nfive\n</pre>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('expands existing PRE tags to encompass selection', function () {
|
it('expands existing PRE tags to encompass selection', function () {
|
||||||
|
@ -231,7 +231,7 @@ describe('Squire RTE', function () {
|
||||||
expect(editor, 'to contain HTML', startHTML);
|
expect(editor, 'to contain HTML', startHTML);
|
||||||
selectAll(editor);
|
selectAll(editor);
|
||||||
editor.makePreformatted();
|
editor.makePreformatted();
|
||||||
expect(editor, 'to contain HTML', '<pre>abc\n\none two three four five\n</pre>');
|
expect(editor, 'to contain HTML', '<pre>abc\n\none two three four five\n\n</pre>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue