From 52a5c24f5e28a4b2ba8ffb006874cd7b552d60f7 Mon Sep 17 00:00:00 2001 From: haoyuren <13851610112@163.com> Date: Fri, 13 Mar 2026 00:52:59 -0500 Subject: Rename to LatteX, add LaTeX autocomplete, fix comment highlight positions - Rename project from ClaudeTeX to LatteX (Cosmic Latte theme pun) - Add new coffee cup logo and branded welcome/project screens - Add 5-source LaTeX autocomplete: commands, environments, \ref, \cite, file paths - Fix comment highlight drift by decoding WebSocket-encoded UTF-8 lines and range text via decodeURIComponent(escape()), matching Overleaf's client implementation - Remove hacky byte-offset position remapping from index.ts - Add pinch-to-zoom on PDF viewer Co-Authored-By: Claude Opus 4.6 --- src/main/compilationManager.ts | 2 +- src/main/index.ts | 4 +- src/main/overleafSocket.ts | 31 +- src/renderer/index.html | 2 +- src/renderer/src/App.css | 73 ++++- src/renderer/src/App.tsx | 34 ++- src/renderer/src/components/Editor.tsx | 5 +- src/renderer/src/components/PdfViewer.tsx | 15 + src/renderer/src/components/ProjectList.tsx | 2 +- src/renderer/src/data/latexCommands.ts | 300 +++++++++++++++++++ src/renderer/src/data/latexEnvironments.ts | 98 +++++++ src/renderer/src/extensions/commentHighlights.ts | 43 ++- src/renderer/src/extensions/latexAutocomplete.ts | 349 +++++++++++++++++++++++ 13 files changed, 933 insertions(+), 25 deletions(-) create mode 100644 src/renderer/src/data/latexCommands.ts create mode 100644 src/renderer/src/data/latexEnvironments.ts create mode 100644 src/renderer/src/extensions/latexAutocomplete.ts (limited to 'src') diff --git a/src/main/compilationManager.ts b/src/main/compilationManager.ts index 3529345..8fbd946 100644 --- a/src/main/compilationManager.ts +++ b/src/main/compilationManager.ts @@ -15,7 +15,7 @@ export class CompilationManager { constructor(projectId: string, cookie: string) { this.projectId = projectId this.cookie = cookie - this.tmpDir = join(require('os').tmpdir(), `claudetex-${projectId}`) + this.tmpDir = join(require('os').tmpdir(), `lattex-${projectId}`) } get dir(): string { diff --git a/src/main/index.ts b/src/main/index.ts index 89a04b0..7fc1c4d 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -211,9 +211,9 @@ ipcMain.handle('overleaf:webLogin', async () => { // Inject a floating back button when navigated away from overleaf.com const injectBackButton = () => { loginWindow.webContents.executeJavaScript(` - if (!document.getElementById('claudetex-back-btn')) { + if (!document.getElementById('lattex-back-btn')) { const btn = document.createElement('div'); - btn.id = 'claudetex-back-btn'; + btn.id = 'lattex-back-btn'; btn.innerHTML = '← Back'; btn.style.cssText = 'position:fixed;top:8px;left:8px;z-index:999999;padding:6px 14px;' + 'background:#333;color:#fff;border-radius:6px;cursor:pointer;font:13px -apple-system,sans-serif;' + diff --git a/src/main/overleafSocket.ts b/src/main/overleafSocket.ts index 52ac20f..1a12260 100644 --- a/src/main/overleafSocket.ts +++ b/src/main/overleafSocket.ts @@ -9,6 +9,15 @@ import { encodeHeartbeat } from './overleafProtocol' +/** Decode WebSocket-encoded UTF-8 text (reverses server's unescape(encodeURIComponent(text))) */ +function decodeUtf8(text: string): string { + try { + return decodeURIComponent(escape(text)) + } catch { + return text // already decoded or pure ASCII + } +} + export interface JoinProjectResult { publicId: string project: { @@ -252,14 +261,30 @@ export class OverleafSocket extends EventEmitter { this.joinedDocs.add(docId) // Ack response format: [error, docLines, version, updates, ranges, pathname] - // First element is error (null = success) const err = result[0] if (err) throw new Error(`joinDoc failed: ${JSON.stringify(err)}`) - const docLines = (result[1] as string[]) || [] + // Server encodes lines + range text via unescape(encodeURIComponent(text)) + // for safe WebSocket transport. Decode with decodeURIComponent(escape(text)). + const rawLines = (result[1] as string[]) || [] + const docLines = rawLines.map(line => decodeUtf8(line)) const version = (result[2] as number) || 0 const updates = (result[3] as unknown[]) || [] - const ranges = (result[4] || { comments: [], changes: [] }) as JoinDocResult['ranges'] + const rawRanges = result[4] as JoinDocResult['ranges'] | undefined + + // Decode range text (op.c, op.i, op.d) — positions (op.p) stay as-is + const ranges = rawRanges || { comments: [], changes: [] } + if (ranges.comments) { + for (const c of ranges.comments) { + if (c.op?.c) c.op.c = decodeUtf8(c.op.c) + } + } + if (ranges.changes) { + for (const ch of ranges.changes as any[]) { + if (ch.op?.i) ch.op.i = decodeUtf8(ch.op.i) + if (ch.op?.d) ch.op.d = decodeUtf8(ch.op.d) + } + } return { docLines, version, updates, ranges } } diff --git a/src/renderer/index.html b/src/renderer/index.html index 1fb4779..9fa1aa8 100644 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -3,7 +3,7 @@ - ClaudeTeX + LatteX
diff --git a/src/renderer/src/App.css b/src/renderer/src/App.css index ec9cf88..2a681a5 100644 --- a/src/renderer/src/App.css +++ b/src/renderer/src/App.css @@ -83,12 +83,23 @@ html, body, #root { text-align: center; } +.welcome-logo { + margin-bottom: 20px; +} + .welcome-content h1 { - font-size: 48px; + font-size: 52px; font-weight: 700; letter-spacing: -1px; margin-bottom: 8px; color: var(--accent); + font-family: "Georgia", "Times New Roman", serif; +} + +.lattex-x { + font-weight: 800; + font-style: italic; + color: var(--accent-blue); } .welcome-content p { @@ -767,7 +778,8 @@ html, body, #root { .projects-header h1 { font-size: 22px; font-weight: 700; - color: var(--text-primary); + color: var(--accent); + font-family: "Georgia", "Times New Roman", serif; } .projects-header-actions { @@ -2039,3 +2051,60 @@ html, body, #root { opacity: 0.5; cursor: not-allowed; } + +/* ── Autocomplete ─────────────────────────────────────────────── */ + +.cm-tooltip-autocomplete { + background: var(--bg-primary) !important; + border: 1px solid var(--border) !important; + border-radius: var(--radius) !important; + box-shadow: var(--shadow-md) !important; + font-family: var(--font-mono) !important; + font-size: 12.5px !important; +} + +.cm-tooltip-autocomplete > ul { + max-height: 250px !important; +} + +.cm-tooltip-autocomplete > ul > li { + padding: 3px 8px !important; + color: var(--text-primary) !important; + line-height: 1.5; +} + +.cm-tooltip-autocomplete > ul > li[aria-selected] { + background: var(--accent-blue) !important; + color: #fff !important; +} + +.cm-tooltip-autocomplete .cm-completionLabel { + font-weight: 500; +} + +.cm-tooltip-autocomplete .cm-completionDetail { + color: var(--text-muted); + font-style: italic; + margin-left: 8px; + font-size: 11.5px; +} + +.cm-tooltip-autocomplete > ul > li[aria-selected] .cm-completionDetail { + color: rgba(255, 255, 255, 0.7); +} + +.cm-tooltip-autocomplete .cm-completionIcon { + padding: 0 4px 0 0; + opacity: 0.6; +} + +.cm-completionInfo { + background: var(--bg-secondary) !important; + border: 1px solid var(--border) !important; + border-radius: var(--radius) !important; + color: var(--text-primary) !important; + padding: 6px 10px !important; + font-family: var(--font-sans) !important; + font-size: 12px !important; + max-width: 350px; +} diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 1eb1d76..fb24a36 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -242,6 +242,21 @@ export default function App() { } } } + + // Pre-load .bib files in background for citation autocomplete + const st = useAppStore.getState() + for (const [docId, relPath] of Object.entries(st.docPathMap)) { + if (relPath.endsWith('.bib') && !st.fileContents[relPath]) { + window.api.otJoinDoc(docId).then((res) => { + if (res.success && res.content !== undefined) { + useAppStore.getState().setFileContent(relPath, res.content) + if (res.version !== undefined) { + useAppStore.getState().setDocVersion(docId, res.version) + } + } + }).catch(() => {}) + } + } } const handleBackToProjects = async () => { @@ -271,7 +286,24 @@ export default function App() {
-

ClaudeTeX

+
+ + + + + + + + + + + + + + + +
+

LatteX

LaTeX editor with real-time Overleaf sync