generated at
scrapbox-cursor-position-6

position() {char, line} を取得する
char : cursorの左側の文字のDOM
ないときは undefined になる
line : cursorがいる行のDOM

known issue
カーソルがないとscrapbox-cursor-position-6#606ebb441280f0000000b7c7でエラーが発生する
座標値が無限になってしまう

dependencies
script.js
import {scrapboxDOM} from '../scrapbox-dom-accessor/script.js'; export function position({pos = 'right'} = {}) { const {top, left} = scrapboxDOM.editor.getBoundingClientRect(); // 基準座標 const style = scrapboxDOM.cursor.style; const cursor = { top: parseInt(style.top), left: parseInt(style.left), height: parseInt(style.height), }; const position = { x: cursor.left + left + 1, y: (cursor.top + top) + cursor.height / 2, }; const targets = document.elementsFromPoint(position.x, position.y); const char = targets.find(target => target.classList.contains('char-index')); const line = targets.find(target => target.classList.contains('line')); return {char, line}; };

test code
js
import('/api/code/takker/scrapbox-cursor-position-6/test.js');
test.js
import {scrapboxDOM} from '../scrapbox-dom-accessor/script.js'; import {position} from './script.js'; const observer = new MutationObserver(() => console.log(position())); observer.observe(scrapboxDOM.cursor, {attributes: true});


#2021-06-08 22:02:02
#2021-04-08 17:13:02