scrapbox-cursor-position-4
Next version:
/icons/hr.icon
scrapboxのcursorの縦棒の位置を取得する関数
返り値
code:ts
type Return = {
left?: CharObject; // cursorの左側のDOM
right?: CharObject; // cursorの右側のDOM
line: LineObject; // cursorのいる行
};
cursorの縦棒の位置が特定できなかったらline以外undefinedとなる
dependencies
code:script.js
import {char as c} from '/api/code/takker/scrapbox-char-accessor/script.js';
import {line as l} from '/api/code/takker/scrapbox-line-accessor/script.js';
import {getCharBorder} from '/api/code/takker/scrapbox-position/script.js';
import {scrapboxDOM} from '/api/code/takker/scrapbox-dom-accessor/script.js';
export const cursor = () => {
const origin = scrapboxDOM.editor.getBoundingClientRect();
const x = origin.left + parseInt(scrapboxDOM.cursor.style.left);
const y = origin.top + parseInt(scrapboxDOM.cursor.style.top);
2020-12-29
10:22:18 cursorが見えないときでも座標を取得できるようにした
code:script.js
const {left, right, line, message} = getCharBorder({x, y});
if (message) return {line: l(line), message};
return {left: c(left), right: c(right), line: l(line)};
};
テストコードtakker.icon
code:test.js
import {cursor} from '/api/code/takker/scrapbox-cursor-position-4/script.js';
document.addEventListener('keydown', () => {
const c = cursor();
});