mirror of
https://github.com/talwrii/plugin-repl.git
synced 2026-07-22 11:40:27 +00:00
31 lines
1 KiB
TypeScript
31 lines
1 KiB
TypeScript
import { App, Modal, Setting } from 'obsidian';
|
|
|
|
export class PromptStringModal extends Modal {
|
|
constructor(app: App, prompt: string, onSubmit: [resolve: (_: any) => void, reject: (_: any) => void]) {
|
|
super(app);
|
|
this.setTitle(prompt);
|
|
let [resolve, reject] = onSubmit
|
|
|
|
let enterDown = false;
|
|
let result = '';
|
|
new Setting(this.contentEl)
|
|
.setName(prompt)
|
|
.addText((text: any) => {
|
|
text.inputEl.addEventListener("keydown", ({ key }) => {
|
|
if (key === 'Enter') {
|
|
enterDown = true
|
|
}
|
|
})
|
|
text.inputEl.addEventListener("keyup", ({ key }) => {
|
|
if ((key === 'Enter') && enterDown) {
|
|
this.close()
|
|
resolve(result)
|
|
return true
|
|
}
|
|
})
|
|
text.onChange((value: any) => {
|
|
result = value;
|
|
});
|
|
})
|
|
}
|
|
}
|