shortcut to add table

This commit is contained in:
Gamosoft 2025-12-11 18:11:25 +01:00
parent 0acd533e1b
commit 64a97c249a
2 changed files with 40 additions and 0 deletions

View File

@ -275,6 +275,7 @@ date: {{date}}
| `Ctrl+B` | `Cmd+B` | Bold | `**text**` | | `Ctrl+B` | `Cmd+B` | Bold | `**text**` |
| `Ctrl+I` | `Cmd+I` | Italic | `*text*` | | `Ctrl+I` | `Cmd+I` | Italic | `*text*` |
| `Ctrl+K` | `Cmd+K` | Insert link | `[text](url)` | | `Ctrl+K` | `Cmd+K` | Insert link | `[text](url)` |
| `Ctrl+Alt+T` | `Cmd+Option+T` | Insert table | 3x3 table placeholder |
## 🚀 Performance ## 🚀 Performance

View File

@ -461,6 +461,12 @@ function noteApp() {
e.preventDefault(); e.preventDefault();
this.insertLink(); this.insertLink();
} }
// Ctrl/Cmd + Alt + T for table
if ((e.ctrlKey || e.metaKey) && e.altKey && e.key === 't') {
e.preventDefault();
this.insertTable();
}
} }
}); });
} }
@ -2548,6 +2554,39 @@ function noteApp() {
this.autoSave(); this.autoSave();
}, },
// Insert a markdown table placeholder
insertTable() {
const editor = document.getElementById('note-editor');
if (!editor) return;
const cursorPos = editor.selectionStart;
// Basic 3x3 table placeholder
const table = `| Header 1 | Header 2 | Header 3 |
|----------|----------|----------|
| Cell 1 | Cell 2 | Cell 3 |
| Cell 4 | Cell 5 | Cell 6 |
`;
// Add newline before if not at start of line
const textBefore = this.noteContent.substring(0, cursorPos);
const needsNewlineBefore = textBefore.length > 0 && !textBefore.endsWith('\n');
const prefix = needsNewlineBefore ? '\n\n' : '';
// Insert the table
this.noteContent = textBefore + prefix + table + this.noteContent.substring(cursorPos);
// Position cursor at first header for easy editing
this.$nextTick(() => {
const newPos = cursorPos + prefix.length + 2; // After "| "
editor.setSelectionRange(newPos, newPos + 8); // Select "Header 1"
editor.focus();
});
// Trigger autosave
this.autoSave();
},
// Save current note // Save current note
async saveNote() { async saveNote() {
if (!this.currentNote) return; if (!this.currentNote) return;