Skip to content

Commit b98cb8e

Browse files
fix: migrate button, repl type and upgrade to ^5.0.0 (#474)
* fix: migrate button, repl type and upgrade to ^5.0.0 * chore: upgrade to 5 allover * chore run dedupe * fix: untrack current in `link` * fix: update state correctly --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 06747ec commit b98cb8e

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

apps/svelte.dev/src/routes/(authed)/playground/[id]/AppControls.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
interface Props {
1616
examples: Array<{ title: string; examples: any[] }>;
1717
user: User | null;
18-
repl: any; // TODO
18+
repl: ReturnType<typeof Repl>;
1919
gist: Gist;
2020
name: string;
2121
modified: boolean;
@@ -39,7 +39,7 @@
3939
let saving = $state(false);
4040
let justSaved = $state(false);
4141
let justForked = $state(false);
42-
let select: any; // TODO why can't i do `select: SelectIcon`?
42+
let select: ReturnType<typeof SelectIcon>;
4343
4444
function wait(ms: number) {
4545
return new Promise((f) => setTimeout(f, ms));

packages/editor/src/lib/Workspace.svelte.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { acceptCompletion } from '@codemirror/autocomplete';
1212
import { indentWithTab } from '@codemirror/commands';
1313
import { indentUnit } from '@codemirror/language';
1414
import { theme } from './theme';
15+
import { untrack } from 'svelte';
1516

1617
export interface File {
1718
type: 'file';
@@ -157,7 +158,7 @@ export class Workspace {
157158
if (this.#view) throw new Error('view is already linked');
158159
this.#view = view;
159160

160-
view.setState(this.#get_state(this.#current));
161+
view.setState(this.#get_state(untrack(() => this.#current)));
161162
}
162163

163164
move(from: Item, to: Item) {
@@ -195,7 +196,7 @@ export class Workspace {
195196
return true;
196197
});
197198

198-
this.#current = next;
199+
this.#select(next);
199200

200201
this.#onreset?.(this.#files);
201202
}
@@ -274,10 +275,9 @@ export class Workspace {
274275
if (!file) {
275276
throw new Error(`Invalid selection ${selected}`);
276277
}
277-
278-
this.#current = file as File;
278+
this.#select(file as File);
279279
} else {
280-
this.#current = first;
280+
this.#select(first);
281281
}
282282

283283
this.#files = files;
@@ -302,11 +302,7 @@ export class Workspace {
302302

303303
update_file(file: File) {
304304
if (file.name === this.#current.name) {
305-
// TODO this line causes the editor to keep losign
306-
// focus and I have no idea why. It seems important,
307-
// but it also doesn't appear to break anything
308-
// if we comment it out?
309-
// this.#current = file;
305+
this.#current = file;
310306
}
311307

312308
this.#files = this.#files.map((old) => {
@@ -455,11 +451,17 @@ export class Workspace {
455451
const existing = state.doc.toString();
456452

457453
if (file.contents !== existing) {
454+
const current_cursor_position = this.#view?.state.selection.ranges[0].from!;
455+
458456
const transaction = state.update({
459457
changes: {
460458
from: 0,
461459
to: existing.length,
462460
insert: file.contents
461+
},
462+
selection: {
463+
anchor: current_cursor_position,
464+
head: current_cursor_position
463465
}
464466
});
465467

0 commit comments

Comments
 (0)