Skip to content

Commit

Permalink
feat: (to test) API UI prompt() large text field submits on enter + m…
Browse files Browse the repository at this point in the history
…odifier
  • Loading branch information
chrisgurney committed Jan 28, 2025
1 parent f9cc048 commit c501176
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Api/PromptModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,24 @@ export class PromptModal extends Modal {
if (this.large) {
textInput = new TextAreaComponent(div);

// listen for submit on enter with modifier key
this.plugin.registerDomEvent(
textInput.inputEl, 'keydown', (e: KeyboardEvent) => {
if (e.key === 'enter') {
const modifierPressed = (Platform.isWin || Platform.isLinux) ? e?.ctrlKey : e?.metaKey;
console.log('enter', modifierPressed);
this.resolveAndClose(e);
}
}
);

// add submit button since enter needed for multiline input on mobile
const buttonDiv = this.contentEl.createDiv();
buttonDiv.addClass('note-toolbar-ui-button-div');
const submitButton = new ButtonComponent(buttonDiv);
submitButton.buttonEl.addClass("mod-cta");
submitButton.setButtonText(t('api.ui.button-submit')).onClick((evt: Event) => {
this.resolveAndClose(evt);
submitButton.setButtonText(t('api.ui.button-submit')).onClick((e: Event) => {
this.resolveAndClose(e);
});
} else {
textInput = new TextComponent(div);
Expand Down

0 comments on commit c501176

Please sign in to comment.