Move typeahead per-position suggestion logic from ProseMirror-based TypeaheadPopover to CQL-based Typeahead#99
Conversation
3dbbcb6 to
7f5af43
Compare
7f5af43 to
184d17b
Compare
f4621d8 to
5e7291f
Compare
184d17b to
8b2f271
Compare
414d013 to
8781a4a
Compare
c6140ae to
33bc62c
Compare
…gestion for a query from the typeahead helper which breaks the current plugin behaviour, todo
…and adjust consumers
…selection position either side of a character to perform correctly), and adjust debug visualisation
to make them simpler and more comprehensible ... but although the tests pass, they are not reversible, which stretches my mental model a bit ... I need to understand better why this wasn't a problem before
…which makes the behaviour clearer I was testing an inverted mapping, making changes unintuitive D:< Having said that, I'm not quite sure why getFieldValueRanges requires a negative oldSize rather than a positive toSize for its chipValue end, which is something I arrived at via experimentation rather than a complete understanding ... dislike
cleaning up the ranges to remove the odd inversion, and expanding the property-based tests to verify they are correct
33bc62c to
1dc8435
Compare
8781a4a to
509320c
Compare
|
|
||
| /** | ||
| * These diff functions are vendored to ignore attributes and markup, as we only care about markup. | ||
| * These diff functions are vendored to ignore attributes, as we only care about markup. |
There was a problem hiding this comment.
This comment didn't make sense, tidied up on the fly
| createCqlEditor("example +tag:"); | ||
|
|
||
| await moveCaretToQueryPos(queryStr.length - 1); | ||
| await moveCaretToQueryPos(queryStr.length); |
There was a problem hiding this comment.
Some of these positions were revealed to be slightly inaccurate by the mapping changes, so they've been amended here.
| const newDoc = tokensToDoc(mapResult(parser(queryBeforeParse)).tokens); | ||
| const queryAfterParse = docToCqlStr(newDoc); | ||
| const result = parser(queryAfterParse); | ||
| const { mapping, queryAst, tokens, error } = mapResult(result); |
There was a problem hiding this comment.
Parsing twice here eliminates an issue that came up in the tests where the cql query derived by a document would not be exactly the same as the query that produced it. For example, the following could occur:
k:v -> <chip><chipKey>k</chipKey><chipValue>v</chipValue></chip> -> +k:v
Re-parsing the string derived from the new document, which may differ from the original, ensures that we get the correct tokens and mapping.
| } | ||
|
|
||
| this.currentSuggestion = suggestionThatCoversSelection; | ||
| this.currentSuggestion = typeaheadSuggestion; |
There was a problem hiding this comment.
The logic to find suggestions here has been moved to the Typeahead class
…based-suggestions
…based-suggestions
What's changed?
Prior to this PR, the typeahead API didn't reason about the document position — it provides all the possible typeahead suggestions for a query, and it was up to the UI to figure out whether a suggestion applies given the state of the UI.
This is less efficient than fetching the given suggestions for a position, but was an easy way to provide reasonable typeahead behaviour when the mapping from query to document, and vice-versa, was less than perfect.
After #103, we can map from document position to query position with confidence, and rely entirely on the
Typeaheadclass to provide the correct suggestions for the given position, which improves separation of concerns (no more reasoning about document positions inTypeaheadPopover.NB: TypeaheadPopover does couple itself to the ProseMirror view, and we'll need to remove that dependency to share it with a hypothetical non-ProseMirror based UI.
How to test
How can we measure success?