paperclip/ui/src/lib
Devin Foley d202631016
fix: autoformat pasted markdown in inline editor (#2673)
## Thinking Path

> - Paperclip orchestrates AI agents for zero-human companies
> - The inline markdown editor (MarkdownEditor / MDXEditor) is used to
edit agent instructions, issue descriptions, and other content
> - When users paste agent instructions copied from terminals or
consoles, extra leading whitespace is uniformly added to every line
> - PR #2572 fixed markdown structure preservation on paste but did not
address the leading whitespace (dedent) problem
> - This pull request adds a Lexical paste normalization plugin that
strips common leading whitespace and normalizes line endings before
MDXEditor processes pasted content
> - The benefit is that pasted content from terminals/consoles renders
correctly without manual cleanup

## What Changed

- **`ui/src/lib/normalize-markdown.ts`** — Pure utility that computes
minimum common indentation across non-empty lines and strips it
(dedent), plus CRLF → LF normalization
- **`ui/src/lib/paste-normalization.ts`** — Lexical `PASTE_COMMAND`
plugin at `CRITICAL` priority that intercepts plain-text pastes,
normalizes the markdown, and re-dispatches cleaned content for MDXEditor
to process. Skips HTML-rich pastes.
- **`ui/src/components/MarkdownEditor.tsx`** — Registers the new plugin;
updates PR #2572's `handlePasteCapture` to use `normalizeMarkdown()`
(dedent + CRLF) instead of `normalizePastedMarkdown()` (CRLF only) for
the markdown-routing path
- **`ui/src/lib/paste-normalization.test.ts`** — 9 unit tests covering
dedent, CRLF normalization, mixed indent, empty lines, single-line
passthrough, and edge cases

## Verification

- `pnpm --dir ui exec vitest run src/lib/paste-normalization.test.ts` —
9 tests pass
- Manual: paste indented agent instructions from a terminal into any
inline markdown editor and confirm leading whitespace is stripped

## Risks

- Low risk. The plugin only activates for plain-text pastes (no HTML
clipboard data). HTML/rich pastes pass through unchanged. Single-line
pastes are not modified. The dedent logic is conservative — it only
strips whitespace common to all non-empty lines.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-04 11:21:27 -07:00
..
agent-icons.ts Fix markdown mention chips 2026-03-23 16:57:27 -05:00
agent-order.ts Preserve sidebar order in company portability 2026-03-23 16:57:59 -05:00
agent-skills-state.test.ts Add unmanaged skill provenance to agent skills 2026-03-18 14:21:50 -05:00
agent-skills-state.ts Add unmanaged skill provenance to agent skills 2026-03-18 14:21:50 -05:00
assignees.test.ts fix: address greptile feedback 2026-03-20 06:18:00 -05:00
assignees.ts fix: address greptile feedback 2026-03-20 06:18:00 -05:00
color-contrast.ts fix: improve pill contrast by using WCAG contrast ratios on composited backgrounds 2026-03-23 16:57:27 -05:00
comment-submit-draft.test.ts Fix optimistic comment draft clearing 2026-03-30 14:14:36 -05:00
comment-submit-draft.ts Fix optimistic comment draft clearing 2026-03-30 14:14:36 -05:00
company-export-selection.test.ts Default recurring task exports to checked 2026-03-23 16:57:38 -05:00
company-export-selection.ts Default recurring task exports to checked 2026-03-23 16:57:38 -05:00
company-page-memory.ts Add browser-based board CLI auth flow 2026-03-23 08:46:05 -05:00
company-portability-sidebar.test.ts Preserve sidebar order in company portability 2026-03-23 16:57:59 -05:00
company-portability-sidebar.ts Preserve sidebar order in company portability 2026-03-23 16:57:59 -05:00
company-routes.test.ts Fix execution workspace company routing 2026-03-29 10:55:21 -05:00
company-routes.ts Fix execution workspace company routing 2026-03-29 10:55:21 -05:00
company-selection.test.ts Fix manual company switch route sync 2026-03-13 09:47:01 -05:00
company-selection.ts Fix manual company switch route sync 2026-03-13 09:47:01 -05:00
groupBy.ts Add shared UI primitives, contexts, and reusable components 2026-02-17 09:57:00 -06:00
inbox.test.ts fix(inbox): prefer canonical last activity 2026-04-03 07:24:33 -05:00
inbox.ts fix(inbox): prefer canonical last activity 2026-04-03 07:24:33 -05:00
instance-settings.test.ts Add username log censor setting 2026-03-20 08:50:00 -05:00
instance-settings.ts Add username log censor setting 2026-03-20 08:50:00 -05:00
issue-timeline-events.test.ts fix(ui): polish issue detail timelines and attachments 2026-04-02 11:51:40 -05:00
issue-timeline-events.ts fix(ui): polish issue detail timelines and attachments 2026-04-02 11:51:40 -05:00
issueDetailBreadcrumb.test.ts fix(ui): polish issue detail timelines and attachments 2026-04-02 11:51:40 -05:00
issueDetailBreadcrumb.ts fix(ui): polish issue detail timelines and attachments 2026-04-02 11:51:40 -05:00
keyboardShortcuts.test.ts merge master into pap-1078-qol-fixes 2026-04-02 13:14:20 -05:00
keyboardShortcuts.ts fix(ui): address final Greptile follow-up 2026-04-02 12:21:35 -05:00
legacy-agent-config.test.ts Hide deprecated agent working directory by default 2026-03-20 07:04:41 -05:00
legacy-agent-config.ts Hide deprecated agent working directory by default 2026-03-20 07:04:41 -05:00
markdownPaste.test.ts Fix markdown paste handling in document editor (#2572) 2026-04-03 08:50:48 -07:00
markdownPaste.ts Fix markdown paste handling in document editor (#2572) 2026-04-03 08:50:48 -07:00
mention-aware-link-node.test.ts Extract mention-aware link node helper and add tests 2026-03-23 20:46:19 -05:00
mention-aware-link-node.ts Extract mention-aware link node helper and add tests 2026-03-23 20:46:19 -05:00
mention-chips.ts fix(ci): refresh lockfile in PR jobs 2026-03-23 19:23:10 -05:00
mention-deletion.test.ts Fix atomic markdown mention deletion 2026-03-23 16:57:27 -05:00
mention-deletion.ts Fix atomic markdown mention deletion 2026-03-23 16:57:27 -05:00
model-utils.ts Fix remaining OpenCode review comments 2026-03-05 16:07:12 +01:00
normalize-markdown.test.ts fix: autoformat pasted markdown in inline editor (#2673) 2026-04-04 11:21:27 -07:00
normalize-markdown.ts fix: autoformat pasted markdown in inline editor (#2673) 2026-04-04 11:21:27 -07:00
onboarding-goal.test.ts Improve onboarding defaults and issue goal fallback 2026-03-12 08:50:31 -05:00
onboarding-goal.ts Improve onboarding defaults and issue goal fallback 2026-03-12 08:50:31 -05:00
onboarding-launch.test.ts Seed onboarding project and issue goal context 2026-03-24 11:48:59 -05:00
onboarding-launch.ts Seed onboarding project and issue goal context 2026-03-24 11:48:59 -05:00
onboarding-route.test.ts test: harden onboarding route coverage 2026-03-18 08:00:02 -05:00
onboarding-route.ts test: harden onboarding route coverage 2026-03-18 08:00:02 -05:00
optimistic-issue-comments.test.ts Improve queued comment thread UX 2026-03-29 10:57:34 -05:00
optimistic-issue-comments.ts Improve queued comment thread UX 2026-03-29 10:57:34 -05:00
paste-normalization.ts fix: autoformat pasted markdown in inline editor (#2673) 2026-04-04 11:21:27 -07:00
portable-files.ts Add company logo portability support 2026-03-19 07:24:04 -05:00
project-order.ts refactor: rename packages to @paperclipai and CLI binary to paperclipai 2026-03-03 08:45:26 -06:00
project-workspaces-tab.test.ts Add workspace runtime controls 2026-03-29 10:55:26 -05:00
project-workspaces-tab.ts feat(routines): add workspace-aware routine runs 2026-04-02 11:38:57 -05:00
queryKeys.ts Add feedback voting and thumbs capture flow 2026-04-02 09:11:49 -05:00
recent-assignees.ts Sort assignee picker: recent selections first, then alphabetical 2026-03-05 11:19:56 -06:00
router.tsx feat: company-prefixed routing, delete tests, docs favicon, and skills 2026-03-02 09:07:09 -06:00
routine-trigger-patch.test.ts fix: address greptile routine review 2026-03-20 16:26:29 -05:00
routine-trigger-patch.ts fix: address greptile routine review 2026-03-20 16:26:29 -05:00
status-colors.ts feat(ui): light/dark theme toggle and light mode color support 2026-02-26 16:33:29 -06:00
timeAgo.ts Add shared UI primitives, contexts, and reusable components 2026-02-17 09:57:00 -06:00
utils.ts fix: append short UUID suffix to project slugs when non-ASCII characters are stripped to prevent slug collisions 2026-03-31 16:35:30 +00:00
worktree-branding.ts Add worktree UI branding 2026-03-13 11:12:43 -05:00
zip.test.ts Handle directory entries in imported zip archives 2026-03-20 14:09:21 -05:00
zip.ts Handle directory entries in imported zip archives 2026-03-20 14:09:21 -05:00