`;
this.dom.shortcutsList.appendChild(item);
}
},
handleExpansion(e) {
if (e.key !== ' ' && e.key !== 'Tab') return;
const text = this.dom.editor.value;
const cursorPos = this.dom.editor.selectionStart;
const textBeforeCursor = text.substring(0, cursorPos);
const lastWord = textBeforeCursor.split(/\s+/).pop();
if (this.shortcuts.has(lastWord)) {
e.preventDefault();
const expansion = this.shortcuts.get(lastWord);
const start = cursorPos - lastWord.length;
const newText = text.substring(0, start) + expansion + text.substring(cursorPos);
this.dom.editor.value = newText;
const newCursorPos = start + expansion.length;
this.dom.editor.selectionStart = this.dom.editor.selectionEnd = newCursorPos;
}
},
generatePdf() {
if (this.shortcuts.size === 0) return;
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ unit: 'pt', format: 'a4' });
pdf.setFontSize(18);
pdf.text("My Text Expander Shortcuts", 40, 60);
const tableData = Array.from(this.shortcuts, ([key, value]) => [key, value]);
pdf.autoTable({
startY: 80,
head: [['Shortcut', 'Expansion Text']],
body: tableData,
headStyles: { fillColor: [37, 99, 235] },
columnStyles: { 1: { cellWidth: 350 } }
});
pdf.save('Text-Expander-Shortcuts.pdf');
}
};
app.init();
});
