Skip to content

Commit d30dfc0

Browse files
committed
slintpad: Always show preview when the first editor is opened
This makes sure we always have soemthing in the preview.
1 parent f6731eb commit d30dfc0

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tools/slintpad/src/editor_widget.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ export function initialize(): Promise<void> {
4848
...getConfigurationServiceOverride(),
4949
...getEditorServiceOverride(
5050
(model, _input, _side_by_side) => {
51-
return Promise.resolve(
52-
EDITOR_WIDGET!.open_model_ref(model),
53-
);
51+
return EDITOR_WIDGET!.open_model_ref(model);
5452
},
5553
),
5654
...getKeybindingsServiceOverride(),
@@ -390,12 +388,7 @@ export class EditorWidget extends Widget {
390388

391389
this.clear_editors();
392390

393-
this.open_default_content().then((uri) => {
394-
this.#client?.sendRequest("workspace/executeCommand", {
395-
command: "slint/showPreview",
396-
arguments: [uri?.toString() ?? "", ""],
397-
});
398-
});
391+
this.open_default_content();
399392
}
400393

401394
private async open_default_content() {
@@ -451,9 +444,9 @@ export class EditorWidget extends Widget {
451444
.then((model_ref) => this.open_model_ref(model_ref));
452445
}
453446

454-
public open_model_ref(
447+
public async open_model_ref(
455448
model_ref: IReference<ITextEditorModel>,
456-
): IStandaloneCodeEditor {
449+
): Promise<IStandaloneCodeEditor> {
457450
const pane = new EditorPaneWidget(model_ref);
458451
this.#tab_map.set(
459452
model_ref.object.textEditorModel?.uri ??
@@ -462,7 +455,17 @@ export class EditorWidget extends Widget {
462455
);
463456
this.#tab_panel!.addWidget(pane);
464457

465-
return pane.editor;
458+
if (this.#tab_map.size === 1) {
459+
await this.#client?.sendRequest("workspace/executeCommand", {
460+
command: "slint/showPreview",
461+
arguments: [
462+
model_ref.object.textEditorModel?.uri.toString() ?? "",
463+
"",
464+
],
465+
});
466+
}
467+
468+
return Promise.resolve(pane.editor);
466469
}
467470

468471
public async map_url(url_: string): Promise<string | undefined> {

0 commit comments

Comments
 (0)