// When user writes into caret, add it to the document.
$('textarea', caret).on('input', function() {
let v = $(this).val();
$(this).val('');
self.insertChar(v);
// When user writes into caret, add it to the document.
$('textarea', caret).on('input', function() {
let v = $(this).val();
$(this).val('');
self.insertChar(v);
// On click on x-node element, set caret position.
self.view.on('click', '*[x-node]', function(e) {
if (e.redakcja_caret_ignore) return;
e.redakcja_caret_ignore = true;
// On click on x-node element, set caret position.
self.view.on('click', '*[x-node]', function(e) {
if (e.redakcja_caret_ignore) return;
e.redakcja_caret_ignore = true;
var selection = window.getSelection();
if (!selection.isCollapsed) return;
var anchorNode = selection.anchorNode;
if (anchorNode.nodeType != Node.TEXT_NODE) return;
var selection = window.getSelection();
if (!selection.isCollapsed) return;
var anchorNode = selection.anchorNode;
if (anchorNode.nodeType != Node.TEXT_NODE) return;
// Is selection still inside a node?
if (!$(anchorNode).closest('[x-node]').length) return;
if ($(anchorNode).parents('[x-annotation-box]').not('.editing').length) return;
// Is selection still inside a node?
if (!$(anchorNode).closest('[x-node]').length) return;
if ($(anchorNode).parents('[x-annotation-box]').not('.editing').length) return;
// cases:
// we are in <akap> (no going up)
// we are in <wyroznienie> (can go up)
// we are next to <wyroznienie> (can go inside)
// cases:
// we are in <akap> (no going up)
// we are in <wyroznienie> (can go up)
// we are next to <wyroznienie> (can go inside)
let contents = this.element.parent().contents();
// Find the text before caret.
let textBefore = contents[contents.index(this.element) - 1];
let contents = this.element.parent().contents();
// Find the text before caret.
let textBefore = contents[contents.index(this.element) - 1];
// Should be text, but what if not?
textBefore.textContent = textBefore.textContent.substr(0, textBefore.textContent.length - 1);
this.normalize();
// Should be text, but what if not?
textBefore.textContent = textBefore.textContent.substr(0, textBefore.textContent.length - 1);
this.normalize();
deleteAfter() {
let contents = this.element.parent().contents();
// Find the text after caret.
let textAfter = contents[contents.index(this.element) + 1];
textAfter.textContent = textAfter.textContent.substr(1);
}
deleteAfter() {
let contents = this.element.parent().contents();
// Find the text after caret.
let textAfter = contents[contents.index(this.element) + 1];
textAfter.textContent = textAfter.textContent.substr(1);
}
splitBlock() {
let splitter = this.element;
let parent, newParent, splitIndex, index;
splitBlock() {
let splitter = this.element;
let parent, newParent, splitIndex, index;
let contents = this.element.parent().contents();
let index = contents.index(this.element);
let target, moved, oldparent;
let contents = this.element.parent().contents();
let index = contents.index(this.element);
let target, moved, oldparent;
let parent = this.element.parent()[0];
if (opts.edge(index, contents.length)) {
// We're at the end -- what to do?
// can we go up?
let parent = this.element.parent()[0];
if (opts.edge(index, contents.length)) {
// We're at the end -- what to do?
// can we go up?
if (target.nodeName == 'EM') {
// enter
parent = $(target);
contents = parent.contents();
index = opts.enter(contents.length);
target = contents[index];
if (target.nodeName == 'EM') {
// enter
parent = $(target);
contents = parent.contents();
index = opts.enter(contents.length);
target = contents[index];
if (target !== undefined && target.nodeType == Node.TEXT_NODE ) {
if (!moved) {
target = opts.splitTarget(target);
} else {
target = opts.noSplitTarget(target);
}
if (target !== undefined && target.nodeType == Node.TEXT_NODE ) {
if (!moved) {
target = opts.splitTarget(target);
} else {
target = opts.noSplitTarget(target);
}