update wysiwyg to start positioning remote carets more accurately
This commit is contained in:
parent
96423d7145
commit
7b23e96a61
@ -64,7 +64,8 @@
|
||||
.remote-cursor {
|
||||
min-height: 20px;
|
||||
width: 3px;
|
||||
position: absolute;
|
||||
//position: absolute;
|
||||
position: fixed;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ export class WysiwygComponent implements OnInit {
|
||||
}
|
||||
|
||||
const parts = path.split('.')
|
||||
.map(x => x.split('#'))
|
||||
.map(x => x.split('@'))
|
||||
.map(([tagName, idxString]) => [tagName, Number(idxString)]);
|
||||
|
||||
let currentElem = this.editable.nativeElement;
|
||||
@ -127,7 +127,7 @@ export class WysiwygComponent implements OnInit {
|
||||
}
|
||||
|
||||
const [tagName, idx] = part;
|
||||
const children = [...currentElem.getElementsByTagName(tagName)];
|
||||
const children = [...(tagName === '#text' ? currentElem.childNodes : currentElem.getElementsByTagName(tagName))];
|
||||
currentElem = children[idx];
|
||||
}
|
||||
|
||||
@ -139,9 +139,11 @@ export class WysiwygComponent implements OnInit {
|
||||
throw new Error('Cannot get path to element unless editable.');
|
||||
}
|
||||
|
||||
debug('getPathToElement', elem);
|
||||
|
||||
const maxNest = 5000;
|
||||
let currentNest = 0;
|
||||
const parents = [];
|
||||
const parents = [elem];
|
||||
let currentParent = elem;
|
||||
|
||||
do {
|
||||
@ -159,7 +161,9 @@ export class WysiwygComponent implements OnInit {
|
||||
return parents.reverse()
|
||||
.slice(1)
|
||||
.map((element, idx) => {
|
||||
const siblings = element.parentElement.getElementsByTagName(element.tagName);
|
||||
const siblings = element.tagName ? element.parentElement.getElementsByTagName(element.tagName)
|
||||
: element.parentElement.childNodes;
|
||||
|
||||
let siblingIdx = -1;
|
||||
[...siblings].some((sibling, potentialIdx) => {
|
||||
if ( sibling === element ) {
|
||||
@ -168,7 +172,7 @@ export class WysiwygComponent implements OnInit {
|
||||
}
|
||||
});
|
||||
|
||||
return `${element.tagName}#${siblingIdx}`;
|
||||
return `${element.tagName || '#text'}@${siblingIdx}`;
|
||||
})
|
||||
.join('.');
|
||||
}
|
||||
@ -176,8 +180,19 @@ export class WysiwygComponent implements OnInit {
|
||||
processSelections() {
|
||||
for ( const sel of this.privEditingUserSelections ) {
|
||||
sel.element = this.getElementFromPath(sel.path);
|
||||
sel.top = sel.element.offsetTop;
|
||||
sel.left = sel.element.offsetLeft;
|
||||
if ( sel.element ) {
|
||||
sel.top = sel.element.offsetTop;
|
||||
sel.left = sel.element.offsetLeft;
|
||||
|
||||
const range = document.createRange();
|
||||
range.setStart(sel.element, sel.offset);
|
||||
range.setEnd(sel.element, sel.offset);
|
||||
|
||||
const rect = range.getClientRects()[0];
|
||||
sel.top = rect.top;
|
||||
sel.left = rect.left;
|
||||
}
|
||||
|
||||
console.log({sel, editable: this.editable});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user