Skip to content

Commit

Permalink
Implement press enter to submit
Browse files Browse the repository at this point in the history
  • Loading branch information
crybot committed May 30, 2024
1 parent 822061f commit 36b782f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This plugin integrates Large Language Models with Obsidian to help you generate

### Integration with OpenAI
- **Multiple Models**: Supports `gpt-3.5-turbo`, `gpt-4`, `gpt-4-turbo`, and `gpt-4o`. Configure your OpenAI API key in the plugin settings and select the desired model.
- **Flashcard Generation**: Generate flashcards from any open note using the `Generate Flashcards` command. The flashcards are appended to your note within a blockquote.
- **Flashcard Generation**: Generate flashcards from any open note using the available commands. The flashcards are appended to your note within a blockquote.

### Customization Options
- **Selective Content Generation**: Choose to generate flashcards from a specific selection of your note or the entire note.
Expand All @@ -22,6 +22,7 @@ This plugin integrates Large Language Models with Obsidian to help you generate
- **Hide flashcards in preview mode**: Toggle this setting to hide the generated flashcards during preview.
If this is on, set `Save scheduling comment on the same line as the flashcard's last line` to on in
the Spaced Repetition plugin as well, in order not to break the blockquote formatting.
- **Change settings on the fly**: You can change settings on a per-command basis by running the `Generate flashcards with new settings` command

### Future Plans
- **Expanded Flashcard Types**: Upcoming updates will support reversed flashcards, automatic deck creation and additional customization options.
Expand Down Expand Up @@ -50,6 +51,9 @@ Unless you see an error on screen, your flashcards should start appearing in a s
at the end of your note soon enough.
Please note that multi-line flashcard generation sometimes does not work. Consider
using `gpt-4o` or `gpt-4-turbo` for better results.
You can also execute the command `Generate flashcards with new settings` which lets
you transiantly customize the settings on the fly by specifying a custom prompt,
the number of flashcards to generate and whether they have to be multiline.


## Tips
Expand Down
19 changes: 16 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4446,9 +4446,10 @@ var InputModal = class extends import_obsidian.Modal {
this.plugin = plugin;
this.onSubmit = onSubmit;
this.configuration = { ...this.plugin.settings };
this.keypressed = false;
}
onOpen() {
let { contentEl } = this;
let { contentEl, containerEl, modalEl } = this;
contentEl.createEl("h1", { text: "Prompt configuration" });
new import_obsidian.Setting(contentEl).setName("Number of flashcards to generate").addText(
(text) => text.setValue(this.configuration.flashcardsCount.toString()).onChange((value) => {
Expand All @@ -4467,10 +4468,22 @@ var InputModal = class extends import_obsidian.Modal {
);
new import_obsidian.Setting(contentEl).addButton(
(btn) => btn.setButtonText("Submit").setCta().onClick(() => {
this.close();
this.onSubmit(this.configuration, this.multiline);
this.submit();
})
);
contentEl.addEventListener("keyup", ({ key }) => {
if (key === "Enter") {
if (this.keypressed) {
this.submit();
} else {
this.keypressed = true;
}
}
});
}
submit() {
this.close();
this.onSubmit(this.configuration, this.multiline);
}
onClose() {
let { contentEl } = this;
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "flashcards-llm",
"name": "Flashcards LLM",
"version": "0.0.10",
"version": "0.0.11",
"minAppVersion": "0.15.0",
"description": "Use Large Language Models (such as ChatGPT) to automatically generate flashcards from obsidian notes",
"author": "Marco Pampaloni",
Expand Down
26 changes: 23 additions & 3 deletions src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ export class InputModal extends Modal {
plugin: FlashcardsLLMPlugin
configuration: FlashcardsSettings;
multiline: boolean;
keypressed: boolean;
onSubmit: (configuration: FlashcardsSettings, multiline: boolean) => void;

constructor(app: App, plugin: FlashcardsLLMPlugin, onSubmit: (configuration: FlashcardsSettings, multiline: boolean) => void) {
super(app);
this.plugin = plugin;
this.onSubmit = onSubmit;
this.configuration = { ...this.plugin.settings };
this.keypressed = false;
}

onOpen() {
let { contentEl } = this;
let { contentEl, containerEl, modalEl } = this;
contentEl.createEl("h1", { text: "Prompt configuration" });

new Setting(contentEl)
Expand Down Expand Up @@ -57,11 +59,29 @@ export class InputModal extends Modal {
.setButtonText("Submit")
.setCta()
.onClick(() => {
this.close();
this.onSubmit(this.configuration, this.multiline);
this.submit();
})
);

contentEl.addEventListener("keyup", ({key}) => {
if (key === "Enter") {
// Hack to make the keypress work reliably:
// without this (for example) it registers the KEYUP event from
// when the user issued the command from the command palette
if (this.keypressed) {
this.submit();
}
else {
this.keypressed = true;
}
}
});

}

submit() {
this.close();
this.onSubmit(this.configuration, this.multiline);
}

onClose() {
Expand Down

0 comments on commit 36b782f

Please sign in to comment.