Skip to content

differentiate notebook moving to new group and splitting #98607

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

Merged
merged 9 commits into from
May 29, 2020

Conversation

rebornix
Copy link
Member

@bpasero the short summary for the PR is differentiating Move Editor to New Group and Splitting Editors. Please let me know if there is any better way to archive the same thing.

Currently EditorOverride doesn't have enough information about whether users are splitting an editor or just moving an editor to another editor group. It's fine for Monaco Editor as recreating the view/models for the editor is cheap while for Notebook (and potentially any editor using webview), we can't do that as recreating a new editor means the intermediate of the webview is lost.

The workflow for moving an editor to a new group

- editorGroupView.openEditor(input, options)
  - editorOverride.open(input, options)
  - NotebookEditor.setInput()
    - new `NotebookEditorWidget`
- editorGroupView.closeEditor(input)

For moving notebook editor to a new group, we want to reuse the NotebookEditorWidget referenced in previous Notebook Editor, however we don't know if it's safe to do so as editorGroupView.closeEditor(input) happens after we create the new editor in the new group. In this PR, I tried to give this information to EditorOverride and they can decide if they should create a complete new editor or not.

// NotebookRegistry.releaseNotebookEditorWidget(originalInput);
// NotebookRegistry.claimNotebookEditorWidget(copiedInput, widgetRef);
// }
if (!options?.shouldCreateNewWhenOverride) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@bpasero here we check if it's splitting or moving by reading shouldCreateNewWhenOverride, if it's just moving the editor, the new editor input will claim ownership of the NotebookEditorWidget (which is a detached DOM node).
Write

@bpasero bpasero assigned rebornix and unassigned bpasero May 27, 2020
@bpasero bpasero self-requested a review May 27, 2020 09:43
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

I am not a big fan of adding a new editor option that is only being set internally from the editor group view. The intent of editor options is to use them from the outside when opening an editor, but not hide internals in there.

Wouldn't it make more sense to maybe add some kind of context to the editor override facilities that tell you why an editor is opening and then act accordingly? That seems like the right place to me to put this kind of information.

@rebornix
Copy link
Member Author

@bpasero thanks for the feedback, makes sense that we should not pollute the EditorOptions as it's widely used.

The move/copy knowledge is inside the EditorGroupView and the knowledge needs to be transferred from group to another when opening a new editor in a new group, I'd like to propose following changes, considering now how editor override works.

Firstly, the info is transferred through openEditor:

export interface IEditorGroup {
-	 openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions): Promise<IEditorPane | null>;
+        openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, keepCopy?: boolean): Promise<IEditorPane | null>;
}

and then we pass the info to editorOverrides

async openEditor(editor: EditorInput, options?: EditorOptions, keepCopy?: boolean): Promise<IEditorPane | null> {

		// Guard against invalid inputs
		if (!editor) {
			return null;
		}

		// Editor opening event allows for prevention
-		const event = new EditorOpeningEvent(this._group.id, editor, options);
+		const event = new EditorOpeningEvent(this._group.id, editor, options, keepCopy);
		this._onWillOpenEditor.fire(event);
		const prevented = event.isPrevented();
		if (prevented) {
			return withUndefinedAsNull(await prevented());
		}

		// Proceed with opening
		return withUndefinedAsNull(await this.doOpenEditor(editor, options));
	}

and lastly this._onWillOpenEditor.fire(event); will trigger the editor overrides, which is the current design.

@bpasero how do you like it now? The challenge here is editor overrides are triggered when an editor is opened
in the group view (through onWillOpenEditor event), it means that the group needs to know that if an editor is "move" or "copy".

@bpasero
Copy link
Member

bpasero commented May 27, 2020

@rebornix Maybe not a bare keepCopy boolean but a context enum that indicates the source of operation? Similar to this:

reason?: SaveReason;

@rebornix
Copy link
Member Author

Yes, an enum is better. I'll update the PR>

@rebornix rebornix requested a review from bpasero May 27, 2020 18:46
@rebornix
Copy link
Member Author

OpenEditorInGroupContext enum is introduced to indicate the reason how the editor is opened in the new group. We may want to extend to something like { reason, balaba } if later on we want to extend the context.

@rebornix rebornix added this to the May 2020 milestone May 27, 2020
@rebornix rebornix mentioned this pull request May 27, 2020
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

Overall good with me, some polish maybe:

  • OpenEditorInGroupContext => OpenEditorContext
  • the enum should initialize its first value to be 1 and not 0 so that we prevent bad checks
  • I see no tests that verify the event carries the proper context, please add it

@rebornix rebornix merged commit ebdff39 into master May 29, 2020
@rebornix rebornix deleted the rebornix/notebookMoveNSplit branch May 29, 2020 17:15
@github-actions github-actions bot locked and limited conversation to collaborators Jul 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants