Skip to content

Conversation

@MarcelRobitaille
Copy link
Collaborator

@MarcelRobitaille MarcelRobitaille commented Jul 22, 2022

Fixes #903

I'm creating a pull request so we can keep track of the remaining tasks for this issue in this first comment:

Generalization:

  • It currently only works on EditInputGroup. To prevent duplicating code, consider Vue mixin.

Responsiveness:

  • Ensure the popup does not go off screen if the # appears in the right of the input.
  • Make the popup width: 100%, left: 0 for small screens.
  • The popup should have a maximum height. If this maximum height is reached, it should be possible to scroll with the mouse wheel AND by navigating through the options with up and down arrow keys.

I'm not sure if you can edit this comment. If not, if there are any other to-do items, please leave a comment and I will update this list.

@MarcelRobitaille MarcelRobitaille marked this pull request as draft July 22, 2022 19:47
@github-actions
Copy link

github-actions bot commented Jul 22, 2022

Unit Test Results

     33 files       33 suites   7m 0s ⏱️
   403 tests    403 ✔️ 0 💤 0
4 433 runs  4 433 ✔️ 0 💤 0

Results for commit 92d6349.

♻️ This comment has been updated with latest results.

@MarcelRobitaille MarcelRobitaille force-pushed the 903-link-suggestions branch 2 times, most recently from 2620fd7 to 2a708da Compare July 25, 2022 15:45
Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
@MarcelRobitaille
Copy link
Collaborator Author

I added scrolling, including keeping the focused element centered when using the arrow keys. Also made some visual improvements.

Peek.2022-07-25.12-05.mp4

Signed-off-by: Marcel Robitaille <[email protected]>
Give it a maximum height and let it scroll with the mouse wheel or when
changing the focused element with up/down arrow keys.

Signed-off-by: Marcel Robitaille <[email protected]>
Previously, the caret position was used for the popup offset. Since the
\# was just typed, the caret was to the right of the hash. The result
was that the popup looked misaligned. It was left aligned to the text
coming after the #, but not to the left of the # itself.

Signed-off-by: Marcel Robitaille <[email protected]>
If the text coming after # becomes so long that the "word" is wrapped to
the next line, move the popup down and left accordingly.

Signed-off-by: Marcel Robitaille <[email protected]>
Signed-off-by: Marcel Robitaille <[email protected]>
Create a mixin to easily apply SuggestionsPopup logic to EditInputField
and EditInputGroup without duplicating logic

Signed-off-by: Marcel Robitaille <[email protected]>
Just check if the list of suggestions is nullish / empty

Signed-off-by: Marcel Robitaille <[email protected]>
Move some of the computed attributes and other logic to the component
itself. Reduces the data passed around

Signed-off-by: Marcel Robitaille <[email protected]>
I noticed sometimes it starts scrolled down. Maybe this happens if you
scroll down, close the popup, and open it again

Signed-off-by: Marcel Robitaille <[email protected]>
@MarcelRobitaille
Copy link
Collaborator Author

MarcelRobitaille commented Jul 25, 2022

I used a mixin to implement this in EditInputField as well and did some other cleanup.

Peek.2022-07-25.15-31.mp4

I should also mention that I fixed the popup overflowing to the right (it will be right-aligned and not aligned with the # if there is not enough space) and I update the popup position when the text wraps.

Peek.2022-07-25.15-52.mp4

@MarcelRobitaille MarcelRobitaille marked this pull request as ready for review July 25, 2022 19:42
@christianlupus christianlupus added this to the Release 0.9.14 milestone Jul 26, 2022
@christianlupus
Copy link
Collaborator

I just wanted to test the extension and I am facing issues. When I want to select a recipe from the popup (both using enter as well as a mouse click), the popup is not closed and the console shows an error:
grafik


Another thing that I have seen and that might be a bit suboptimal from UX perspective: When you want to enter a link and type #ap (for apple pie), you can "loose" the popover by pressing ESC or moving the focus to another location (all right). When you decide that you want to continue typing the recipe name, nothing is happening anymore. You have to remove the # in order to trigger the popup again.

Was it possible to extend the functionality such that if you type at the end of any word that started with a single # to open the popover dialog as well?

@seyfeb
Copy link
Collaborator

seyfeb commented Jul 26, 2022

Was it possible to extend the functionality such that if you type at the end of any word that started with a single # to open the popover dialog as well?

One word of caution: this should not lead to repeatedly opening the popup after the user has canceled the selection (with ESC, the arrow keys, or sth.) and continues typing otherwise this would be annoying :D It might make sense if the user has navigated to a completely unrelated part and returns back to the end of the string starting with a #

@christianlupus
Copy link
Collaborator

That is true. However, as far as I understand the idea, the user "just" does not have to press enter to be allowed to type anything he/she likes. Only pressing enter or selecting with the pointer/mouse will replace the word with the link. Pressing Esc Enter would allow inserting a line break directly after a word beginning with #.

@MarcelRobitaille
Copy link
Collaborator Author

Sorry about that. I did some major refactoring and didn't test everything well enough. I'll fix it.

Signed-off-by: Marcel Robitaille <[email protected]>
@MarcelRobitaille
Copy link
Collaborator Author

I fixed the bug.

I also implemented recovery of the popup when the focus comes back. This will not recover if the popup was dismissed with escape or arrow keys. Is this the desired behaviour? It's hard to see my clicks in the video. I click outside the textarea then I click back inside the textarea.

Peek.2022-07-26.17-45.mp4

@christianlupus
Copy link
Collaborator

OK, I tested once more.

The bug I reported is still present: You cannot insert any link to the description field. The other fields do work as these are EditInputGroups. But the description is an EditInputField which is missing the handleSuggestionSelected method used in the mixin.

Second, I think the fix for the hidden popup is not working on my machine:

903-no-links.mp4

@MarcelRobitaille
Copy link
Collaborator Author

Hi @christianlupus. Thanks for testing it. I think the first issue has to do with the markdown editor. I am getting an error related to pasteString: TypeError: field.editor is undefined. I logged this.$refs.inputField, which is a dom node with no editor attribute. I'm not sure how this is supposed to work, and I'm not sure how I could have changed this with this PR.

The video is interesting. I will look into it.

@christianlupus
Copy link
Collaborator

Hi @christianlupus. Thanks for testing it. I think the first issue has to do with the markdown editor. I am getting an error related to pasteString: TypeError: field.editor is undefined. I logged this.$refs.inputField, which is a dom node with no editor attribute. I'm not sure how this is supposed to work, and I'm not sure how I could have changed this with this PR.

This is a leftover from an old implementation I removed for security reasons (high-risk npm audit warning). The old editor was a Vue component that declared itself as Markdown editor. It looked much like a plain textarea. As the component has not received any updates for over 2 years, I removed it as stale.

The video is interesting. I will look into it.

FYI: This is made on Linux with Firefox.

When the suggestion is selected, the search text should be replaced by
the reference. The old version was just inserting the reference.

This also fixes `EditInputField` where `pasteString` is broken

Signed-off-by: Marcel Robitaille <[email protected]>
@MarcelRobitaille
Copy link
Collaborator Author

MarcelRobitaille commented Jul 28, 2022

I realized that just doing paste on submit was the wrong approach. We need to remove the search text and insert the reference. This must keep the text before and after intact. @christianlupus noticed this in the video where the search text was remaining.

As a result, the issue of the discrepancy between EditInputGroup and EditInputField selection is fixed. I implemented the above logic in a way that it works for both and does not rely on pasteString.

This video shows that the search text is correctly replaced. In previous versions, the search text would remain after the inserted reference.

Peek.2022-07-28.02-12.mp4

I still do not know why the popup is not recovered properly in your video. Would you try the latest version? I added some logging that might help track down what's going on. I also realized it would be possible to implement that feature with css and a sibling selector. That could be a good option as well. It's fewer event listeners to set up every time the component is used at any rate.

@christianlupus
Copy link
Collaborator

Now, it seems to work rock-solid. I like it! 💯 🚀

Do you want to clean up the debug logs or comment them out in some other way? Please let me know, when you are finished with the PR.

@MarcelRobitaille
Copy link
Collaborator Author

Glad you like it!

Actually I just noticed one other problem. You can confuse the system if you click inside the textarea to change the caret position.

Peek.2022-07-29.15-29.mp4

GitHub just closes the popup if the caret changes by click, even if the new position is between the # and the next space.

The system gets confused if the caret position changes without it
realising. Arrow keys are handled, but clicking the mouse was not.

Signed-off-by: Marcel Robitaille <[email protected]>
@MarcelRobitaille
Copy link
Collaborator Author

I can remove the logs if you want, but I only added them to track down your recovery bug. I did not change anything about that besides adding the logs, so I expected the bug to still be there.

Also, is there a good way to avoid all of this https://github.com/MarcelRobitaille/cookbook/blob/903-link-suggestions/src/components/EditInputField.vue#L12-L15? Right now, it's duplicated in 4 different places. Plus, you have to remember to call handleSuggestionsPopupKeyDown in the keyUp handler: https://github.com/MarcelRobitaille/cookbook/blob/903-link-suggestions/src/components/EditInputGroup.vue#L289

@christianlupus
Copy link
Collaborator

I can remove the logs if you want, but I only added them to track down your recovery bug. I did not change anything about that besides adding the logs, so I expected the bug to still be there.

I have not been able to reproduce the problem. To prevent filling up the console of the production, I added a config flag to hide them by default. Only if the environment variable VERBOSE is set to 1 during running npm run build-dev or similar commands, the debug logging is put out.

This will allow us to debug if the problem comes up again.

Also, is there a good way to avoid all of this https://github.com/MarcelRobitaille/cookbook/blob/903-link-suggestions/src/components/EditInputField.vue#L12-L15? Right now, it's duplicated in 4 different places.

I am not aware of a way to shorten that. You will have to register with all components the appropriate event listeners. Are you only concerned that you want to write less code or because you fear breaking changes in the future if the code grows further?

Plus, you have to remember to call handleSuggestionsPopupKeyDown in the keyUp handler: https://github.com/MarcelRobitaille/cookbook/blob/903-link-suggestions/src/components/EditInputGroup.vue#L289

Here am not sure if this can be simplified. I am thinking if this could work by adding another layer of components as an abstraction that will handle the majority of the event handling. Then the effect would be restricted to a hand full of files. But I have no overview of the current state of the components and I thus cannot provide well-educated feedback.

Copy link
Collaborator

@christianlupus christianlupus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@christianlupus
Copy link
Collaborator

I just approved. So, you can merge yourself. If you see fit, you can merge now and think about any code style enhancements later or try to enhance directly in this PR. This is up to you, @MarcelRobitaille.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discussion/UI/UX: Handling of sharp for use with markdown and links

3 participants