joplin icon indicating copy to clipboard operation
joplin copied to clipboard

Desktop: #9870: Fixed command palette not properly showing non-latin-characters

Open pedr opened this issue 1 year ago • 1 comments

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.

image image

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):

image

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:

image

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

pedr avatar Feb 09 '24 20:02 pedr

PR is ready to review again.

pedr avatar Feb 14 '24 21:02 pedr

That looks good, thanks Pedro!

laurent22 avatar Feb 19 '24 10:02 laurent22