[PR #22214] [CLOSED] fix: prevent preceding character deletion when typing inline code backticks #42185

Closed
opened 2026-04-25 14:10:43 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22214
Author: @MJ16MJ
Created: 3/4/2026
Status: Closed

Base: devHead: fix/inline-code-preceding-char-deleted


📝 Commits (1)

  • bec19ca fix: prevent preceding character deletion when typing inline code backticks

📊 Changes

2 files changed (+22 additions, -1 deletions)

View changed files

📝 package.json (+1 -0)
📝 src/lib/components/common/RichTextInput.svelte (+21 -1)

📄 Description

Pull Request Checklist

Before submitting, make sure you've checked the following:

  • Target branch: dev
  • Description: Provided below.
  • Changelog: Included below.
  • Dependencies: Added @tiptap/extension-code as explicit dependency (already a transitive dep via @tiptap/starter-kit, same version ^3.0.7).
  • Testing: Manually verified the root cause by tracing TipTap's markInputRule logic with the default regex vs the fixed regex. The fix changes only the input rule regex pattern — all other Code mark behavior (keyboard shortcut, paste rules, rendering) remains unchanged.
  • Agentic AI Code: This PR has been reviewed and the fix has been verified by tracing through the TipTap source code.
  • Code review: Self-reviewed.
  • Git Hygiene: Single atomic commit, one logical change.
  • Title Prefix: fix:

Changelog Entry

Description

When "Rich Text Input for Chat" is enabled and a user types inline code using backticks immediately after text (e.g. Hello\123`), the character preceding the opening backtick is incorrectly deleted, resulting in Hell+123instead ofHello+123`.

Root cause: TipTap's default Code mark input rule uses the regex /(^|[^\x60])\x60([^\x60]+)\x60(?!\x60)$/. The first capture group [^\x60] captures the character before the opening backtick. When markInputRule processes the match, it calls tr.delete(range.from + startSpaces, textStart) which deletes everything from the match start to the code content — including that captured preceding character.

Fix: Override the Code extension from StarterKit with a custom extension (FixedCode) that uses a lookbehind assertion /(?<=[^\x60]|^)\x60([^\x60]+)\x60(?!\x60)$/ instead of a capture group, so the preceding character is never part of the match range.

Added

  • @tiptap/extension-code as explicit dependency (was already transitive via starter-kit)
  • FixedCode extension in RichTextInput.svelte that extends TipTap's Code mark with a corrected input rule

Changed

  • StarterKit configured with code: false to disable the default (buggy) Code mark
  • FixedCode added to the editor extensions list

Fixed

  • Preceding character no longer deleted when typing inline code backticks in Rich Text Input mode (e.g. Hello\123`` now correctly produces "Hello" + code("123"))

Security

  • N/A

Breaking Changes

  • N/A

Additional Information

  • Fixes [PR #688] [MERGED] Update README.md (#20417)
  • Confirmed reproducible by collaborator @silentoplayz on latest dev with "Rich Text Input for Chat" toggled on
  • The lookbehind (?<=...) is supported in all modern browsers (Chrome 62+, Firefox 78+, Safari 16.4+)
  • Only the input rule is overridden — keyboard shortcut (Mod+E), paste rules, and rendering remain unchanged from the default Code extension

Screenshots or Videos

Before (bug): Typing Hello\123`` produces "Hell" + code("123") — the "o" is deleted

After (fix): Typing Hello\123`` correctly produces "Hello" + code("123")

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/22214 **Author:** [@MJ16MJ](https://github.com/MJ16MJ) **Created:** 3/4/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/inline-code-preceding-char-deleted` --- ### 📝 Commits (1) - [`bec19ca`](https://github.com/open-webui/open-webui/commit/bec19ca517245a1d993518ab4c5cb96de2209296) fix: prevent preceding character deletion when typing inline code backticks ### 📊 Changes **2 files changed** (+22 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `package.json` (+1 -0) 📝 `src/lib/components/common/RichTextInput.svelte` (+21 -1) </details> ### 📄 Description # Pull Request Checklist **Before submitting, make sure you've checked the following:** - [x] **Target branch:** `dev` - [x] **Description:** Provided below. - [x] **Changelog:** Included below. - [x] **Dependencies:** Added `@tiptap/extension-code` as explicit dependency (already a transitive dep via `@tiptap/starter-kit`, same version `^3.0.7`). - [x] **Testing:** Manually verified the root cause by tracing TipTap's `markInputRule` logic with the default regex vs the fixed regex. The fix changes only the input rule regex pattern — all other Code mark behavior (keyboard shortcut, paste rules, rendering) remains unchanged. - [x] **Agentic AI Code:** This PR has been reviewed and the fix has been verified by tracing through the TipTap source code. - [x] **Code review:** Self-reviewed. - [x] **Git Hygiene:** Single atomic commit, one logical change. - [x] **Title Prefix:** `fix:` # Changelog Entry ### Description When "Rich Text Input for Chat" is enabled and a user types inline code using backticks immediately after text (e.g. `Hello\`123\``), the character preceding the opening backtick is incorrectly deleted, resulting in `Hell` + `123` instead of `Hello` + `123`. **Root cause:** TipTap's default Code mark input rule uses the regex `/(^|[^\x60])\x60([^\x60]+)\x60(?!\x60)$/`. The first capture group `[^\x60]` captures the character **before** the opening backtick. When `markInputRule` processes the match, it calls `tr.delete(range.from + startSpaces, textStart)` which deletes everything from the match start to the code content — including that captured preceding character. **Fix:** Override the Code extension from StarterKit with a custom extension (`FixedCode`) that uses a lookbehind assertion `/(?<=[^\x60]|^)\x60([^\x60]+)\x60(?!\x60)$/` instead of a capture group, so the preceding character is never part of the match range. ### Added - `@tiptap/extension-code` as explicit dependency (was already transitive via starter-kit) - `FixedCode` extension in `RichTextInput.svelte` that extends TipTap's Code mark with a corrected input rule ### Changed - StarterKit configured with `code: false` to disable the default (buggy) Code mark - `FixedCode` added to the editor extensions list ### Fixed - Preceding character no longer deleted when typing inline code backticks in Rich Text Input mode (e.g. `Hello\`123\`` now correctly produces "Hello" + code("123")) ### Security - N/A ### Breaking Changes - N/A --- ### Additional Information - Fixes #20417 - Confirmed reproducible by collaborator @silentoplayz on latest `dev` with "Rich Text Input for Chat" toggled on - The lookbehind `(?<=...)` is supported in all modern browsers (Chrome 62+, Firefox 78+, Safari 16.4+) - Only the input rule is overridden — keyboard shortcut (Mod+E), paste rules, and rendering remain unchanged from the default Code extension ### Screenshots or Videos **Before (bug):** Typing `Hello\`123\`` produces "Hell" + code("123") — the "o" is deleted **After (fix):** Typing `Hello\`123\`` correctly produces "Hello" + code("123") ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 14:10:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#42185