WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-humans-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tiptap/extension-code': patch
---

Fixed inline code removing preceding character when typing
5 changes: 2 additions & 3 deletions packages/extension-code/src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ declare module '@tiptap/core' {
* This ensures that any text between backticks is formatted as code,
* regardless of the surrounding characters (exception being another backtick).
*/
export const inputRegex = /(^|[^`])`([^`]+)`(?!`)$/

export const inputRegex = /(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))$/
/**
* Matches inline code while pasting.
*/
export const pasteRegex = /(^|[^`])`([^`]+)`(?!`)/g
export const pasteRegex = /(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))/g
Comment on lines +40 to +44
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated regex patterns should have test coverage similar to the Bold extension. Consider adding a test file at packages/extension-code/__tests__/code.spec.ts to verify:

  1. The new regex correctly matches backtick-enclosed text when preceded by whitespace or at start of line
  2. The regex correctly rejects cases without proper whitespace (addressing the original bug where "a`b`" consumed the "a")
  3. Both inputRegex and pasteRegex match expected patterns

Example test structure (following Bold extension's pattern):

import { inputRegex, pasteRegex } from '@tiptap/extension-code'
import { describe, expect, it } from 'vitest'

describe('code regex test', () => {
  it('input regex matches code with space before', () => {
    expect(' `Test`').toMatch(inputRegex)
  })
  
  it('input regex matches code at start', () => {
    expect('`Test`').toMatch(inputRegex)
  })
  
  it('paste regex matches', () => {
    expect('`Test`').toMatch(pasteRegex)
  })
})

Copilot uses AI. Check for mistakes.

/**
* This extension allows you to mark text as inline code.
Expand Down
Loading