diff --git a/source/KeyHandlers.js b/source/KeyHandlers.js
index d6e6d9c..1d744e6 100644
--- a/source/KeyHandlers.js
+++ b/source/KeyHandlers.js
@@ -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 (foo|) then move it
- // outside of the link (foo|) 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 );