diff options
| author | haoyuren <13851610112@163.com> | 2026-03-13 00:52:59 -0500 |
|---|---|---|
| committer | haoyuren <13851610112@163.com> | 2026-03-13 00:52:59 -0500 |
| commit | 52a5c24f5e28a4b2ba8ffb006874cd7b552d60f7 (patch) | |
| tree | 2dc6182077eb3d3a5d6d1a5f655cde1896435cad /src/main/overleafSocket.ts | |
| parent | a0dd3d7ac642111faeaefd02c5a452898b9c6d49 (diff) | |
Rename to LatteX, add LaTeX autocomplete, fix comment highlight positionsv0.1.0
- 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 <noreply@anthropic.com>
Diffstat (limited to 'src/main/overleafSocket.ts')
| -rw-r--r-- | src/main/overleafSocket.ts | 31 |
1 files changed, 28 insertions, 3 deletions
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 } } |
