import {selection} from '/api/code/takker/scrapbox-selection-2/script.js'; import {scrapboxDOM} from '/api/code/takker/scrapbox-dom-accessor/script.js'; import {goLine, goHead, enterEdit, upLines} from '/api/code/takker/scrapbox-edit-emulation/script.js'; import {line as l} from '/api/code/takker/scrapbox-line-info-2/script.js'; import {press} from '/api/code/takker/scrapbox-keyboard-emulation-2/script.js'; import {insertText} from '/api/code/takker/scrapbox-insert-text/script.js'; export async function sortLines() { const sortedLineDOMs = scrapbox.Page.lines .slice(startNo, 1 + endNo) .map((line, i) => {return {lineDOM: scrapboxDOM.lines.children[i + startNo], text: line.text}}) .sort((a,b)=>new Intl.Collator().compare(a.text,b.text)) .map(({lineDOM}) => lineDOM); // 一番上から順に入れ替え作業をする let insertPosition = startNo; for (const lineDOM of sortedLineDOMs) { const presentPosition = l(lineDOM).index; // 現在の行の位置 if (presentPosition !== insertPosition) { goLine({index: presentPosition}); await sleep(10); upLines(presentPosition - insertPosition); } insertPosition++; } } const sleep = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));