📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
New snippets system: Katex snippets, carret management and improve existing interfaces
Smaug67396c559d3a3bcc
diff --git a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vueindex af53a3bf..8c43ee2a 100644--- a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue+++ b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue@@ -3,13 +3,12 @@<div style="height: 100%"><div class="editor-container"><Toolbar v-model="document" :minimal="minimal" @execute-action="exec" />- <div style="display: flex; min-height: 0; padding: 6px; flex: 1; flex-direction: column; gap: 8px">+ <div style="display: flex; min-height: 0; padding: 6px 0; flex: 1; flex-direction: column; gap: 8px"><input v-if="!minimal" v-model="document.name" placeholder="Title" class="title" @input="autoSaveConditional" /><input v-if="!minimal" v-model="document.description" placeholder="Description" class="description" @input="autoSaveConditional" /><AppTagInput v-model="document.tags" style="margin-bottom: 10px" @update:model-value="autoSaveConditional" /><div ref="container" class="markdown"><div ref="editorContainer" class="codemirror-editor" style="border-right: 1px solid var(--border-color)" />- <!-- eslint-disable-next-line vue/no-v-html --><divv-if="showPreview"ref="markdownPreview"@@ -22,14 +21,16 @@</div></div></template>+<script setup lang="ts">import { EditorView, keymap, highlightSpecialChars, drawSelection, lineNumbers, type KeyBinding } from '@codemirror/view';import { EditorState, Compartment } from '@codemirror/state';import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';-import { autocompletion } from '@codemirror/autocomplete';+import { autocompletion, completionKeymap, snippet, type CompletionContext } from '@codemirror/autocomplete';import { markdown, markdownLanguage } from '@codemirror/lang-markdown';import { loadTheme } from './themes';+import { katexSnippets } from './katex-snippets';import Toolbar from './Toolbar.vue';import ImageSelectorModal from './ImageSelectorModal.vue';import GridOrganizationModal from './GridOrganizationModal.vue';@@ -56,6 +57,10 @@ const document = ref<Partial<Node>>({content_compiled: compile(props.doc?.content || ''),});+// ... [FONCTIONS EXEC, MODALS, ETC. INCHANGÉES] ...+// Je ne répète pas le bloc exec/insertText/Modals pour gagner de la place,+// gardez exactement ce que vous aviez.+function exec(action: string, payload?: string) {if (action === 'preview') return (showPreview.value = !showPreview.value);if (action === 'openColorPicker') return openColorModal();@@ -127,6 +132,7 @@ function exec(action: string, payload?: string) {view.focus();}+function insertText(text: string) {if (!editorView.value || !text) return;@@ -141,6 +147,7 @@ function insertText(text: string) {view.focus();}+function openColorModal() {const modalManager = useModal();modalManager.add(new Modal(shallowRef(ColorPickerModal), { props: { onColorSelect: handleColorSelect } }));@@ -194,51 +201,8 @@ function handleGridSelect(gridMarkdown: string) {view.focus();}-const snippets = preferences.get('snippets');-const snippetListener = EditorView.updateListener.of(update => {- if (!update.docChanged || !editorView.value) return;-- const { state, transactions } = update;- const lastTransaction = transactions[0];-- const changes = lastTransaction!.changes;-- // Ne gère que les insertions simples- let hasInsertion = false;- changes.iterChanges((fromA, toA, fromB, toB, inserted) => {- if (inserted.length > 0) {- hasInsertion = true;- }- });- if (!hasInsertion) return;-- // Check if snippet work- const cursorPos = state.selection.main.head;- const line = state.doc.lineAt(cursorPos);- const textBefore = line.text.slice(0, cursorPos - line.from);-- const match = snippets.value.find(snippet => snippet.id && textBefore.endsWith(snippet.id as string));- if (!match) return;-- const start = cursorPos - (match.id as string).length;- const snippet = match.label;-- // replace $0 with a cursor- const [before, after] = snippet.split('$0');- const newText = (before || '') + (after || '');-- const view = editorView.value;- view.dispatch({- changes: { from: start, to: cursorPos, insert: newText },- selection: {- anchor: start + (before?.length || 0),- },- });-});-const fileUploadHandler = EditorView.domEventHandlers({paste: event => {- // Handle file upload and format as Markdown (e.g., )const items = event.clipboardData?.items;if (!items) return;for (const item of items) {@@ -318,6 +282,29 @@ const updateListener = EditorView.updateListener.of(v => {autoSaveConditional();}});++function snippetSource(context: CompletionContext) {+ const snippets = preferences.get('snippets').value;++ const word = context.matchBefore(/[\w!:]+/);++ if (!word && !context.explicit) return null;+ return {+ from: word ? word.from : context.pos,+ // MODIFICATION CLÉ: Remplacer snippetCompletion() par un objet Completion littéral+ // avec 'apply: snippet(s.label)'++ options: [...snippets, ...katexSnippets].map(s => ({+ label: s.label, // Le déclencheur qui apparaît dans la liste (ex: !yellow)+ detail: 'Snippet',+ type: 'snippet',+ // On utilise 'snippet' pour créer explicitement la fonction d'application+ // qui va analyser et gérer le curseur pour $0, $1, etc.+ apply: snippet(s.label),+ })),+ };+}+const state = EditorState.create({doc: document.value.content || '',extensions: [@@ -326,10 +313,12 @@ const state = EditorState.create({history(),drawSelection(),autocompletion(),- keymap.of([...defaultKeymap, ...historyKeymap, ...searchKeymap, indentWithTab, ...markdownKeysmap]),+ keymap.of([...completionKeymap, ...defaultKeymap, ...historyKeymap, indentWithTab, ...searchKeymap, ...markdownKeysmap]),markdown({ base: markdownLanguage }),+ markdownLanguage.data.of({+ autocomplete: snippetSource,+ }),updateListener,- snippetListener,fileUploadHandler,themeCompartment.of(loadTheme()),highlightSelectionMatches({}),@@ -342,6 +331,7 @@ const state = EditorState.create({}),],});+onMounted(() => {if (!editorContainer.value) return;editorView.value = new EditorView({@@ -352,6 +342,7 @@ onMounted(() => {window.addEventListener('keydown', handleGlobalKeys);});+// ... [REST OF COMPONENT INCHANGED] ...onBeforeUnmount(() => {if (preferences.get('documentAutoSave').value) {updateDocumentContent();@@ -371,7 +362,6 @@ function handleGlobalKeys(e: KeyboardEvent) {e.preventDefault();showPreview.value = !showPreview.value;}-if (e.key === 'Escape') {emit('exit');}@@ -408,34 +398,28 @@ const autoSave = debounceDelayed(() => {<style scoped lang="scss">@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap');-.markdown {display: flex;- min-height: 0; /* permet aux enfants flexibles de ne pas déborder */+ min-height: 0;flex: 1;gap: 8px;}-.editor-container {display: flex;width: 100%;height: 100%;flex-direction: column;}-.codemirror-editor {flex: 1;overflow: auto;}-.editor-container:deep(.cm-editor) {height: 100%;}-/* stylelint-disable */.editor-container:deep(.cm-selectionBackground) {background-color: var(--selection-color) !important;}-.markdown-preview {height: 100%;padding: 1rem;@@ -443,18 +427,15 @@ const autoSave = debounceDelayed(() => {flex: 1;overflow: auto;}-input {border: none;outline: none;}-.title {padding: 6px 10px;font-size: 1.5rem;font-weight: 600;}-.description {padding: 4px 10px;font-size: 1.1rem;diff --git a/frontend/app/components/MarkdownEditor/katex-snippets.ts b/frontend/app/components/MarkdownEditor/katex-snippets.tsnew file mode 100644index 00000000..d7a7561f--- /dev/null+++ b/frontend/app/components/MarkdownEditor/katex-snippets.ts@@ -0,0 +1,305 @@+export const katexSnippets = [+ // ---------- Accents ----------+ { id: 'acute', label: '\\acute{${0}}' },+ { id: 'grave', label: '\\grave{${0}}' },+ { id: 'hat', label: '\\hat{${0}}' },+ { id: 'widehat', label: '\\widehat{${0}}' },+ { id: 'bar', label: '\\bar{${0}}' },+ { id: 'overline', label: '\\overline{${0}}' },+ { id: 'underline', label: '\\underline{${0}}' },+ { id: 'vec', label: '\\vec{${0}}' },+ { id: 'tilde', label: '\\tilde{${0}}' },+ { id: 'widetilde', label: '\\widetilde{${0}}' },+ { id: 'check', label: '\\check{${0}}' },+ { id: 'breve', label: '\\breve{${0}}' },+ { id: 'dot', label: '\\dot{${0}}' },+ { id: 'ddot', label: '\\ddot{${0}}' },+ { id: 'dddot', label: '\\dddot{${0}}' },+ { id: 'ddddot', label: '\\ddddot{${0}}' },+ { id: 'overbrace', label: '\\overbrace{${0}}^{${1}}' },+ { id: 'underbrace', label: '\\underbrace{${0}}_{${1}}' },+ { id: 'overleftarrow', label: '\\overleftarrow{${0}}' },+ { id: 'overrightarrow', label: '\\overrightarrow{${0}}' },+ { id: 'underleftarrow', label: '\\underleftarrow{${0}}' },+ { id: 'underrightarrow', label: '\\underrightarrow{${0}}' },+ { id: 'overleftrightarrow', label: '\\overleftrightarrow{${0}}' },+ { id: 'underleftrightarrow', label: '\\underleftrightarrow{${0}}' },+ { id: 'overgroup', label: '\\overgroup{${0}}' },+ { id: 'undergroup', label: '\\undergroup{${0}}' },+ { id: 'utilde', label: '\\utilde{${0}}' },+ { id: 'widecheck', label: '\\widecheck{${0}}' },+ { id: 'overlinesegment', label: '\\overlinesegment{${0}}' },+ { id: 'underlinesegment', label: '\\underlinesegment{${0}}' },+ { id: 'underbar', label: '\\underbar{${0}}' },++ // ---------- Delimiters ----------+ { id: 'lparen', label: '\\lparen' },+ { id: 'rparen', label: '\\rparen' },+ { id: 'lbrack', label: '\\lbrack' },+ { id: 'rbrack', label: '\\rbrack' },+ { id: 'lbrace', label: '\\lbrace' },+ { id: 'rbrace', label: '\\rbrace' },+ { id: 'langle', label: '\\langle' },+ { id: 'rangle', label: '\\rangle' },+ { id: 'lgroup', label: '\\lgroup' },+ { id: 'rgroup', label: '\\rgroup' },+ { id: 'ulcorner', label: '\\ulcorner' },+ { id: 'urcorner', label: '\\urcorner' },+ { id: 'llcorner', label: '\\llcorner' },+ { id: 'lrcorner', label: '\\lrcorner' },+ { id: 'vert', label: '\\vert' },+ { id: 'Vert', label: '\\Vert' },+ { id: 'backslash', label: '\\backslash' },+ { id: 'left', label: '\\left${0}' },+ { id: 'right', label: '\\right${0}' },+ { id: 'middle', label: '\\middle${0}' },+ { id: 'big', label: '\\big${0}' },+ { id: 'Big', label: '\\Big${0}' },+ { id: 'bigg', label: '\\bigg${0}' },+ { id: 'Bigg', label: '\\Bigg${0}' },+ { id: 'bigl', label: '\\bigl${0}' },+ { id: 'bigr', label: '\\bigr${0}' },+ { id: 'bigm', label: '\\bigm${0}' },+ { id: 'Bigl', label: '\\Bigl${0}' },+ { id: 'Bigr', label: '\\Bigr${0}' },+ { id: 'Bigm', label: '\\Bigm${0}' },+ { id: 'biggl', label: '\\biggl${0}' },+ { id: 'biggr', label: '\\biggr${0}' },+ { id: 'biggm', label: '\\biggm${0}' },+ { id: 'Biggl', label: '\\Biggl${0}' },+ { id: 'Biggr', label: '\\Biggr${0}' },+ { id: 'Biggm', label: '\\Biggm${0}' },++ // ---------- Environments (snippets) ----------+ { id: 'matrix', label: '\\begin{matrix}${0}\\\\${1}\\end{matrix}' },+ { id: 'pmatrix', label: '\\begin{pmatrix}${0}\\\\${1}\\end{pmatrix}' },+ { id: 'bmatrix', label: '\\begin{bmatrix}${0}\\\\${1}\\end{bmatrix}' },+ { id: 'vmatrix', label: '\\begin{vmatrix}${0}\\\\${1}\\end{vmatrix}' },+ { id: 'Vmatrix', label: '\\begin{Vmatrix}${0}\\\\${1}\\end{Vmatrix}' },+ { id: 'Bmatrix', label: '\\begin{Bmatrix}${0}\\\\${1}\\end{Bmatrix}' },+ { id: 'smallmatrix', label: '\\begin{smallmatrix}${0}\\\\${1}\\end{smallmatrix}' },+ { id: 'array', label: '\\begin{array}{${0}}${1}\\end{array}' },+ { id: 'cases', label: '\\begin{cases}${0}\\end{cases}' },+ { id: 'rcases', label: '\\begin{rcases}${0}\\end{rcases}' },+ { id: 'darray', label: '\\begin{darray}${0}\\end{darray}' },+ { id: 'dcases', label: '\\begin{dcases}${0}\\end{dcases}' },+ { id: 'drcases', label: '\\begin{drcases}${0}\\end{drcases}' },+ { id: 'equation', label: '\\begin{equation}${0}\\end{equation}' },+ { id: 'equation*', label: '\\begin{equation*}${0}\\end{equation*}' },+ { id: 'split', label: '\\begin{split}${0}\\end{split}' },+ { id: 'align', label: '\\begin{align}${0}\\end{align}' },+ { id: 'align*', label: '\\begin{align*}${0}\\end{align*}' },+ { id: 'gather', label: '\\begin{gather}${0}\\end{gather}' },+ { id: 'gather*', label: '\\begin{gather*}${0}\\end{gather*}' },+ { id: 'alignat', label: '\\begin{alignat}{${0}}${1}\\end{alignat}' },+ { id: 'alignat*', label: '\\begin{alignat*}{${0}}${1}\\end{alignat*}' },+ { id: 'gathered', label: '\\begin{gathered}${0}\\end{gathered}' },+ { id: 'aligned', label: '\\begin{aligned}${0}\\end{aligned}' },+ { id: 'alignedat', label: '\\begin{alignedat}{${0}}${1}\\end{alignedat}' },+ { id: 'CD', label: '\\begin{CD}${0}\\end{CD}' },++ // ---------- Basic structures ----------+ { id: 'frac', label: '\\frac{${0}}{${1}}' },+ { id: 'dfrac', label: '\\dfrac{${0}}{${1}}' },+ { id: 'tfrac', label: '\\tfrac{${0}}{${1}}' },+ { id: 'binom', label: '\\binom{${0}}{${1}}' },+ { id: 'sqrt', label: '\\sqrt{${0}}' },+ { id: 'sqrtn', label: '\\sqrt[${0}]{${1}}' },+ { id: 'boxed', label: '\\boxed{${0}}' },+ { id: 'cancel', label: '\\cancel{${0}}' },+ { id: 'bcancel', label: '\\bcancel{${0}}' },+ { id: 'xcancel', label: '\\xcancel{${0}}' },+ { id: 'sout', label: '\\sout{${0}}' },++ // ---------- Arrows ----------+ { id: 'to', label: '\\to' },+ { id: 'rightarrow', label: '\\rightarrow' },+ { id: 'leftarrow', label: '\\leftarrow' },+ { id: 'leftrightarrow', label: '\\leftrightarrow' },+ { id: 'Rightarrow', label: '\\Rightarrow' },+ { id: 'Leftarrow', label: '\\Leftarrow' },+ { id: 'Leftrightarrow', label: '\\Leftrightarrow' },+ { id: 'mapsto', label: '\\mapsto' },+ { id: 'longrightarrow', label: '\\longrightarrow' },+ { id: 'longleftarrow', label: '\\longleftarrow' },+ { id: 'longleftrightarrow', label: '\\longleftrightarrow' },+ { id: 'uparrow', label: '\\uparrow' },+ { id: 'downarrow', label: '\\downarrow' },+ { id: 'updownarrow', label: '\\updownarrow' },+ { id: 'Uparrow', label: '\\Uparrow' },+ { id: 'Downarrow', label: '\\Downarrow' },+ { id: 'Updownarrow', label: '\\Updownarrow' },++ // ---------- Relations & operators ----------+ { id: 'cdot', label: '\\cdot' },+ { id: 'times', label: '\\times' },+ { id: 'div', label: '\\div' },+ { id: 'pm', label: '\\pm' },+ { id: 'mp', label: '\\mp' },+ { id: 'leq', label: '\\leq' },+ { id: 'geq', label: '\\geq' },+ { id: 'neq', label: '\\neq' },+ { id: 'approx', label: '\\approx' },+ { id: 'sim', label: '\\sim' },+ { id: 'propto', label: '\\propto' },+ { id: 'equiv', label: '\\equiv' },+ { id: 'subset', label: '\\subset' },+ { id: 'supset', label: '\\supset' },+ { id: 'subseteq', label: '\\subseteq' },+ { id: 'supseteq', label: '\\supseteq' },+ { id: 'in', label: '\\in' },+ { id: 'notin', label: '\\notin' },+ { id: 'ni', label: '\\ni' },+ { id: 'mid', label: '\\mid' },+ { id: 'land', label: '\\land' },+ { id: 'lor', label: '\\lor' },+ { id: 'forall', label: '\\forall' },+ { id: 'exists', label: '\\exists' },+ { id: 'nexists', label: '\\nexists' },+ { id: 'therefore', label: '\\therefore' },+ { id: 'because', label: '\\because' },+ { id: 'implies', label: '\\implies' },+ { id: 'impliedby', label: '\\impliedby' },+ { id: 'iff', label: '\\iff' },++ // ---------- Spacing ----------+ { id: 'thinspace', label: '\\thinspace' },+ { id: 'medspace', label: '\\medspace' },+ { id: 'thickspace', label: '\\thickspace' },+ { id: 'enspace', label: '\\enspace' },+ { id: 'quad', label: '\\quad' },+ { id: 'qquad', label: '\\qquad' },+ { id: 'negthinspace', label: '\\negthinspace' },+ { id: 'negmedspace', label: '\\negmedspace' },+ { id: 'negthickspace', label: '\\negthickspace' },+ { id: 'kern', label: '\\kern${0}' },+ { id: 'mkern', label: '\\mkern${0}' },+ { id: 'hspace', label: '\\hspace{${0}}' },+ { id: 'hphantom', label: '\\hphantom{${0}}' },+ { id: 'vphantom', label: '\\vphantom{${0}}' },+ { id: 'phantom', label: '\\phantom{${0}}' },++ // ---------- Layout ----------+ { id: 'stackrel', label: '\\stackrel{${0}}{${1}}' },+ { id: 'overset', label: '\\overset{${0}}{${1}}' },+ { id: 'underset', label: '\\underset{${0}}{${1}}' },+ { id: 'atop', label: '${0} \\atop ${1}' },+ { id: 'raisebox', label: '\\raisebox{${0}}{${1}}' },+ { id: 'vcenter', label: '\\vcenter{${0}}' },+ { id: 'smash', label: '\\smash{${0}}' },+ { id: 'mathllap', label: '\\mathllap{${0}}' },+ { id: 'mathrlap', label: '\\mathrlap{${0}}' },+ { id: 'mathclap', label: '\\mathclap{${0}}' },++ // ---------- Tags ----------+ { id: 'tag', label: '\\tag{${0}} ${1}' },+ { id: 'tag*', label: '\\tag*{${0}} ${1}' },++ // ---------- HTML (trust option required) ----------+ { id: 'href', label: '\\href{${0}}{${1}}' },+ { id: 'url', label: '\\url{${0}}' },+ { id: 'includegraphics', label: '\\includegraphics[height=${0}]{${1}}' },+ { id: 'htmlId', label: '\\htmlId{${0}}{${1}}' },+ { id: 'htmlClass', label: '\\htmlClass{${0}}{${1}}' },+ { id: 'htmlStyle', label: '\\htmlStyle{${0}}{${1}}' },+ { id: 'htmlData', label: '\\htmlData{${0}}{${1}}' },++ // ---------- Greek letters (lowercase) ----------+ { id: 'alpha', label: '\\alpha' },+ { id: 'beta', label: '\\beta' },+ { id: 'gamma', label: '\\gamma' },+ { id: 'delta', label: '\\delta' },+ { id: 'epsilon', label: '\\epsilon' },+ { id: 'zeta', label: '\\zeta' },+ { id: 'eta', label: '\\eta' },+ { id: 'theta', label: '\\theta' },+ { id: 'iota', label: '\\iota' },+ { id: 'kappa', label: '\\kappa' },+ { id: 'lambda', label: '\\lambda' },+ { id: 'mu', label: '\\mu' },+ { id: 'nu', label: '\\nu' },+ { id: 'xi', label: '\\xi' },+ { id: 'omicron', label: '\\omicron' },+ { id: 'pi', label: '\\pi' },+ { id: 'rho', label: '\\rho' },+ { id: 'sigma', label: '\\sigma' },+ { id: 'tau', label: '\\tau' },+ { id: 'upsilon', label: '\\upsilon' },+ { id: 'phi', label: '\\phi' },+ { id: 'chi', label: '\\chi' },+ { id: 'psi', label: '\\psi' },+ { id: 'omega', label: '\\omega' },+ { id: 'varepsilon', label: '\\varepsilon' },+ { id: 'varkappa', label: '\\varkappa' },+ { id: 'vartheta', label: '\\vartheta' },+ { id: 'thetasym', label: '\\thetasym' },+ { id: 'varpi', label: '\\varpi' },+ { id: 'varrho', label: '\\varrho' },+ { id: 'varsigma', label: '\\varsigma' },+ { id: 'varphi', label: '\\varphi' },++ // ---------- Greek letters (uppercase) ----------+ { id: 'Gamma', label: '\\Gamma' },+ { id: 'Delta', label: '\\Delta' },+ { id: 'Theta', label: '\\Theta' },+ { id: 'Lambda', label: '\\Lambda' },+ { id: 'Xi', label: '\\Xi' },+ { id: 'Pi', label: '\\Pi' },+ { id: 'Sigma', label: '\\Sigma' },+ { id: 'Upsilon', label: '\\Upsilon' },+ { id: 'Phi', label: '\\Phi' },+ { id: 'Psi', label: '\\Psi' },+ { id: 'Omega', label: '\\Omega' },+ { id: 'varGamma', label: '\\varGamma' },+ { id: 'varDelta', label: '\\varDelta' },+ { id: 'varTheta', label: '\\varTheta' },+ { id: 'varLambda', label: '\\varLambda' },+ { id: 'varXi', label: '\\varXi' },+ { id: 'varPi', label: '\\varPi' },+ { id: 'varSigma', label: '\\varSigma' },+ { id: 'varUpsilon', label: '\\varUpsilon' },+ { id: 'varPhi', label: '\\varPhi' },+ { id: 'varPsi', label: '\\varPsi' },+ { id: 'varOmega', label: '\\varOmega' },++ // ---------- Other letters/symbols ----------+ { id: 'imath', label: '\\imath' },+ { id: 'jmath', label: '\\jmath' },+ { id: 'nabla', label: '\\nabla' },+ { id: 'partial', label: '\\partial' },+ { id: 'aleph', label: '\\aleph' },+ { id: 'beth', label: '\\beth' },+ { id: 'gimel', label: '\\gimel' },+ { id: 'daleth', label: '\\daleth' },+ { id: 'eth', label: '\\eth' },+ { id: 'hbar', label: '\\hbar' },+ { id: 'hslash', label: '\\hslash' },+ { id: 'wp', label: '\\wp' },+ { id: 'Im', label: '\\Im' },+ { id: 'Re', label: '\\Re' },+ { id: 'Bbbk', label: '\\Bbbk' },+ { id: 'cnums', label: '\\cnums' },+ { id: 'Complex', label: '\\Complex' },+ { id: 'N', label: '\\N' },+ { id: 'Z', label: '\\Z' },+ { id: 'Q', label: '\\Q' },+ { id: 'R', label: '\\R' },+ { id: 'Reals', label: '\\Reals' },+ { id: 'reals', label: '\\reals' },++ // ---------- Logic and set helpers ----------+ { id: 'Set', label: '\\Set{${0} \\mid ${1}}' },+ { id: 'set', label: '\\set{${0} \\mid ${1}}' },++ // ---------- Macros helpers ----------+ { id: 'def', label: '\\def\\${0}{${1}}' },+ { id: 'gdef', label: '\\gdef\\${0}{${1}}' },+ { id: 'newcommand', label: '\\newcommand\\${0}[${1}]{${2}}' },+ { id: 'renewcommand', label: '\\renewcommand\\${0}[${1}]{${2}}' },+ { id: 'providecommand', label: '\\providecommand\\${0}[${1}]{${2}}' },+ { id: 'let', label: '\\let\\${0}=\\${1}' },+ { id: 'globaldef', label: '\\global\\def\\${0}{${1}}' },++ // ---------- Misc ----------+ { id: 'char', label: '\\char"${0}' },+] as const;diff --git a/frontend/app/composables/Preferences.ts b/frontend/app/composables/Preferences.tsindex b4f3f4fe..9c891a21 100644--- a/frontend/app/composables/Preferences.ts+++ b/frontend/app/composables/Preferences.ts@@ -30,15 +30,15 @@ export const DEFAULT_PREFERENCES = {navigation: true as boolean,},snippets: [- { id: '!blue', label: ':::blue\n$0\n:::' },- { id: '!green', label: ':::green\n$0\n:::' },- { id: '!yellow', label: ':::yellow\n$0\n:::' },- { id: '!grey', label: ':::grey\n$0\n:::' },- { id: '!details', label: ':::details\n$0\n:::' },- { id: '!center', label: ':::center\n$0\n:::' },- { id: '!m', label: '$$0$' },- { id: '!property', label: ':::property $0\n\n:::' },- { id: '!warning', label: ':::warning $0\n\n:::' },+ { id: '!blue', label: ':::blue\n${0}\n:::' },+ { id: '!green', label: ':::green\n${0}\n:::' },+ { id: '!yellow', label: ':::yellow\n${0}\n:::' },+ { id: '!grey', label: ':::grey\n${0}\n:::' },+ { id: '!details', label: ':::details\n${0}\n:::' },+ { id: '!center', label: ':::center\n${0}\n:::' },+ { id: '!m', label: '${0}$' },+ { id: '!property', label: ':::property ${0}\n\n:::' },+ { id: '!warning', label: ':::warning ${0}\n\n:::' },] as ANode<string>[],editorFontFamily: 'JetBrains Mono' as string,editorFontSize: 14 as number,diff --git a/frontend/app/pages/dashboard/settings/_views/snippets.vue b/frontend/app/pages/dashboard/settings/_views/snippets.vueindex a6d40834..6ebf34c1 100644--- a/frontend/app/pages/dashboard/settings/_views/snippets.vue+++ b/frontend/app/pages/dashboard/settings/_views/snippets.vue@@ -4,19 +4,14 @@<h2 class="ctitle">Snippets</h2><p class="csubtitle">Manage your markdown snippets for quick insertion. Use shortcuts like !blue to quickly insert pre-defined content.</p></div>-<!-- Search and Actions --><div class="toolbar"><div class="search-section"><div class="search-wrapper">- <Icon name="search" class="search-icon" />- <input v-model="searchQuery" type="text" placeholder="Search snippets..." class="search-input" />- </div>- <div class="filter-section">- <AppSelect v-model="sortBy" :items="sortOptions" placeholder="Sort by..." size="200px" :searchable="false" />+ <Icon name="search" class="search-icon" /> <input v-model="searchQuery" type="text" placeholder="Search snippets..." class="search-input" /></div>+ <div class="filter-section"><AppSelect v-model="sortBy" :items="sortOptions" placeholder="Sort by..." size="200px" :searchable="false" /></div></div>-<div class="actions"><AppButton v-if="selectedSnippets.length > 0" type="danger" @click="deleteSelected"> Delete Selected ({{ selectedSnippets.length }}) </AppButton><AppButton type="secondary" class="flex-btn" @click="exportSnippets"><Icon name="backup" /> Export </AppButton>@@ -25,31 +20,56 @@<AppButton type="primary" @click="addSnippet"> + Add Snippet </AppButton></div></div>-- <!-- Snippets Grid --><div class="snippets-container">- <div v-if="filteredSnippets.length === 0" class="no-snippets">+ <div v-if="filteredSnippets.length === 0 && !creatingSnippet" class="no-snippets"><Icon name="search" class="no-snippets-icon" /><p v-if="searchQuery">No snippets found matching "{{ searchQuery }}"</p><p v-else>No snippets available. Create your first snippet!</p></div><TransitionGroup name="snippet" tag="div" class="snippets-grid">+ <!-- Existing snippets -->+ <div v-if="creatingSnippet" class="snippet-card editing">+ <div class="snippet-header">+ <div class="snippet-header-left"></div>+ <div class="snippet-actions">+ <button class="action-btn save-btn" title="Save snippet" @click="saveNewSnippet()">+ <Icon name="check" />+ </button>+ <button class="action-btn cancel-btn" title="Cancel creation" @click="cancelNewSnippet()">+ <Icon name="close" />+ </button>+ </div>+ </div>+ <div class="snippet-edit-form">+ <div class="form-group">+ <input v-model="newSnippet.id" class="snippet-key-input" placeholder="!shortcut" :class="{ error: error(newSnippet.id) }" />+ <div v-if="error(newSnippet.id)" class="error-message">{{ error(newSnippet.id) }}</div>+ </div>+ <div class="form-group">+ <label>Content:</label>+ <textarea+ v-model="newSnippet.label"+ class="snippet-content-input"+ placeholder="Snippet content... Use ${0}, ${1}, ... to tab through placeholders"+ rows="4"+ />+ </div>+ </div>+ </div><divv-for="(snippet, index) in filteredSnippets":key="snippet.id || index"class="snippet-card":class="{ selected: selectedSnippets.includes(index), editing: editingIndex === index }">- <!-- Card Header --><div class="snippet-header"><div class="snippet-header-left"><input type="checkbox" :checked="selectedSnippets.includes(index)" class="snippet-checkbox" @change="toggleSelection(index)" /><div v-if="editingIndex !== index" class="snippet-shortcut-display">- <code class="shortcut-code">{{ snippet.id || '!untitled' }}</code>+ <code class="shortcut-code">{{ snippet.id }}</code></div></div>-<div class="snippet-actions"><button v-if="editingIndex !== index" class="action-btn edit-btn" title="Edit snippet" @click="startEdit(index)"><Icon name="edit" />@@ -73,7 +93,6 @@<input v-model="editingSnippet.id" class="snippet-key-input" placeholder="!shortcut" :class="{ error: error(editingSnippet.id) }" /><div v-if="error(editingSnippet.id)" class="error-message">{{ error(editingSnippet.id) }}</div></div>-<div class="form-group"><label>Content:</label><textarea v-model="editingSnippet.label" class="snippet-content-input" placeholder="Snippet content..." rows="4" />@@ -82,38 +101,21 @@<!-- View Mode --><div v-else class="snippet-content">- <div class="snippet-preview">- <div class="preview-label">Preview:</div>- <!-- eslint-disable-next-line vue/no-v-html | OK Because user self entry -->- <div class="preview-content" v-html="getPreviewHtml(snippet.label)" />- </div>-- <div class="snippet-raw">- <div class="raw-label">Raw content:</div>- <pre class="raw-content">{{ snippet.label }}</pre>- </div>+ <pre class="raw-content">{{ snippet.label }}</pre></div></div>++ <!-- Temporary snippet creation --></TransitionGroup></div>-- <!-- Import file input (hidden) --><input ref="fileInput" type="file" accept=".json" style="display: none" @change="handleFileImport" /></div></template><script setup lang="ts">import { DEFAULT_PREFERENCES } from '~/composables/Preferences';-import compile from '~/helpers/markdown';--const snippets = usePreferences().get('snippets');--// Sort options for AppSelect-const sortOptions = [- { id: 'shortcut', label: 'Sort by Shortcut' },- { id: 'content', label: 'Sort by Content' },- { id: 'usage', label: 'Sort by Usage' },-];+const preferences = usePreferences();+const snippets = preferences.get('snippets');// Reactive stateconst searchQuery = ref('');@@ -122,42 +124,45 @@ const selectedSnippets = ref<number[]>([]);const editingIndex = ref<number | null>(null);const editingSnippet = ref<{ id: string; label: string }>({ id: '', label: '' });const originalSnippet = ref<{ id: string; label: string }>({ id: '', label: '' });-const fileInput = ref<HTMLInputElement | null>(null);-// Computed properties+// Temporary snippet creation+const creatingSnippet = ref(false);+const newSnippet = ref<{ id: string; label: string }>({ id: '', label: '' });+const sortOptions = [+ { id: 'shortcut', label: 'Sort by Shortcut' },+ { id: 'content', label: 'Sort by Content' },+ { id: 'usage', label: 'Sort by Usage' },+];+// Computedconst filteredSnippets = computed(() => {- const filtered = snippets.value.filter(snippet => {- const searchLower = searchQuery.value.toLowerCase();- return snippet.id.toLowerCase().includes(searchLower) || snippet.label.toLowerCase().includes(searchLower);- });-- // Sort snippets- return filtered.sort((a, b) => {- switch (sortBy.value) {- case 'shortcut':- return a.id.localeCompare(b.id);- case 'content':- return a.label.localeCompare(b.label);- case 'usage':- // For now, sort by id as usage tracking isn't implemented- return a.id.localeCompare(b.id);- default:- return 0;- }- });+ return snippets.value+ .filter(+ snippet => snippet.id.toLowerCase().includes(searchQuery.value.toLowerCase()) || snippet.label.toLowerCase().includes(searchQuery.value.toLowerCase()),+ )+ .sort((a, b) => a.id.localeCompare(b.id));});// Functionsfunction addSnippet() {- const newSnippet = { id: '', label: '' };- snippets.value = [newSnippet, ...snippets.value];+ creatingSnippet.value = true;+ newSnippet.value = { id: '', label: '' };+}- // Start editing the new snippet immediately- nextTick(() => {- startEdit(0);- });+function saveNewSnippet() {+ if (error(newSnippet.value.id)) return;+ snippets.value.unshift({ ...newSnippet.value });+ preferences.set('snippets', snippets.value);+ creatingSnippet.value = false;+ newSnippet.value = { id: '', label: '' };}+function cancelNewSnippet() {+ creatingSnippet.value = false;+ newSnippet.value = { id: '', label: '' };+}++const fileInput = ref<HTMLInputElement | null>(null);+function removeSnippet(index: number) {const actualIndex = findActualIndex(index);if (actualIndex !== -1) {@@ -165,7 +170,7 @@ function removeSnippet(index: number) {// Clear selection if deleted snippet was selectedselectedSnippets.value = selectedSnippets.value.filter(i => i !== index);-+ preferences.set('snippets', snippets.value);// Cancel editing if we're editing this snippetif (editingIndex.value === index) {cancelEdit();@@ -195,6 +200,7 @@ function deleteSelected() {actualIndices.forEach(index => {snippets.value.splice(index, 1);+ preferences.set('snippets', snippets.value);});selectedSnippets.value = [];@@ -215,6 +221,7 @@ function saveEdit() {const actualIndex = findActualIndex(editingIndex.value);if (actualIndex !== -1) {snippets.value[actualIndex] = { ...editingSnippet.value };+ preferences.set('snippets', snippets.value);}cancelEdit();}@@ -227,19 +234,17 @@ function cancelEdit() {}function error(shortcut: string): string | false {- if (!shortcut.trim()) return 'Shortcut is required';- const otherSnippets = snippets.value.filter((_, index) => index !== (editingIndex.value !== null ? findActualIndex(editingIndex.value) : -1));- if (otherSnippets.some(snippet => snippet.id === shortcut)) {- return 'This shortcut already exists';+ // Return This shortcut already exists if duplicate+ const isDuplicate = snippets.value.some((snippet, index) => {+ const actualIndex = findActualIndex(index);+ return snippet.id === shortcut && actualIndex !== findActualIndex(editingIndex.value ?? -1);+ });+ if (isDuplicate) {+ return 'This shortcut already exists.';}-return false;}-function getPreviewHtml(content: string): string {- return compile(content);-}-function exportSnippets() {const dataStr = JSON.stringify(snippets.value, null, 2);const dataBlob = new Blob([dataStr], { type: 'application/json' });@@ -274,9 +279,8 @@ function handleFileImport(event: Event) {snippets.value = [...snippets.value, ...newSnippets];}- } catch (error) {- console.error('Failed to import snippets:', error);- alert('Failed to import snippets. Please check the file format.');+ } catch {+ useNotifications().add({ title: 'Failed to import snippets. Please check the file format.', type: 'error' });}};@@ -371,6 +375,8 @@ watch(searchQuery, () => {// Snippets container.snippets-container {min-height: 200px;+ background-color: var(--bg-ui);+ border-radius: 12px;}.no-snippets {@@ -386,7 +392,6 @@ watch(searchQuery, () => {p {margin: 0;- font-size: 1.1rem;}}@@ -405,16 +410,12 @@ watch(searchQuery, () => {// Snippet card.snippet-card {position: relative;- padding: 1rem;- border: 1px solid var(--border-color);+ padding: 0.5rem 1rem;border-radius: 8px;- background: var(--bg-color);- box-shadow: 0 2px 8px rgb(0 0 0 / 10%);transition: all 0.2s ease;&:hover {- border-color: var(--primary-border);- box-shadow: 0 4px 16px rgb(0 0 0 / 15%);+ background-color: var(--bg-ui);}&.selected {@@ -424,7 +425,6 @@ watch(searchQuery, () => {&.editing {border-color: var(--green);- box-shadow: 0 4px 16px var(--green-border);}}@@ -433,8 +433,6 @@ watch(searchQuery, () => {display: flex;align-items: center;justify-content: space-between;- margin-bottom: 0.75rem;- padding-bottom: 0.5rem;}.snippet-header-left {@@ -444,8 +442,8 @@ watch(searchQuery, () => {}.snippet-checkbox {- width: 18px;- height: 18px;+ width: 17px;+ height: 17px;cursor: pointer;}@@ -522,29 +520,17 @@ watch(searchQuery, () => {// View mode content.snippet-content {- .preview-label,.raw-label {font-size: 0.85rem;font-weight: 600;}- .preview-content {- padding: 0.35rem 0;- border-radius: 6px;- font-size: 0.9rem;- background: var(--bg-color-secondary);- }-.raw-content {margin: 0;- padding: 0.35rem 0;- border-radius: 6px;font-family: $monospace-font;- font-size: 0.85rem;line-height: 1.4;background: var(--code-bg);- white-space: pre-wrap;- word-break: break-word;+ white-space: nowrap;}}