scrapbox-cursor-position
scrapboxcursor
ScrapVim使
cursor : div.cursor
cursor
lines : div.lines
scrapbox
cursor
{id, column}
id :cursor id
column cursor
0
index+1
{error: 'The cursor doesn\'t has a focus.'}

export function getCursorInfo({lines, cursor}) {
// cursor
const cursorLine = lines.getElementsByClassName('cursor-line')?.[0];
if (!cursorLine) return {error: 'The cursor doesn\'t has a focus.'};
// <span>
const chars = [...cursorLine.querySelectorAll('span[class^="c-"]')];
// cursor<span>
const cursorLeft = Math.round(cursor.getBoundingClientRect().left);
const targetChar = chars.find(char => {
const {left, right} = char.getBoundingClientRect();
return Math.round(left) <= cursorLeft && cursorLeft < Math.round(right);});
return {
id: cursorLine.id,
column: targetChar?
parseInt(targetChar.className.replace(/c-(\d+)/,'$1')) :
chars.length, //
};
}

#2020-12-24 04:22:51
#2020-11-21 23:17:45