joplin
joplin copied to clipboard
Desktop: #9870: Fixed command palette not properly showing non-latin-characters
Fixes https://github.com/laurent22/joplin/issues/9870
Modify how the text highlight (surroundKeywords
function) works in the command palette to properly render non latin characters.
Description
There were two issues with this code, one happened when the keyword was set to an empty string. In this case our code in surroundKeywords
would break the text on every character (that is why you see the codes in the original issue):
I thought the easiest solution would be to change the input rather than change the regex logic, so I'm filtering the empty strings out of the keywords object: https://github.com/pedr/joplin/blob/c382ba9a61850e3f2914730af9f21122fbdbfb99/packages/app-desktop/plugins/GotoAnything.tsx#L420-L425
The other problem happened because we were escaping the characters before running the regex, the result was that we also would get a broken representation:
To fix this I changed the code to break the text into segments with the regex and join everything together again after escaping the content and adding prefixes and suffixes if required:
https://github.com/pedr/joplin/blob/c382ba9a61850e3f2914730af9f21122fbdbfb99/packages/lib/string-utils.ts#L256-L267
Testing
I added some other automated test cases to the surroundKeywords
function.
The feature can also be tested by:
- Changing the language to one with non-latin-characters
- Opening the command palette
- Search for commands, the text should be readable and highlighted
- Search for tags, the text should be readable and highlighted
PR is ready to review again.
That looks good, thanks Pedro!