Skip to content

Commit 24d3344

Browse files
committed
highlight on select, scroll into view
1 parent 130d6ed commit 24d3344

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

packages/repl/src/lib/Output/Output.svelte

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import PaneWithPanel from './PaneWithPanel.svelte';
77
import Viewer from './Viewer.svelte';
88
import { Editor, Workspace, type File } from 'editor';
9-
import { untrack } from 'svelte';
9+
import { tick, untrack } from 'svelte';
1010
import { decode, type SourceMapSegment } from '@jridgewell/sourcemap-codec';
1111
1212
interface Props {
@@ -116,7 +116,7 @@
116116
output.highlight_range(null);
117117
};
118118
119-
workspace.onhover((pos) => {
119+
const from_input = (pos: number, should_scroll: boolean) => {
120120
if (!current?.result?.[v]?.map) return;
121121
122122
const mappings = decode(current.result[v].map.mappings);
@@ -138,14 +138,23 @@
138138
139139
// if we're still here, we have a match
140140
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+
141150
return;
142151
}
143152
144153
clear();
145154
}
146-
});
155+
};
147156
148-
output.onhover((pos) => {
157+
const from_output = (pos: number, should_scroll: boolean) => {
149158
if (!current?.result?.[v]?.map) return;
150159
151160
const mappings = decode(current.result[v].map.mappings);
@@ -160,12 +169,27 @@
160169
161170
if (a[0] <= column && b[0] >= column) {
162171
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+
163181
return;
164182
}
165183
166184
clear();
167185
}
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));
169193
}
170194
});
171195
</script>

packages/repl/src/lib/Repl.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@
176176
max="-4.1rem"
177177
>
178178
{#snippet a()}
179-
<section>
179+
<section id="input">
180180
<ComponentSelector {runes} {onchange} {workspace} {can_migrate} />
181181

182182
<Editor {workspace} />
183183
</section>
184184
{/snippet}
185185

186186
{#snippet b()}
187-
<section>
187+
<section id="output">
188188
<Output
189189
status={status_visible ? status : null}
190190
{embedded}

0 commit comments

Comments
 (0)