(lines)
| 30 | } |
| 31 | |
| 32 | export function findBannerCursor(lines) { |
| 33 | const safeLines = splitCodeDraft(joinCodeLines(lines)); |
| 34 | for (let index = 0; index < safeLines.length; index++) { |
| 35 | const line = safeLines[index] ?? ""; |
| 36 | const marker = "SELF_EDIT_BANNER"; |
| 37 | const markerIndex = line.indexOf(marker); |
| 38 | if (markerIndex === -1) continue; |
| 39 | const equalsIndex = line.indexOf("=", markerIndex + marker.length); |
| 40 | if (equalsIndex === -1) continue; |
| 41 | |
| 42 | for (const quote of ['"', "'", "`"]) { |
| 43 | const openQuote = line.indexOf(quote, equalsIndex + 1); |
| 44 | if (openQuote === -1) continue; |
| 45 | const closeQuote = line.indexOf(quote, openQuote + 1); |
| 46 | const column = closeQuote === -1 ? openQuote + 1 : closeQuote; |
| 47 | return Object.freeze({ line: index, column }); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | const fallbackLine = Math.max(0, safeLines.length - 1); |
| 52 | return Object.freeze({ |
| 53 | line: fallbackLine, |
| 54 | column: (safeLines[fallbackLine] ?? "").length, |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | export function createCodeEditorState(draft, options = {}) { |
| 59 | const lines = splitCodeDraft(draft); |
no test coverage detected