Skip to content

Commit 6dc2924

Browse files
committed
✨ library中でscrapbox.Page.linesを呼び出している箇所をgetCachedLines()に置き換えた
1 parent e1ccbd4 commit 6dc2924

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

browser/dom/node.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// <reference lib="dom" />
44
import { isNone, isNumber, isString } from "../../is.ts";
55
import { ensureArray } from "../../ensure.ts";
6+
import { getCachedLines } from "./getCachedLines.ts";
67
import type { Line, Scrapbox } from "../../deps/scrapbox.ts";
78
import { lines } from "./dom.ts";
89
import * as Text from "../../text.ts";
@@ -83,9 +84,10 @@ export const isLineDOM = (dom: unknown): dom is HTMLDivElement =>
8384

8485
export const getLineCount = (): number => getLines().length;
8586

86-
export const getLines = (): Line[] => {
87-
ensureArray(scrapbox.Page.lines, "scrapbox.Page.lines");
88-
return scrapbox.Page.lines;
87+
export const getLines = (): readonly Line[] => {
88+
const lines = getCachedLines();
89+
ensureArray<Line>(lines, "scrapbox.Page.lines");
90+
return lines;
8991
};
9092

9193
export const getText = <T extends HTMLElement>(

text.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const getIndentCount = (text: string): number =>
1010
*/
1111
export function getIndentLineCount(
1212
index: number,
13-
lines: string[] | { text: string }[],
13+
lines: readonly string[] | readonly { text: string }[],
1414
): number {
1515
const base = getIndentCount(getText(index, lines));
1616
let count = 0;
@@ -23,7 +23,10 @@ export function getIndentLineCount(
2323
return count;
2424
}
2525

26-
function getText(index: number, lines: string[] | { text: string }[]) {
26+
function getText(
27+
index: number,
28+
lines: readonly string[] | readonly { text: string }[],
29+
) {
2730
const line = lines[index];
2831
return isString(line) ? line : line.text;
2932
}

0 commit comments

Comments
 (0)