encoding: Add "reopen with encoding"#46553
Conversation
24e737e to
e58d9a1
Compare
|
Nice, thank you! I am not sure about the API, We also set the encoding before the loaded buffer was loaded with that encoding. I guess this makes the UI update faster, but it introduces a transient state where the encoding doesn't match what was used to load the content. I'm not sure that will ever actually cause problems, but it'd be nice to avoid it. |
e58d9a1 to
7bcfae8
Compare
|
Thank you for the feedback! I agree that passing the encoding explicitly is much cleaner than managing a state flag. I have addressed your suggestions in the latest commit:
I have also re-verified the changes against the test plan outlined in the PR description to ensure everything works as expected. |
|
Should I close this PR? |
|
Sorry for the slow response here, and thank you again for this. I've pushed up support for undo/redo because without it the feature felt a bit broken. I also think we need to figure out the story for remote development (at least the devcontainer/ssh variety) to really call this feature done. Not sure if that's of interest to you, but shouldn't be too hard (famous last words) – we'll need a way to pass the buffer encoding from the remote down, and then a way to request a reload. You said in the description that in response to the file on disk changing, zed reloads the file with the new encoding; I didn't see this happening, it kept the existing encoding (though TBH this felt fine as a user – and I can of course use reopen with encoding if I need). |
|
Thanks again for the review and merging this! I completely agree that the remote development story is the missing piece to make this feature truly complete. The path forward seems clear (piping the encoding info through RPC), but I realize this is a step up in complexity compared to the local version and will require more rigorous verification. I'll give it a shot!That said, since it might take me some time to get the wiring right, if a better implementation comes along from someone else in the meantime (perhaps while I'm stuck in a rabbit hole!), please don't hesitate to move forward with that one lol. |
|
Thank you! If you have acres to Claude code it can probably make you an end to end test with the other remote integration tests (or you can copy that pattern). The other tip is to ssh to localhost to avoid too much time wasted, but iteration cycles can be slow. |
|
Wow, thank you so much for the incredibly generous offer to pair! I am honored. To be honest, while my async English I/O works fine, my real-time audio processing has high latency and tends to drop packets. So a live pairing session might be a bit challenging for me right now! I'll start by trying your suggestions ("ssh to localhost" / Claude Code) to navigate the "rabbit hole" at my own pace. I'll reach out on GitHub if I hit a wall. Thanks again for your support! |
Key changes: - Reopen with encoding (zed-industries#46553) - new encoding selector with reopen support - Relative line jumps in go-to-line (zed-industries#46932) - Terminal tab renaming (zed-industries#45800) - Project search spinner while search underway (zed-industries#47620) - Git: retain "since" diffs, avoid unwrap in panel, don't rebuild diff on repo change - Extensions: fix duplicate button IDs preventing uninstall (zed-industries#47745) - SendKeystrokes: don't use layout key equivalents (zed-industries#47061) - Collab tests extracted to integration crate (deleted in our fork) - Various CI, docs, and agent improvements Conflict resolutions: - Kept native_button style, adopted extension_button_id() for unique IDs - Added encoding_selector::init alongside browser::init - Fixed _cx → cx rename for new encoding selector render code Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add "Reopen with Encoding" feature (Local/Single user)
Summary
This PR adds a "Reopen with Encoding" feature to allow users to manually specify an encoding and reload the active buffer.
This feature allows users to explicitly specify the encoding and reload the file to resolve garbled text caused by incorrect detection.
Changes
encoding_selectorforce_encoding_on_next_reloadflag to the Buffer struct.reloadmethod to check this flag and apply the following logic:Limitations & Scope
To ensure stability and keep the PR focused, the following scenarios are intentionally out of scope:
Remote Connection (SSH/WSL)Collaboration SessionFiles that worktree detects as "binary" (e.g., UTF-16 files without BOM containing non-ASCII characters) are not opened in the editor, so this feature cannot be triggered.
Future Work: Fixing this would require modifying crates/worktree heuristics or exposing a "Force Open as Text" action for InvalidItemView to trigger. Given the scope and impact, this is deferred to a future PR.
Test Plan
I verified the feature and BOM handling using the following scenarios:
Preparation
Used the following test files:
Used an external editor (VS Code or Notepad) for verification.
Case 1: English-only file behavior
Case 2: Fixing Mojibake
※Confirm it opens with mojibake
Case 3: Unicode file with BOM behavior
Shift JIS.Case 4: Non-Unicode file with BOM behavior
Case 5: Revert to Unicode
Case 6: External BOM removal (State sync)
Case 7: External BOM addition
Case 8: External Encoding Change (Auto-detect sync)
test_utf8.txt).buffer.encodingis correctly updated during reload).Release Notes: