add startOfLine option
This commit is contained in:
@@ -45,7 +45,10 @@ export default class BlockquoteNode extends Node {
|
||||
return [
|
||||
suggestionsPlugin({
|
||||
debug: true,
|
||||
matcher: triggerCharacter('@', { allowSpaces: false }),
|
||||
matcher: triggerCharacter('@', {
|
||||
allowSpaces: true,
|
||||
startOfLine: false,
|
||||
}),
|
||||
onEnter(args) {
|
||||
console.log('start', args);
|
||||
},
|
||||
|
||||
@@ -8,16 +8,18 @@ import { Decoration, DecorationSet } from 'prosemirror-view';
|
||||
* @param {Boolean} allowSpaces
|
||||
* @returns {function(*)}
|
||||
*/
|
||||
export function triggerCharacter(char, { allowSpaces = false }) {
|
||||
export function triggerCharacter(char, { allowSpaces = false, startOfLine = false }) {
|
||||
|
||||
/**
|
||||
* @param {ResolvedPos} $position
|
||||
*/
|
||||
return $position => {
|
||||
// Matching expressions used for later
|
||||
const suffix = new RegExp(`\\s${char}$`);
|
||||
const prefix = startOfLine ? '^' : ''
|
||||
const regexp = allowSpaces
|
||||
? new RegExp(`${char}.*?(?=\\s${char}|$)`, 'g')
|
||||
: new RegExp(`(?:^)?${char}[^\\s${char}]*`, 'g');
|
||||
? new RegExp(`${prefix}${char}.*?(?=\\s${char}|$)`, 'g')
|
||||
: new RegExp(`${prefix}(?:^)?${char}[^\\s${char}]*`, 'g');
|
||||
|
||||
// Lookup the boundaries of the current node
|
||||
const textFrom = $position.before();
|
||||
|
||||
Reference in New Issue
Block a user