Skip to content
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

Toggle markdown format on selected text clears selection #1807

Closed
vkbo opened this issue Apr 9, 2024 · 1 comment · Fixed by #1808
Closed

Toggle markdown format on selected text clears selection #1807

vkbo opened this issue Apr 9, 2024 · 1 comment · Fixed by #1808
Labels
bug Issue: Something isn't working editor Component: Editor
Milestone

Comments

@vkbo
Copy link
Owner

vkbo commented Apr 9, 2024

From #1804 by @HeyMyian

When highlighting a word and applying a markdown format to the word, the word stays visually highlighted. Repeated use of the markdown format however merely removes the highlight without removing the format. Otherwise, toggling markdown formatting works as expected.

@vkbo vkbo added bug Issue: Something isn't working editor Component: Editor labels Apr 9, 2024
@vkbo vkbo added this to the Release 2.4 milestone Apr 9, 2024
@vkbo
Copy link
Owner Author

vkbo commented Apr 9, 2024

I just created the ticket myself since I have a solution ready.

Turns out the issue is that when you toggle from a selection, the selection is restored "backwards" afterwards. That is, when you make a selection, the UI puts the cursor at the end of it. But the code that makes sure the selection is still present after the formatting tags are added actually applied the selection backwards so that the cursor is at the beginning.

Now, what causes the deselection is a special case that makes sure you don't add more markdown tags after existing tags, so that it doesn't produce **text in bold****|** where | is the cursor. Since the cursor was left at the beginning of the selection, the leading ** triggered this when you tried to toggle the bold format off, which cancelled the operation instead of toggling it.

This code is very convoluted because there are a lot of different behaviours depending on a bunch of conditions. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue: Something isn't working editor Component: Editor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant