| 63 | |
| 64 | // Full lines covered by `sel`; excludes the trailing line if `sel.end` sits exactly past a `\n`. |
| 65 | const lineRange = (text, sel) => { |
| 66 | const start = text.lastIndexOf('\n', sel.start - 1) + 1; |
| 67 | const anchor = (sel.end > sel.start && text[sel.end - 1] === '\n') ? sel.end - 1 : sel.end; |
| 68 | let end = text.indexOf('\n', anchor); |
| 69 | if (end === -1) end = text.length; |
| 70 | return { start, end }; |
| 71 | }; |
| 72 | |
| 73 | // Strip common leading-whitespace from non-empty lines so a snippet pasted from deeper context lands flush. |
| 74 | const dedentCommon = (s) => { |