Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/ha-code-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class HaCodeEditor extends UpdatingElement {

protected firstUpdated(changedProps: PropertyValues): void {
super.firstUpdated(changedProps);
this._blockKeyboardShortcuts();
this._load();
}

Expand Down Expand Up @@ -232,6 +233,10 @@ export class HaCodeEditor extends UpdatingElement {
this.codemirror!.on("changes", () => this._onChange());
}

private _blockKeyboardShortcuts() {
this.addEventListener("keydown", (ev) => ev.stopPropagation());
}

private _onChange(): void {
const newValue = this.value;
if (newValue === this._value) {
Expand Down
37 changes: 29 additions & 8 deletions src/state/quick-bar-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,41 @@ export default <T extends Constructor<HassElement>>(superClass: T) =>
}

private _showQuickBar(e: KeyboardEvent, commandMode = false) {
if (
!this.hass?.user?.is_admin ||
!this.hass.enableShortcuts ||
this._inInputField(e)
) {
if (!this._canShowQuickBar(e)) {
return;
}

showQuickBar(this, { commandMode });
}

private _inInputField(e: KeyboardEvent) {
return ["INPUT", "TEXTAREA"].includes(
(e.composedPath()[0] as HTMLElement).tagName
private _canShowQuickBar(e: KeyboardEvent) {
return (
this.hass?.user?.is_admin &&
this.hass.enableShortcuts &&
this._canOverrideAlphanumericInput(e)
);
}

private _canOverrideAlphanumericInput(e: KeyboardEvent) {
const el = e.composedPath()[0] as any;

if (el.tagName === "TEXTAREA") {
return false;
}

if (el.tagName !== "INPUT") {
return true;
}

switch (el.type) {
case "button":
case "checkbox":
case "hidden":
case "radio":
case "range":
return true;
default:
return false;
}
}
};