(lines, cursor)
| 15 | } |
| 16 | |
| 17 | export 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 | |
| 32 | export function findBannerCursor(lines) { |
| 33 | const safeLines = splitCodeDraft(joinCodeLines(lines)); |
no test coverage detected