e.preventDefault();
var cursor = canvas.getCursor();
if(!cursor.isSelecting()) {
- var position = cursor.getPosition();
- position.element.split({offset: position.offset});
+ var position = cursor.getPosition(),
+ elements = position.element.split({offset: position.offset}),
+ newEmpty,
+ goto;
+
+ if(position.offsetAtBeginning)
+ newEmpty = elements.first;
+ else if(position.offsetAtEnd)
+ newEmpty = elements.second;
+ if(newEmpty) {
+ goto = newEmpty.append(documentElement.DocumentTextElement.create({text: '\u200B'}, this));
+ canvas.setCurrentElement(goto);
+ }
}
}
});
if(params.caretTo || !textElementToLand.sameNode(this.getCursor().getPosition().element))
this._moveCaretToTextElement(textElementToLand, params.caretTo); // as method on element?
if(!(textElementToLand.sameNode(currentTextElement)))
- this.publisher('currentTextElementSet', element);
+ this.publisher('currentTextElementSet', textElementToLand);
} else {
document.getSelection().removeAllRanges();
}
if(which === 'anchor') {
return {
element: anchorElement,
- offset: selection.anchorOffset
+ offset: selection.anchorOffset,
+ offsetAtBeginning: selection.anchorOffset === 0,
+ offsetAtEnd: anchorElement && anchorElement.getText().length === selection.anchorOffset
};
}
return {
element: element,
- offset: offset
+ offset: offset,
+ offsetAtBeginning: offset === 0,
+ offsetAtEnd: element.getText().length === offset
}
}
})