Skip to content

Conversation

@dangmarm
Copy link
Collaborator

@dangmarm dangmarm commented Jun 17, 2024

Added ch-code-diff-editor component.

Breaking changes

  • Removed diff editor support from the ch-code-editor component. The diff editor support is now provided by the ch-code-diff-editor component.

@dangmarm dangmarm added feature Feature implementation pull request target: major This PR is targeted for the next major release breaking changes labels Jun 17, 2024
@netlify
Copy link

netlify bot commented Jun 17, 2024

Deploy Preview for gx-chameleon ready!

Name Link
🔨 Latest commit e58aa63
🔍 Latest deploy log https://app.netlify.com/sites/gx-chameleon/deploys/6671ecb45e61a0000868268e
😎 Deploy Preview https://deploy-preview-346--gx-chameleon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@dangmarm dangmarm requested a review from ncamera June 17, 2024 19:16
Copy link
Collaborator

@ncamera ncamera left a comment

Choose a reason for hiding this comment

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

Thanks! I leave some comments.

Comment on lines 50 to 57
@Prop() readonly options: CodeDiffEditorOptions = {
theme: this.theme,
automaticLayout: true,
mouseWheelScrollSensitivity: 4,
mouseWheelZoom: true,
enableSplitViewResizing: true,
renderSideBySide: true
};
Copy link
Collaborator

@ncamera ncamera Jun 17, 2024

Choose a reason for hiding this comment

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

I prefer to initialize this parameter in the connectedCallback lifecycle method. With that, we can sort the properties in alphabetical order and avoid issues in the future if the theme property is defined after the options property.

Another solution could be to remove the theme property from the CodeDiffEditorOptions type (using the Omit utility classes from TypeScript) and then extend the options object with the theme in the #setupDiffEditor method.

Comment on lines 48 to 54
@Prop() readonly options: CodeEditorOptions = {
theme: this.theme,
automaticLayout: true,
mouseWheelScrollSensitivity: 4,
mouseWheelZoom: true,
tabSize: 2
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as before.

Comment on lines 195 to 209
componentDidLoad() {
this.#configureYaml();
this.#setupDiffEditor();

this.#resizeObserver = new ResizeObserver(entries => {
const absoluteContentEntry = entries[0].contentRect;

this.#monacoDiffEditorInstance.layout({
width: absoluteContentEntry.width,
height: absoluteContentEntry.height
});
});

this.#resizeObserver.observe(this.#absoluteContentRef);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I notice that in the previous implementation we didn't disconnect the observer to avoid memory leaks. Can you add this change in the disconnectedCallback method?

For reference: https://github.com/genexuslabs/chameleon-controls-library/blob/main/src/components/popover/popover.tsx#L1067

this.#editorId = `ch-editor-${autoId++}`;
}

componentDidLoad() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as before for the memory leak.

Comment on lines 158 to 163
...(!(
"originalEditable" in this.options || "readOnly" in this.options
) && {
originalEditable: !this.readonly,
readOnly: this.readonly
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think is better to use the readonly property as the default value, even if one of the properties (originalEditable or readOnly) is defined. Otherwise, we have to specify the current behavior in the description of the readonly property.

Suggested change
...(!(
"originalEditable" in this.options || "readOnly" in this.options
) && {
originalEditable: !this.readonly,
readOnly: this.readonly
})
originalEditable: this.options.originalEditable ?? !this.readonly,
readOnly: this.options.readOnly ?? this.readonly

Comment on lines 66 to 69
this.#monacoDiffEditorInstance.updateOptions({
originalEditable: !newReadonly ?? true,
readOnly: newReadonly ?? false
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

This implementation should match the logic implemented in the #setupDiffEditor method.

@ncamera ncamera changed the title Add component ch-code-diff-editor Add component ch-code-diff-editor and refactoring the ch-code-editor interface Jun 17, 2024
@dangmarm dangmarm requested a review from ncamera June 18, 2024 18:41
Copy link
Collaborator

@ncamera ncamera left a comment

Choose a reason for hiding this comment

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

LGTM! Just two nits

Comment on lines 66 to 67
* If the ´readOnly´ or ´originalEditable´ property is specified in the ´options´ property,
* this property has no effect.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* If the ´readOnly´ or ´originalEditable´ property is specified in the ´options´ property,
* this property has no effect.
* If the `readOnly` or `originalEditable` property is specified in the `options` property,
* this property has no effect.

* - If `mode` === `"editor"` defaults to `false`.
* - If `mode` === `"diff-editor"` defaults to `true`.
* Specifies if the editor should be readonly.
* If the ´readOnly´ property is specified in the ´options´ property,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* If the ´readOnly´ property is specified in the ´options´ property,
* If the `readOnly` property is specified in the `options` property,

@dangmarm dangmarm merged commit adb2717 into main Jun 18, 2024
@dangmarm dangmarm deleted the add/ch-code-diff-editor branch June 18, 2024 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking changes feature Feature implementation pull request target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants