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(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
}
}
})
expect(cursor.isSelecting()).to.equal(false, 'cursor is not selecting anything');
expect(position.element.getText()).to.equal('Alice has a cat');
expect(position.offset).to.equal(5);
+ expect(position.offsetAtEnd).to.equal(false, 'offset is not at end');
+
+ getSelection.returns({
+ anchorNode: text,
+ focusNode: text,
+ anchorOffset: 15,
+ focusOffset: 15,
+ isCollapsed: true
+ });
+
+ expect(cursor.getPosition().offsetAtEnd).to.equal(true, 'offset at end');
});
it('returns boundries of selection when browser selection not collapsed', function() {