MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / clampCodeCursor

Function clampCodeCursor

scripts/hsr/widget-code-editor-state.mjs:17–30  ·  view source on GitHub ↗
(lines, cursor)

Source from the content-addressed store, hash-verified

15}
16
17export function clampCodeCursor(lines, cursor) {
18 const safeLines = splitCodeDraft(joinCodeLines(lines));
19 const lineCount = safeLines.length;
20 const rawLine =
21 typeof cursor?.line === "number" && Number.isFinite(cursor.line) ? Math.floor(cursor.line) : 0;
22 const line = Math.max(0, Math.min(rawLine, lineCount - 1));
23 const lineText = safeLines[line] ?? "";
24 const rawColumn =
25 typeof cursor?.column === "number" && Number.isFinite(cursor.column)
26 ? Math.floor(cursor.column)
27 : lineText.length;
28 const column = Math.max(0, Math.min(rawColumn, lineText.length));
29 return Object.freeze({ line, column });
30}
31
32export function findBannerCursor(lines) {
33 const safeLines = splitCodeDraft(joinCodeLines(lines));

Callers 5

buildViewFunction · 0.90
normalizeCodeSelectionFunction · 0.90
renderEditorPanelFunction · 0.90
createCodeEditorStateFunction · 0.85

Calls 2

splitCodeDraftFunction · 0.85
joinCodeLinesFunction · 0.85

Tested by

no test coverage detected