mirror of
https://github.com/zadam/trilium.git
synced 2025-11-07 13:56:11 +01:00
shortcut negation syntax
This commit is contained in:
@@ -83,6 +83,10 @@ function lexer(str) {
|
||||
|
||||
continue;
|
||||
}
|
||||
else if (['#', '~'].includes(currentWord) && chr === '!') {
|
||||
currentWord += chr;
|
||||
continue;
|
||||
}
|
||||
else if (chr === ' ') {
|
||||
finishWord();
|
||||
continue;
|
||||
@@ -93,7 +97,10 @@ function lexer(str) {
|
||||
finishWord();
|
||||
continue;
|
||||
}
|
||||
else if (fulltextEnded && previousOperatorSymbol() !== isOperatorSymbol(chr)) {
|
||||
else if (fulltextEnded
|
||||
&& !['#!', '~!'].includes(currentWord)
|
||||
&& previousOperatorSymbol() !== isOperatorSymbol(chr)) {
|
||||
|
||||
finishWord();
|
||||
|
||||
currentWord += chr;
|
||||
|
||||
@@ -70,8 +70,8 @@ function getExpression(tokens, parsingContext, level = 0) {
|
||||
i++;
|
||||
|
||||
return new OrExp([
|
||||
NoteContentUnprotectedFulltextExp(operator, [tokens[i]]),
|
||||
NoteContentProtectedFulltextExp(operator, [tokens[i]])
|
||||
new NoteContentUnprotectedFulltextExp(operator, [tokens[i]]),
|
||||
new NoteContentProtectedFulltextExp(operator, [tokens[i]])
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -134,6 +134,22 @@ function getExpression(tokens, parsingContext, level = 0) {
|
||||
parsingContext.addError(`Unrecognized note property "${tokens[i]}"`);
|
||||
}
|
||||
|
||||
function parseAttribute(name) {
|
||||
const isLabel = name.startsWith('#');
|
||||
|
||||
name = name.substr(1);
|
||||
|
||||
const isNegated = name.startsWith('!');
|
||||
|
||||
if (isNegated) {
|
||||
name = name.substr(1);
|
||||
}
|
||||
|
||||
const subExp = isLabel ? parseLabel(name) : parseRelation(name);
|
||||
|
||||
return isNegated ? new NotExp(subExp) : subExp;
|
||||
}
|
||||
|
||||
function parseLabel(labelName) {
|
||||
parsingContext.highlightedTokens.push(labelName);
|
||||
|
||||
@@ -234,15 +250,8 @@ function getExpression(tokens, parsingContext, level = 0) {
|
||||
if (Array.isArray(token)) {
|
||||
expressions.push(getExpression(token, parsingContext, level++));
|
||||
}
|
||||
else if (token.startsWith('#')) {
|
||||
const labelName = token.substr(1);
|
||||
|
||||
expressions.push(parseLabel(labelName));
|
||||
}
|
||||
else if (token.startsWith('~')) {
|
||||
const relationName = token.substr(1);
|
||||
|
||||
expressions.push(parseRelation(relationName));
|
||||
else if (token.startsWith('#') || token.startsWith('~')) {
|
||||
expressions.push(parseAttribute(token));
|
||||
}
|
||||
else if (['orderby', 'limit'].includes(token)) {
|
||||
if (level !== 0) {
|
||||
|
||||
Reference in New Issue
Block a user