add startOfLine option

This commit is contained in:
Philipp Kühn
2018-09-04 23:26:51 +02:00
parent 0e3810bca0
commit 39072b217d
2 changed files with 9 additions and 4 deletions

View File

@@ -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();