diff --git a/src/localization/source/en/commands/add_comment.yaml b/src/localization/source/en/commands/add_comment.yaml new file mode 100644 index 0000000..ee932cf --- /dev/null +++ b/src/localization/source/en/commands/add_comment.yaml @@ -0,0 +1,2 @@ +name: Add comment to Jira +error: Error adding comment diff --git a/src/localization/source/en/modals/comment.yaml b/src/localization/source/en/modals/comment.yaml new file mode 100644 index 0000000..2446703 --- /dev/null +++ b/src/localization/source/en/modals/comment.yaml @@ -0,0 +1,11 @@ +name: Add Jira comment + +body: + name: Comment + desc: "Write your comment here, or select text in the editor before running this command to pre-fill it" + placeholder: "Write your comment here. Tip: select text in the editor before running this command to pre-fill." + +submit: Submit + +warns: + empty: Comment cannot be empty diff --git a/src/localization/source/ru/commands/add_comment.yaml b/src/localization/source/ru/commands/add_comment.yaml new file mode 100644 index 0000000..ee932cf --- /dev/null +++ b/src/localization/source/ru/commands/add_comment.yaml @@ -0,0 +1,2 @@ +name: Add comment to Jira +error: Error adding comment diff --git a/src/localization/source/ru/modals/comment.yaml b/src/localization/source/ru/modals/comment.yaml new file mode 100644 index 0000000..2446703 --- /dev/null +++ b/src/localization/source/ru/modals/comment.yaml @@ -0,0 +1,11 @@ +name: Add Jira comment + +body: + name: Comment + desc: "Write your comment here, or select text in the editor before running this command to pre-fill it" + placeholder: "Write your comment here. Tip: select text in the editor before running this command to pre-fill." + +submit: Submit + +warns: + empty: Comment cannot be empty diff --git a/src/modals/IssueCommentModal.ts b/src/modals/IssueCommentModal.ts index 575d3c8..fda25c3 100644 --- a/src/modals/IssueCommentModal.ts +++ b/src/modals/IssueCommentModal.ts @@ -1,4 +1,4 @@ -import {App, Modal, Notice, Setting} from "obsidian"; +import {App, Modal, Notice, Setting, TextAreaComponent} from "obsidian"; import {useTranslations} from "../localization/translator"; const t = useTranslations("modals.comment").t; @@ -20,31 +20,37 @@ export class IssueCommentModal extends Modal { onOpen() { new Setting(this.contentEl).setName(t("name")).setHeading(); - new Setting(this.contentEl) - .setName(t("body.name")) - .addTextArea((text) => { - text - .setValue(this.commentText) - .onChange((value) => { - this.commentText = value; - }); - text.inputEl.rows = 10; - text.inputEl.style.width = "100%"; + const textarea = new TextAreaComponent(this.contentEl) + .setPlaceholder(t("body.placeholder")) + .setValue(this.commentText) + .onChange((value) => { + this.commentText = value; }); + textarea.inputEl.rows = 10; + textarea.inputEl.style.width = "100%"; + textarea.inputEl.style.marginBottom = "0.75em"; + textarea.inputEl.addEventListener("keydown", (e) => { + if (e.ctrlKey && e.key === "Enter") { + e.preventDefault(); + this.submit(); + } + }); new Setting(this.contentEl) .addButton((btn) => btn .setButtonText(t("submit")) .setCta() - .onClick(() => { - if (!this.commentText.trim()) { - new Notice(t("warns.empty")); - return; - } - this.close(); - this.onSubmit(this.commentText); - }) + .onClick(() => this.submit()) ); } + + private submit() { + if (!this.commentText.trim()) { + new Notice(t("warns.empty")); + return; + } + this.close(); + this.onSubmit(this.commentText); + } }