fix: support all characters for suggestion char, fix #2385
This commit is contained in:
@@ -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'
|
||||||
|
|||||||
4
packages/core/src/utilities/escapeForRegEx.ts
Normal file
4
packages/core/src/utilities/escapeForRegEx.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// source: https://stackoverflow.com/a/6969486
|
||||||
|
export function escapeForRegEx(string: string): string {
|
||||||
|
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user