@chatwoot/prosemirror-schema
Advanced tools
Comparing version 1.0.11 to 1.0.12
{ | ||
"name": "@chatwoot/prosemirror-schema", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"description": "Schema setup for using prosemirror in chatwoot. Based on 👉 https://github.com/ProseMirror/prosemirror-example-setup/", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -9,4 +9,4 @@ /** | ||
export const triggerCharacters = char => $position => { | ||
const regexp = new RegExp(`(?:^)?${char}[^\\s${char}]*`, 'g'); | ||
export const triggerCharacters = (char, minChars = 0) => $position => { | ||
const regexp = new RegExp(`(^|\\s)(${char}[^\\s${char}]{${minChars},})`, 'g'); | ||
@@ -22,13 +22,13 @@ const textFrom = $position.before(); | ||
while ((match = regexp.exec(text))) { | ||
const prefix = match.input.slice(Math.max(0, match.index - 1), match.index); | ||
if (!/^[\s\0]?$/.test(prefix)) { | ||
// eslint-disable-next-line | ||
continue; | ||
} | ||
const beforeChar = match[1]; // Will be empty at start of text, or a space in the middle | ||
const fullMatch = match[2]; // Includes the trigger character and following text | ||
const from = match.index + $position.start(); | ||
let to = from + match[0].length; | ||
const from = match.index + $position.start() + beforeChar.length; | ||
const to = from + fullMatch.length; | ||
if (from < $position.pos && to >= $position.pos) { | ||
return { range: { from, to }, text: match[0] }; | ||
const trimmedText = fullMatch | ||
? fullMatch.slice(char.length).trim() | ||
: ""; // Remove trigger char and trim | ||
return { range: { from, to }, text: trimmedText }; | ||
} | ||
@@ -35,0 +35,0 @@ } |
Sorry, the diff of this file is too big to display
183838