Skip to content

Commit

Permalink
feat: Enable Ctrl+Enter form submission (#60)
Browse files Browse the repository at this point in the history
fixes #60
  • Loading branch information
theotheo authored Oct 22, 2023
1 parent d912a54 commit 7f72122
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/FormModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,27 @@ export class FormModal extends Modal {
return exhaustiveGuard(type);
}
});

const submit = () => {
this.onSubmit(new FormResult(this.formResult, "ok"));
this.close();
}

new Setting(contentEl).addButton((btn) =>
btn
.setButtonText("Submit")
.setCta()
.onClick(() => {
this.onSubmit(new FormResult(this.formResult, "ok"));
this.close();
})
);
.onClick(submit)
)

const submitEnterCallback = (evt: KeyboardEvent) => {
if ((evt.ctrlKey || evt.metaKey) && evt.key === "Enter") {
evt.preventDefault();
submit();
}
};

contentEl.addEventListener("keydown", submitEnterCallback)
}

onClose() {
Expand Down

0 comments on commit 7f72122

Please sign in to comment.