Skip to content

refactor: Use range exported from @core/iterutil/range #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions browser/dom/edit.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 });
}
};
Expand Down Expand Up @@ -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 });
}
};
Expand All @@ -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 });
}
};
Expand All @@ -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 });
}
};
Expand Down
14 changes: 7 additions & 7 deletions browser/dom/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,7 +38,7 @@ export const focusEnd = async (holding = 1000): Promise<void> => {
* @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");
}
};
Expand All @@ -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");
}
};
Expand All @@ -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");
}
};
Expand All @@ -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");
}
};
Expand Down Expand Up @@ -193,7 +193,7 @@ export const scrollHalfDown = async (count = 1): Promise<void> => {
* @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");
}
};
Expand All @@ -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");
}
};
22 changes: 0 additions & 22 deletions range.test.ts

This file was deleted.

5 changes: 0 additions & 5 deletions range.ts

This file was deleted.