-
Notifications
You must be signed in to change notification settings - Fork 0
Move typeahead per-position suggestion logic from ProseMirror-based TypeaheadPopover to CQL-based Typeahead #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jonathonherbert
wants to merge
16
commits into
jsh/correct-mappings-like-really-correct
Choose a base branch
from
jsh/pos-based-suggestions
base: jsh/correct-mappings-like-really-correct
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8bb69f6
Get suggestions by position, rather than returning every possible sug…
jonathonherbert 0020279
Ensure one suggestion is returned from the typeahead helper at once, …
jonathonherbert e349d68
Fix issue where keys would be suggested when values were present
jonathonherbert 9f4dab6
Improve test failure messaging for assertCqlStrPosFromDocPos
jonathonherbert a96762c
Use ProseMirror positions for typeahead suggestions (which require a …
jonathonherbert 8890990
Do not attempt to show the popover if no popover exists
jonathonherbert 79acd5d
Fix remaining tests
jonathonherbert 8aec806
Add position-based mapping tests, and begin work on smoke test
jonathonherbert 6b6c260
Add property-based testing to discover edge cases
jonathonherbert 82cc5ed
Rewrite mappings using tests as a guide
jonathonherbert 3b54a46
Correct mappings, reversing the specs to test queryStr -> doc first, …
jonathonherbert f48eb32
Add mappings for quoted and escaped chipKeys and chipValues
jonathonherbert 10e1d5f
Tidy up a few things I spotted during the refactor
jonathonherbert 1dc8435
Reinstate CAPI typeahead provider for page
jonathonherbert 660b169
Merge branch 'jsh/correct-mappings-like-really-correct' into jsh/pos-…
jonathonherbert 70008ed
Merge branch 'jsh/correct-mappings-like-really-correct' into jsh/pos-…
jonathonherbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,15 +95,16 @@ export class TypeaheadPopover extends Popover { | |
| }); | ||
| } | ||
|
|
||
| public isRenderingNavigableMenu = () => this.isVisible && !!this.currentSuggestion?.suggestions.length; | ||
| public isRenderingNavigableMenu = () => | ||
| this.isVisible && !!this.currentSuggestion?.suggestions.length; | ||
|
|
||
| public updateSuggestions = ( | ||
| typeaheadSuggestions: MappedTypeaheadSuggestion[], | ||
| typeaheadSuggestion?: MappedTypeaheadSuggestion, | ||
| ) => { | ||
| this.isPending = false; | ||
| if ( | ||
| this.view.isDestroyed || | ||
| !typeaheadSuggestions.length || | ||
| !typeaheadSuggestion || | ||
| this.view.state.selection.from !== this.view.state.selection.to | ||
| ) { | ||
| this.currentSuggestion = undefined; | ||
|
|
@@ -112,19 +113,7 @@ export class TypeaheadPopover extends Popover { | |
| return; | ||
| } | ||
|
|
||
| const { selection: currentSelection } = this.view.state; | ||
| const suggestionThatCoversSelection = typeaheadSuggestions.find( | ||
| ({ from, to }) => | ||
| currentSelection.from >= from && currentSelection.to <= to, | ||
| ); | ||
|
|
||
| if (!suggestionThatCoversSelection) { | ||
| this.currentSuggestion = undefined; | ||
| this.hide(); | ||
| return; | ||
| } | ||
|
|
||
| this.currentSuggestion = suggestionThatCoversSelection; | ||
| this.currentSuggestion = typeaheadSuggestion; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic to find suggestions here has been moved to the Typeahead class |
||
| this.show(); | ||
| }; | ||
|
|
||
|
|
@@ -141,12 +130,20 @@ export class TypeaheadPopover extends Popover { | |
| } | ||
| }; | ||
|
|
||
| protected show = () => { | ||
| protected show = async () => { | ||
| if (!this.currentSuggestion) { | ||
| return Promise.resolve(); | ||
| } | ||
| const { node } = this.view.domAtPos(this.currentSuggestion.from); | ||
| return super.show(node as HTMLElement); | ||
|
|
||
| // The node given from `domAtPos` may be a text node | ||
| if (node && node instanceof HTMLElement) { | ||
| return super.show(node); | ||
| } | ||
|
|
||
| console.warn( | ||
| `[cql]: Attempted to show popover, but domAtPos did not return an element for ${this.currentSuggestion.from}`, | ||
| ); | ||
| }; | ||
|
|
||
| public handleAction: ActionHandler = (action) => { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:vRe-parsing the string derived from the new document, which may differ from the original, ensures that we get the correct tokens and mapping.