fix: support all characters for suggestion char, fix #2385

This commit is contained in:
Philipp Kühn
2022-01-13 13:57:33 +01:00
parent 1dcbefd08b
commit 42d3ee8fc9
3 changed files with 7 additions and 6 deletions

View File

@@ -21,6 +21,7 @@ export * from './pasteRules/markPasteRule'
export * from './pasteRules/textPasteRule' export * from './pasteRules/textPasteRule'
export * from './utilities/callOrReturn' export * from './utilities/callOrReturn'
export * from './utilities/escapeForRegEx'
export * from './utilities/mergeAttributes' export * from './utilities/mergeAttributes'
export * from './helpers/combineTransactionSteps' export * from './helpers/combineTransactionSteps'

View File

@@ -0,0 +1,4 @@
// source: https://stackoverflow.com/a/6969486
export function escapeForRegEx(string: string): string {
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
}

View File

@@ -1,4 +1,4 @@
import { Range } from '@tiptap/core' import { Range, escapeForRegEx } from '@tiptap/core'
import { ResolvedPos } from 'prosemirror-model' import { ResolvedPos } from 'prosemirror-model'
export interface Trigger { export interface Trigger {
@@ -24,11 +24,7 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch {
$position, $position,
} = config } = config
// Matching expressions used for later const escapedChar = escapeForRegEx(char)
const escapedChar = char
.split('')
.map(c => `\\${c}`)
.join('')
const suffix = new RegExp(`\\s${escapedChar}$`) const suffix = new RegExp(`\\s${escapedChar}$`)
const prefix = startOfLine ? '^' : '' const prefix = startOfLine ? '^' : ''
const regexp = allowSpaces const regexp = allowSpaces