[research] Composer: detect pasted code and offer a fenced code block #107
Open
opened 2026-09-17 01:39:34 -04:00 by jared
·
1 comment
No Branch/Tag Specified
lotus
update-packages
sw-fix
read-me-update
image-path-changes
dm-calls
fix-2469
renovate/element-hq-element-call-embedded-0.x
renovate/npm-i18next-http-backend-vulnerability
renovate/npm-vite-vulnerability
dev
docs-update
more-theme
fix-257
imporve-thread-reply
revert-2402-improve-menu-congestion
mxidColor-toggle
update-sw-main-msg
v4.11.1
v4.10.5
v4.10.4
v4.10.3
v4.10.2
v4.10.1
v4.10.0
v4.9.1
v4.9.0
v4.8.1
v4.8.0
v4.7.1
v4.7.0
v4.6.0
v4.5.1
v4.5.0
v4.4.0
v4.3.2
v4.3.0
v4.2.3
v4.2.2
v4.2.1
v4.2.0
v4.1.0
v4.0.3
v4.0.0
v3.2.0
v3.1.0
v3.0.0
v2.2.6
v2.2.5
v2.2.4
v2.2.3
v2.2.2
v2.2.1
v2.2.0
v2.1.3
v2.1.2
v2.1.1
v2.1.0
v2.0.4
v2.0.3
v2.0.2
v2.0.1
v2.0.0
v1.8.2
v1.8.1
v1.8.0
v1.7.0
v1.6.1
v1.6.0
v1.5.1
v1.5.0
v1.4.0
v1.3.2
v1.3.1
v1.3.0
v1.2.1
v1.2.0
v1.1.0
v1.0.0
Labels
Clear labels
a11y
area: appearance
area: auth-session
area: build-ci
area: calls
area: desktop
area: media
area: messaging
area: mobile
area: moderation
area: navigation
area: notifications
area: settings
area: threads
bug
dependencies
docs
duplicate
enhancement
help wanted
invalid
needs-human-review
performance
planning
priority: critical
priority: high
priority: low
priority: medium
qa
question
research
security
tech-debt
ux
wontfix
Accessibility: keyboard, screen reader, contrast, motion
Client area: appearance
Client area: auth-session
Client area: build-ci
Client area: calls
Client area: desktop
Client area: media
Client area: messaging
Client area: mobile
Client area: moderation
Client area: navigation
Client area: notifications
Client area: settings
Client area: threads
Something is not working
Third-party package versions and advisories
README / LOTUS_* docs wrong or missing
This issue or pull request already exists
New feature
Need some help
Something is wrong
Re-render storms, leaks, heavy work on hot paths
Data loss, security hole, or crash on a main path
Broken feature or serious usability problem
Minor issue or polish
Wrong behaviour in an edge case or notable degradation
Manual QA: shipped, needs a human in a real environment
More information is needed
XSS, unsafe URLs, data leaks, auth/session
Code health, dead code, fragile patterns
Usability or visual inconsistency
This won't be fixed
Milestone
No items
No Milestone
Features 2026-Q4
Projects
Clear projects
No projects
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: LotusGuild/cinny#107
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
When a multi-line paste looks like code (consistent indentation, braces/semicolons, keywords, or the clipboard carries
text/htmlfrom an editor with monospace styling), offer to wrap it in a fenced code block with a language guess instead of sending a wall of text.Research first:
src/app/features/room/RoomInput.tsxhandlePaste,src/app/components/editor/input.ts) and how code blocks are represented (BlockType.CodeBlock) and serialised toformatted_body.Deliverable: findings + a plan in this issue.
Findings (2026-09-20)
1. Paste today.
RoomInput.tsx:406-423handlePaste: first the file paste hook (useFilePasteHandler.ts— images/files → upload board), then, only when tracking-param stripping is on, it rewritestext/plainand re-inserts viaReactEditor.insertData. Everything else is Slate's defaultinsertData:text/plainis split on newlines into paragraphs (oneBlockType.Paragraphper line);text/htmlfrom editors is not consumed (Slate only usesapplication/x-slate-fragmentor plain text), so VS Code's monospace HTML is discarded — we can still read it fromclipboardDataas a signal. Code blocks areBlockType.CodeBlockcontainingBlockType.CodeLinechildren (editor/types.ts:13-14), serialised to<pre><code>…</code></pre>with one line per CodeLine (output.ts:86-90) and to the plainbodyas fenced text;toggleBlock(editor, BlockType.CodeBlock)(used by the toolbar,Toolbar.tsx:101) converts the selected paragraphs in place. No language class is emitted today (<code class="language-x">), so a language guess would be a small addition tooutput.ts.2. Heuristic (pure, unit-testable —
utils/looksLikeCode.ts). Score a paste only when it has ≥ 3 non-empty lines; require ≥ 2 of:;,{,},),:, or,(statement terminators);=/=>/->/::/()and at least one of{,},[,];function,const,let,var,return,import,export,class,def,fn,pub,struct,if (,for (,while (,#include,SELECT,FROM,<?php,</), case-sensitive except SQL;text/htmlcontainsfont-family:with a monospace face, or a<pre/<code.Hard no (prose guard): average line length > 90 chars with sentence punctuation (
.twice per line), or > 60 % of lines are plain words with spaces and no symbols, or the text is a URL list / quoted reply (>). Language guess only when confident ({+;+const|let|=>→ js/ts;def+:→ python;#include/->→ c;pub fn→ rust;SELECT→ sql), else none.3. UX recommendation: prompt, never auto-convert. After a qualifying paste, show an inline chip above the composer — "Paste as code block? ·
js· Yes · No" — for 8 s or until the next keystroke; Yes runstoggleBlock(editor, CodeBlock)over the just-inserted range (we know the selection before/after insert) and remembers the answer per session; No dismisses; typing dismisses. Ctrl/⌘-Shift-V (paste as code) as the explicit path. Auto-conversion is out: the prose guard cannot be perfect, and silently changing a message's shape erodes trust more than a dismissible chip costs. A setting "Offer to paste as code" (default on) lets people turn the chip off.4. Cost. ~120 lines heuristic + tests with fixtures (JS, Python, SQL, Rust, a log excerpt, a stack trace, prose with line breaks, a markdown list, a quoted reply), ~80 lines chip + toggle wiring, +10 in
output.tsforclass="language-x". Waiting for a yes on the prompt-vs-auto call before building.