Skip to content

feat(composer): inline code quotes and fenced code blocks behind a flag#3530

Open
kliment-slice wants to merge 2 commits into
mainfrom
quote-input
Open

feat(composer): inline code quotes and fenced code blocks behind a flag#3530
kliment-slice wants to merge 2 commits into
mainfrom
quote-input

Conversation

@kliment-slice

@kliment-slice kliment-slice commented Jul 17, 2026

Copy link
Copy Markdown

Problem

When typing an inline quote rn backticks and triple backticks are plain text. Proposing similar mechanics to other apps out there, which render inline quotes and code blocks in the prompt composer box.

Changes

image

Adds backtick quoting to the composer, gated by the posthog-code-prompt-code-blocks feature flag (#766905, created at 0% rollout, dev builds bypass it):

  • Inline quote: `code` restyles as an inline code chip the moment the trailing backtick is typed; ArrowRight exits the mark.
  • Fenced block: ``` (optionally ```lang) + Shift+Enter opens a styled code block. The stock Tiptap input rules are stripped (they also fire on space/Enter) so Shift+Enter is the only trigger.
  • Keyboard model: Enter always submits, regardless of cursor position — including inside a code block. Shift+Enter is the only way to make a line: hard break outside, newline inside the block, fence conversion on a ``` line.
  • Arrow keys move in and out of the block; a small CodeBlockArrowExit extension mirrors Tiptap's exitOnArrowDown for ArrowUp when the block is the doc's first node. Prompt-history recall no longer hijacks arrows while inside a block.
  • Serialization: quotes serialize to standard markdown (backticks/fences) so the model sees the content verbatim and the chat thread renders it as code. Draft restore parses fences back into code blocks so persisted drafts don't corrupt code whitespace. No changes to contentToXml — markdown is plain text to the wire format.

How did you test this?

  • 33 new unit tests: markdown serialization round-trips (fences, languages, blank lines, backtick-containing code), Shift+Enter fence conversion at both positions, and flag-off schema gating. Full @posthog/ui suite passes (197 files / 1740 tests), plus pnpm typecheck and biome lint.
  • Manually, in the running Electron app over CDP: inline quote styling on the trailing backtick, fence creation via Shift+Enter, in-block newlines, Enter-submits-from-anywhere, arrow-key escapes at both block edges, ```+space staying literal, and draft round-trip across a renderer reload.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

Adds backtick quoting to the message composer, gated by the
posthog-code-prompt-code-blocks feature flag (dev builds bypass it):

- `inline code` styles as a code chip the moment the trailing backtick
  is typed; ArrowRight exits the mark.
- ``` + Shift+Enter opens a fenced code block (optionally ```lang).
  Shift+Enter inside adds newlines; the stock space/enter input rules
  are disabled so Shift+Enter is the only trigger.
- Enter always submits, regardless of cursor position — including
  inside a code block. Only Shift+Enter makes a line.
- Arrow keys move in and out of the block; a custom ArrowUp escape
  mirrors Tiptap's exitOnArrowDown for a block at the top of the doc.
- Content serializes to standard markdown (backticks/fences) so the
  model sees the quoted content verbatim and the chat thread renders
  it as code; drafts round-trip fences without corrupting whitespace.

Flag created in PostHog project 2 (#766905), active at 0% rollout.

Generated-By: PostHog Code
Task-Id: 6340d9d8-aa7e-43e6-b1de-c99c8b52c738
@trunk-io

trunk-io Bot commented Jul 17, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 291199b.

Comment thread packages/ui/src/features/message-editor/tiptap/useTiptapEditor.ts
@veria-ai

veria-ai Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

Bash-mode detection ran on editor.getText(), which strips markup — with
code quoting enabled, `!rm -rf ~` typed as an inline quote (or a fenced
block starting with !) lost its backticks and read as a leading-! bash
command, so content rendered as a quoted literal would execute as a
shell command on submit.

Detection (indicator, submit, isBashMode) now uses the serialized
content text, where quoted code keeps its backticks/fences and can
never start with !. Plain !commands are unaffected, and real bash
commands containing an inline quote now keep their backticks instead
of silently losing them.

Addresses the review finding on #3530.

Generated-By: PostHog Code
Task-Id: 6340d9d8-aa7e-43e6-b1de-c99c8b52c738
@kliment-slice
kliment-slice requested a review from k11kirky July 17, 2026 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant