|
1 | 1 | <script lang="ts"> |
2 | 2 | import { marked } from 'marked'; |
| 3 | + import { locate } from 'locate-character'; |
3 | 4 | import AstView from './AstView.svelte'; |
4 | 5 | import CompilerOptions from './CompilerOptions.svelte'; |
5 | 6 | import PaneWithPanel from './PaneWithPanel.svelte'; |
|
90 | 91 |
|
91 | 92 | const lines = decode(current.result.js.map.mappings); |
92 | 93 |
|
93 | | - // TODO find the `line`/`column` corresponding to `pos` |
| 94 | + const { line, column } = locate(workspace.current.contents, pos)!; |
94 | 95 |
|
95 | | - for (const segments of lines) { |
96 | | - // TODO find the segment that corresponds to `line`/`column` |
| 96 | + for (let ai = 0; ai < lines.length; ai += 1) { |
| 97 | + const segments = lines[ai]; |
| 98 | + for (let j = 0; j < segments.length; j += 1) { |
| 99 | + let bi = ai; |
| 100 | +
|
| 101 | + const a = segments[j]; |
| 102 | + const b = segments[j + 1] ?? lines[++bi][0]; |
| 103 | +
|
| 104 | + if (!b) continue; |
| 105 | +
|
| 106 | + if (a[2] > line) continue; |
| 107 | + if (b[2] < line) continue; |
| 108 | +
|
| 109 | + if (a[2] === line && a[3] > column) continue; |
| 110 | + if (b[2] === line && b[3] < column) continue; |
| 111 | +
|
| 112 | + // if we're still here, we have a match |
| 113 | + const split = { |
| 114 | + original: workspace.current.contents.split('\n'), |
| 115 | + generated: current.result.js.code.split('\n') |
| 116 | + }; |
| 117 | +
|
| 118 | + const original = { |
| 119 | + start: split.original.slice(0, a[2]).join('\n').length + 1 + a[3], |
| 120 | + end: split.original.slice(0, b[2]).join('\n').length + 1 + b[3] |
| 121 | + }; |
| 122 | +
|
| 123 | + const generated = { |
| 124 | + start: split.generated.slice(0, ai).join('\n').length + 1 + a[0], |
| 125 | + end: split.generated.slice(0, bi).join('\n').length + 1 + b[0] |
| 126 | + }; |
| 127 | +
|
| 128 | + workspace.highlight_range(original); |
| 129 | + js_workspace.highlight_range(generated); |
| 130 | + return; |
| 131 | + } |
| 132 | +
|
| 133 | + workspace.highlight_range(null); |
| 134 | + js_workspace.highlight_range(null); |
97 | 135 | } |
98 | 136 | }); |
99 | 137 |
|
|
0 commit comments