added dropdown

This commit is contained in:
Sparsh Yadav 2023-04-15 18:10:11 +05:30
parent e7a6a57952
commit a579a15f98
2 changed files with 72 additions and 0 deletions

35
main.js
View file

@ -66,6 +66,7 @@ var TextInputModal = /** @class */ (function (_super) {
container.style.display = 'flex';
container.style.flexDirection = 'column';
container.style.gap = '1rem';
container.style.padding = '1rem';
this.contentEl.appendChild(container);
// Add a title input field
this.titleInput = document.createElement('input');
@ -76,6 +77,40 @@ var TextInputModal = /** @class */ (function (_super) {
this.titleInput.style.border = '1px solid var(--text-faint)';
this.titleInput.style.borderRadius = '4px';
container.appendChild(this.titleInput);
// Add a dropdown for existing notes
this.dropdown = document.createElement('select');
this.dropdown.style.display = 'none';
this.dropdown.style.marginTop = '0.5rem';
this.dropdown.style.fontSize = '1em';
this.dropdown.style.padding = '0.5rem';
this.dropdown.style.border = '1px solid var(--text-faint)';
this.dropdown.style.borderRadius = '4px';
container.appendChild(this.dropdown);
// Populate the dropdown and open the note on selection
this.titleInput.addEventListener('input', function (event) {
var matchingNotes = _this.app.vault.getMarkdownFiles().filter(function (note) { return note.basename.toLowerCase().startsWith(event.target.value.toLowerCase()); });
_this.dropdown.innerHTML = '';
if (matchingNotes.length > 0) {
_this.dropdown.style.display = 'block';
for (var _i = 0, matchingNotes_1 = matchingNotes; _i < matchingNotes_1.length; _i++) {
var note = matchingNotes_1[_i];
var option = document.createElement('option');
option.value = note.path;
option.textContent = note.basename;
_this.dropdown.appendChild(option);
}
}
else {
_this.dropdown.style.display = 'none';
}
});
this.dropdown.addEventListener('change', function (event) {
var selectedNote = _this.app.vault.getAbstractFileByPath(event.target.value);
if (selectedNote) {
_this.close();
_this.app.workspace.activeLeaf.openFile(selectedNote);
}
});
// Add a textarea for note content
this.textarea = document.createElement('textarea');
this.textarea.rows = 5;

37
main.ts
View file

@ -15,6 +15,7 @@ class TextInputModal extends Modal {
container.style.display = 'flex';
container.style.flexDirection = 'column';
container.style.gap = '1rem';
container.style.padding = '1rem';
this.contentEl.appendChild(container);
// Add a title input field
@ -27,6 +28,42 @@ class TextInputModal extends Modal {
this.titleInput.style.borderRadius = '4px';
container.appendChild(this.titleInput);
// Add a dropdown for existing notes
this.dropdown = document.createElement('select');
this.dropdown.style.display = 'none';
this.dropdown.style.marginTop = '0.5rem';
this.dropdown.style.fontSize = '1em';
this.dropdown.style.padding = '0.5rem';
this.dropdown.style.border = '1px solid var(--text-faint)';
this.dropdown.style.borderRadius = '4px';
container.appendChild(this.dropdown);
// Populate the dropdown and open the note on selection
this.titleInput.addEventListener('input', (event) => {
const matchingNotes = this.app.vault.getMarkdownFiles().filter((note) => note.basename.toLowerCase().startsWith(event.target.value.toLowerCase()));
this.dropdown.innerHTML = '';
if (matchingNotes.length > 0) {
this.dropdown.style.display = 'block';
for (const note of matchingNotes) {
const option = document.createElement('option');
option.value = note.path;
option.textContent = note.basename;
this.dropdown.appendChild(option);
}
} else {
this.dropdown.style.display = 'none';
}
});
this.dropdown.addEventListener('change', (event) => {
const selectedNote = this.app.vault.getAbstractFileByPath(event.target.value);
if (selectedNote) {
this.close();
this.app.workspace.activeLeaf.openFile(selectedNote);
}
});
// Add a textarea for note content
this.textarea = document.createElement('textarea');
this.textarea.rows = 5;