JetBrains: Encoding and bug fixes
Created by: philipp-spiess
Fixes #36280 (closed) Fixes #36166 (closed) Fixes #36144 (closed) Fixes #36231 (closed)
This PR fixes a lot if bugs that we had with our preview component. Specifically we:
- Change the content encoding in our JS -> Java bridge to be a base64 representation to avoid issues in the JSON parsing libraries (it would through before we could even do any workarounds in user space).
- Use a proper base64 encoding library on the JS side that handles all Unicode characters (
btoa()
would error on some files with[Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.](https://stackoverflow.com/questions/23223718/failed-to-execute-btoa-on-window-the-string-to-be-encoded-contains-characte)
). - Make the
content
field optional in the JS -> Java bridge to support files with no preview out of the box (We use this for when previewing binary files but also for types that do not have a preview). Note: We need to change the Java side rendering to use a label instead of the editor component when content is null. - We fix
getCharacterCountUntilLine
to ignore\r\n
the same way that our content preparation is doing so that index match again. - We query
highlight
in the Blob query to get a server-side error when the file we download is a binary file. We can use this to:- Avoid downloading the file when it's a binary
- Know when we do not want to render a preview
- Add all support match types to
getFirstResultId()
to properly select the right match to preview automatically (previously this would either be the first content match if one content match was in the search result list or nothing).
Test plan
#36280 (closed) The first search result is not always automatically previewed
https://user-images.githubusercontent.com/458591/171157097-3abbc5a6-3c03-40e7-ae44-6d3f370b7e2a.mov
#36166 (closed) Java throws an error for binary files
#36144 (closed) Recalculate offset for Windows linebreaks
#36231 (closed) Previewing files with special character encodings don't work
App preview:
Check out the client app preview documentation to learn more.