alamion_obsidian-jira-sync/src/modals/IssueCommentModal.ts
slips 4958fc6a3c feat: add "Add comment to Jira" command with editor selection pre-fill
Opens a modal pre-populated with any selected editor text, allowing
users to highlight notes in a non-synced section and post them as a
Jira comment in one step. Supports API v2 (plain text) and v3 (ADF).
2026-04-27 17:11:59 -04:00

50 lines
1.2 KiB
TypeScript

import {App, Modal, Notice, Setting} from "obsidian";
import {useTranslations} from "../localization/translator";
const t = useTranslations("modals.comment").t;
/**
* Modal for adding a comment to a Jira issue.
* Pre-populated with any text that was selected in the editor when the command was invoked.
*/
export class IssueCommentModal extends Modal {
private onSubmit: (commentText: string) => void;
private commentText: string;
constructor(app: App, initialText: string, onSubmit: (commentText: string) => void) {
super(app);
this.commentText = initialText;
this.onSubmit = onSubmit;
}
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%";
});
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);
})
);
}
}