|
6 | 6 | import PaneWithPanel from './PaneWithPanel.svelte'; |
7 | 7 | import Viewer from './Viewer.svelte'; |
8 | 8 | import { Editor, Workspace, type File } from 'editor'; |
9 | | - import { untrack } from 'svelte'; |
| 9 | + import { tick, untrack } from 'svelte'; |
10 | 10 | import { decode, type SourceMapSegment } from '@jridgewell/sourcemap-codec'; |
11 | 11 |
|
12 | 12 | interface Props { |
|
116 | 116 | output.highlight_range(null); |
117 | 117 | }; |
118 | 118 |
|
119 | | - workspace.onhover((pos) => { |
| 119 | + const from_input = (pos: number, should_scroll: boolean) => { |
120 | 120 | if (!current?.result?.[v]?.map) return; |
121 | 121 |
|
122 | 122 | const mappings = decode(current.result[v].map.mappings); |
|
138 | 138 |
|
139 | 139 | // if we're still here, we have a match |
140 | 140 | highlight(i, a, b); |
| 141 | +
|
| 142 | + if (should_scroll) { |
| 143 | + tick().then(() => { |
| 144 | + document.querySelector('#output .highlight').scrollIntoView({ |
| 145 | + block: 'center' |
| 146 | + }); |
| 147 | + }); |
| 148 | + } |
| 149 | +
|
141 | 150 | return; |
142 | 151 | } |
143 | 152 |
|
144 | 153 | clear(); |
145 | 154 | } |
146 | | - }); |
| 155 | + }; |
147 | 156 |
|
148 | | - output.onhover((pos) => { |
| 157 | + const from_output = (pos: number, should_scroll: boolean) => { |
149 | 158 | if (!current?.result?.[v]?.map) return; |
150 | 159 |
|
151 | 160 | const mappings = decode(current.result[v].map.mappings); |
|
160 | 169 |
|
161 | 170 | if (a[0] <= column && b[0] >= column) { |
162 | 171 | highlight(line, a, b); |
| 172 | +
|
| 173 | + if (should_scroll) { |
| 174 | + tick().then(() => { |
| 175 | + document.querySelector('#input .highlight').scrollIntoView({ |
| 176 | + block: 'center' |
| 177 | + }); |
| 178 | + }); |
| 179 | + } |
| 180 | +
|
163 | 181 | return; |
164 | 182 | } |
165 | 183 |
|
166 | 184 | clear(); |
167 | 185 | } |
168 | | - }); |
| 186 | + }; |
| 187 | +
|
| 188 | + workspace.onhover((pos) => from_input(pos, false)); |
| 189 | + workspace.onselect((from, to) => from === to && from_input(from, true)); |
| 190 | +
|
| 191 | + output.onhover((pos) => from_output(pos, false)); |
| 192 | + output.onselect((from, to) => from === to && from_output(from, true)); |
169 | 193 | } |
170 | 194 | }); |
171 | 195 | </script> |
|
0 commit comments