first commit

This commit is contained in:
douboer@gmail.com
2026-03-03 13:23:14 +08:00
commit 3b7c1d558a
161 changed files with 28120 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import type { IReactive } from "../base/reactivity";
/**
* Get current cursor position in a textbox
* https://stackoverflow.com/16105482/get-current-cursor-position-in-a-textbox
*/
// TODO: compatibility check
function getCursorPosition<T extends HTMLElement>(field: T): number {
if ("selectionStart" in field) {
return field.selectionStart as number;
}
return 0;
}
export function updateCursor(
el: HTMLTextAreaElement,
data: IReactive<string>,
ptr: IReactive<number>
) {
let pos = getCursorPosition(el);
const len = data.value.length;
if (pos > len) {
pos = len;
} else if (pos < 0) {
pos = 0;
}
ptr.value = pos;
}