Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

online_editor: Code navigation between files #1709

Merged
merged 2 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions tools/online_editor/src/editor_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
} from "vscode-languageserver-protocol/browser";

import { commands } from "vscode";
import { StandaloneServices, ICodeEditorService } from "vscode/services";

interface ModelAndViewState {
model: monaco.editor.ITextModel;
Expand Down Expand Up @@ -306,6 +307,32 @@ class EditorPaneWidget extends Widget {
});
MonacoServices.install();

const code_editor_service = StandaloneServices.get(ICodeEditorService);
this.#disposables.push(
code_editor_service.registerCodeEditorOpenHandler(
(
{ resource, options },
source: monaco.editor.ICodeEditor | null,
_sideBySide?: boolean,
): Promise<monaco.editor.ICodeEditor | null> => {
if (editor == null) {
return Promise.resolve(editor);
}

if (!this.set_model(resource.toString())) {
return Promise.resolve(null);
Comment on lines +314 to +323
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think url would be a more readable name :). Maybe set_model could also be renamed to set_current_url since it does take a url as a parameter and only internally uses the models.

Suggested change
{ resource, options },
source: monaco.editor.ICodeEditor | null,
_sideBySide?: boolean,
): Promise<monaco.editor.ICodeEditor | null> => {
if (editor == null) {
return Promise.resolve(editor);
}
if (!this.set_model(resource.toString())) {
return Promise.resolve(null);
{ resource: url, options },
source: monaco.editor.ICodeEditor | null,
_sideBySide?: boolean,
): Promise<monaco.editor.ICodeEditor | null> => {
if (editor == null) {
return Promise.resolve(editor);
}
if (!this.set_model(url.toString())) {
return Promise.resolve(null);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that should change, but not as part of this patch: There are several methods that have Model in their name and they all should change.

I also want to use Url directly over converting that to and from string in several places.

}

if (options != null && options.selection != undefined) {
editor.setSelection(options.selection as monaco.IRange);
editor.revealLine(options.selection.startLineNumber);
}

return Promise.resolve(source);
},
),
);

const editor = monaco.editor.create(container, {
language: "slint",
glyphMargin: true,
Expand Down
2 changes: 0 additions & 2 deletions tools/online_editor/src/preview_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export class PreviewWidget extends Widget {
this.title.caption = `Slint Viewer`;
this.title.closable = true;

console.log("Event loop running?", is_event_loop_running);

this.#canvas_id = "";
this.#instance = null;
this.#resolve_attached_to_dom = () => {
Expand Down