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