mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Fix #293 - Fix a-tag handling on Gecko
This commit is contained in:
parent
465c1268be
commit
adeee498cc
1 changed files with 28 additions and 10 deletions
|
@ -14,6 +14,29 @@ var keys = {
|
|||
221: ']'
|
||||
};
|
||||
|
||||
/**
|
||||
* If the cursor is at the end of a link , then move it outside of the link so that the entered text does
|
||||
* not become part of the link text. Special case for gecko which does not move outside automatically.
|
||||
*
|
||||
* @param {Squire} self Instance of the editor.
|
||||
* @param {Range} range Current selection range.
|
||||
*/
|
||||
function handleATagCursor(self, range) {
|
||||
var node = range.endContainer;
|
||||
var parent = node.parentNode;
|
||||
if (isGecko) {
|
||||
if ( range.collapsed && node.nodeName === 'A' && range.endOffset === getLength( node ) ) {
|
||||
range.setStartAfter( node );
|
||||
self.setSelection( range );
|
||||
}
|
||||
}
|
||||
if ( range.collapsed && parent.nodeName === 'A' &&
|
||||
!node.nextSibling && range.endOffset === getLength( node ) ) {
|
||||
range.setStartAfter( parent );
|
||||
self.setSelection( range );
|
||||
}
|
||||
}
|
||||
|
||||
// Ref: http://unixpapa.com/js/key.html
|
||||
var onKey = function ( event ) {
|
||||
var code = event.keyCode,
|
||||
|
@ -67,6 +90,8 @@ var onKey = function ( event ) {
|
|||
this._ensureBottomLine();
|
||||
this.setSelection( range );
|
||||
this._updatePath( range, true );
|
||||
} else {
|
||||
handleATagCursor( this, range );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -427,17 +452,10 @@ var keyHandlers = {
|
|||
addLinks( range.startContainer, self._root, self );
|
||||
self._getRangeAndRemoveBookmark( range );
|
||||
|
||||
// If the cursor is at the end of a link (<a>foo|</a>) then move it
|
||||
// outside of the link (<a>foo</a>|) so that the space is not part of
|
||||
// the link text.
|
||||
node = range.endContainer;
|
||||
parent = node.parentNode;
|
||||
if ( range.collapsed && parent.nodeName === 'A' &&
|
||||
!node.nextSibling && range.endOffset === getLength( node ) ) {
|
||||
range.setStartAfter( parent );
|
||||
}
|
||||
handleATagCursor(self, range);
|
||||
|
||||
// Delete the selection if not collapsed
|
||||
else if ( !range.collapsed ) {
|
||||
if ( !range.collapsed ) {
|
||||
deleteContentsOfRange( range, self._root );
|
||||
self._ensureBottomLine();
|
||||
self.setSelection( range );
|
||||
|
|
Loading…
Reference in a new issue