diff --git a/browser/dom/edit.ts b/browser/dom/edit.ts index e08fc33..e292c02 100644 --- a/browser/dom/edit.ts +++ b/browser/dom/edit.ts @@ -1,7 +1,7 @@ import { goHead, goLine } from "./motion.ts"; import { press } from "./press.ts"; import { getLineCount } from "./node.ts"; -import { range } from "../../range.ts"; +import { range } from "@core/iterutil/range"; import { textInput } from "./dom.ts"; import { isArray } from "@core/unknownutil/is/array"; import { isNumber } from "@core/unknownutil/is/number"; @@ -10,24 +10,24 @@ import type { Scrapbox } from "@cosense/types/userscript"; declare const scrapbox: Scrapbox; export const undo = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("z", { ctrlKey: true }); } }; export const redo = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("z", { shiftKey: true, ctrlKey: true }); } }; export const insertIcon = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("i", { ctrlKey: true }); } }; export const insertTimestamp = (index = 1): void => { - for (const _ of range(0, index)) { + for (const _ of range(1, index)) { press("t", { altKey: true }); } }; @@ -94,12 +94,12 @@ export const deleteLines = async ( }; export const indentLines = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowRight", { ctrlKey: true }); } }; export const outdentLines = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowLeft", { ctrlKey: true }); } }; @@ -120,23 +120,23 @@ export const moveLinesBefore = (from: number, to: number): void => { } }; export const upLines = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowUp", { ctrlKey: true }); } }; export const downLines = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowDown", { ctrlKey: true }); } }; export const indentBlocks = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowRight", { altKey: true }); } }; export const outdentBlocks = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowLeft", { altKey: true }); } }; @@ -148,12 +148,12 @@ export const moveBlocks = (count: number): void => { } }; export const upBlocks = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowUp", { altKey: true }); } }; export const downBlocks = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowDown", { altKey: true }); } }; diff --git a/browser/dom/motion.ts b/browser/dom/motion.ts index f86c553..61f1f47 100644 --- a/browser/dom/motion.ts +++ b/browser/dom/motion.ts @@ -12,7 +12,7 @@ import { } from "./node.ts"; import { caret } from "./caret.ts"; import { isHeightViewable } from "./isHeightViewable.ts"; -import { range } from "../../range.ts"; +import { range } from "@core/iterutil/range"; /** @deprecated * Long press at the end of cursor line to gain focus @@ -38,7 +38,7 @@ export const focusEnd = async (holding = 1000): Promise => { * @param [count=1] - Number of moves to perform */ export const moveLeft = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowLeft"); } }; @@ -47,7 +47,7 @@ export const moveLeft = (count = 1): void => { * @param [count=1] - Number of moves to perform */ export const moveUp = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowUp"); } }; @@ -56,7 +56,7 @@ export const moveUp = (count = 1): void => { * @param [count=1] - Number of moves to perform */ export const moveDown = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowDown"); } }; @@ -65,7 +65,7 @@ export const moveDown = (count = 1): void => { * @param [count=1] - Number of moves to perform */ export const moveRight = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("ArrowRight"); } }; @@ -193,7 +193,7 @@ export const scrollHalfDown = async (count = 1): Promise => { * @param [count=1] - Number of scroll operations to perform */ export const scrollUp = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("PageUp"); } }; @@ -202,7 +202,7 @@ export const scrollUp = (count = 1): void => { * @param [count=1] - Number of scroll operations to perform */ export const scrollDown = (count = 1): void => { - for (const _ of range(0, count)) { + for (const _ of range(1, count)) { press("PageDown"); } }; diff --git a/range.test.ts b/range.test.ts deleted file mode 100644 index 047841f..0000000 --- a/range.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { range } from "./range.ts"; -import { assertStrictEquals } from "@std/assert"; - -Deno.test("range()", () => { - let count = 0; - for (const i of range(0, 10)) { - assertStrictEquals(i, count++); - } - assertStrictEquals(10, count); - - count = 5; - for (const i of range(5, 12)) { - assertStrictEquals(i, count++); - } - assertStrictEquals(12, count); - - count = 0; - for (const i of range(5, 5)) { - assertStrictEquals(i, count++); - } - assertStrictEquals(0, count); -}); diff --git a/range.ts b/range.ts deleted file mode 100644 index 37258c7..0000000 --- a/range.ts +++ /dev/null @@ -1,5 +0,0 @@ -export function* range(start: number, end: number) { - for (let i = start; i < end; i++) { - yield i; - } -}