(draft, options = {})
| 56 | } |
| 57 | |
| 58 | export function createCodeEditorState(draft, options = {}) { |
| 59 | const lines = splitCodeDraft(draft); |
| 60 | const scrollTop = |
| 61 | typeof options.scrollTop === "number" && Number.isFinite(options.scrollTop) |
| 62 | ? Math.max(0, Math.floor(options.scrollTop)) |
| 63 | : 0; |
| 64 | const scrollLeft = |
| 65 | typeof options.scrollLeft === "number" && Number.isFinite(options.scrollLeft) |
| 66 | ? Math.max(0, Math.floor(options.scrollLeft)) |
| 67 | : 0; |
| 68 | |
| 69 | const preferredCursor = options.cursor ? clampCodeCursor(lines, options.cursor) : null; |
| 70 | const cursor = preferredCursor ?? findBannerCursor(lines); |
| 71 | |
| 72 | return Object.freeze({ |
| 73 | lines, |
| 74 | cursor, |
| 75 | selection: null, |
| 76 | scrollTop, |
| 77 | scrollLeft, |
| 78 | }); |
| 79 | } |
no test coverage detected