Skip to content

Commit

Permalink
Add whitespace to searchText when EOF tokens extend beyond the previo…
Browse files Browse the repository at this point in the history
…us token
  • Loading branch information
jonathonherbert committed Sep 24, 2024
1 parent d586836 commit 3798591
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions prosemirror-client/src/cqlInput/CqlInput.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ describe("CqlInput", () => {

await waitFor("example");
});

it("accepts whitespace after non-string tokens", async () => {
const { editor, waitFor } = await createCqlEditor("a AND");

await editor.insertText(" ");

await waitFor("a AND ");
});
});

describe("typeahead", () => {
Expand Down
16 changes: 13 additions & 3 deletions prosemirror-client/src/cqlInput/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const tokensToDoc = (_tokens: ProseMirrorToken[]): Node => {
const nodes = joinSearchTextTokens(_tokens).reduce<Node[]>(
(acc, token, index, tokens): Node[] => {
switch (token.tokenType) {
case "QUERY_FIELD_KEY":
case "QUERY_FIELD_KEY": {
const tokenKey = token.literal;
const tokenValue = tokens[index + 1]?.literal;
const previousToken = tokens[index - 1];
Expand All @@ -168,13 +168,23 @@ export const tokensToDoc = (_tokens: ProseMirrorToken[]): Node => {
]),
])
);
}
case "QUERY_VALUE":
case "EOF":
case "EOF": {
const previousToken = tokens[index - 1];
const previousNode = acc[acc.length - 1];
if (previousToken?.to < token.from && previousNode.type === searchText) {
return acc.slice(0, acc.length - 1).concat(
searchText.create(undefined, schema.text(previousNode.textContent + " "))
)
}
return acc;
default:
}
default: {
return acc.concat(
searchText.create(undefined, schema.text(token.lexeme))
);
}
}
},
[] as Node[]
Expand Down
4 changes: 1 addition & 3 deletions prosemirror-client/src/lang/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ export class Scanner {
private addUnquotedString = () => {
while (
// Consume whitespace up until the last whitespace char
(!isWhitespace(this.peek()) ||
isWhitespace(this.peek(1)) ||
this.isAtEnd(1)) &&
(!isWhitespace(this.peek()) || (isWhitespace(this.peek(1)) || this.isAtEnd(1))) &&
this.peek() != ")" &&
!this.isAtEnd()
) {
Expand Down

0 comments on commit 3798591

Please sign in to comment.