-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Indent-based folds for YAML editor #21966
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,10 +123,14 @@ export class HaCodeEditor extends ReactiveElement { | |
} | ||
const transactions: TransactionSpec[] = []; | ||
if (changedProps.has("mode")) { | ||
// TODO: not sure how to handle things here | ||
transactions.push({ | ||
effects: this._loadedCodeMirror!.langCompartment!.reconfigure( | ||
this._mode | ||
), | ||
effects: [ | ||
this._loadedCodeMirror!.langCompartment!.reconfigure(this._mode), | ||
this._loadedCodeMirror!.foldingCompartment.reconfigure( | ||
this._getFoldingExtensions() | ||
), | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reconfiguring folding compartment on mode change looks good, but consider removing the TODO comment. I see that you have implemented the suggestion to reconfigure the folding compartment alongside the language compartment when the mode changes. This looks good to me. However, the TODO comment is still present, indicating that you might still be unsure about the handling of mode changes. If you are satisfied with the current implementation, consider removing the TODO comment to avoid confusion. If you need further guidance on handling mode changes, please let me know, and I'll be happy to assist you. |
||
}); | ||
} | ||
if (changedProps.has("readOnly")) { | ||
|
@@ -194,6 +198,9 @@ export class HaCodeEditor extends ReactiveElement { | |
this.linewrap ? this._loadedCodeMirror.EditorView.lineWrapping : [] | ||
), | ||
this._loadedCodeMirror.EditorView.updateListener.of(this._onUpdate), | ||
this._loadedCodeMirror.foldingCompartment.of( | ||
this._getFoldingExtensions() | ||
), | ||
]; | ||
|
||
if (!this.readOnly) { | ||
|
@@ -311,6 +318,17 @@ export class HaCodeEditor extends ReactiveElement { | |
fireEvent(this, "value-changed", { value: this._value }); | ||
}; | ||
|
||
private _getFoldingExtensions = (): Extension => { | ||
if (this.mode === "yaml") { | ||
return [ | ||
this._loadedCodeMirror!.foldGutter(), | ||
this._loadedCodeMirror!.foldingOnIndent, | ||
]; | ||
} | ||
|
||
return []; | ||
}; | ||
|
||
static get styles(): CSSResultGroup { | ||
return css` | ||
:host(.error-state) .cm-gutters { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left this as a note so I wouldn't forget. I probably need some guidance here. Not sure if/how to handle mode changes
can mode changes even occur at all? I assume we need to check if mode changed to/from yaml, and disable/enable the added extensions accordingly, but not sure how to go about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would need to make it a compartment, so you can reconfigure it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it. will take a look at that, thanks