zed/docs
Ichimura Tomoo 6b90aaa1bd
status_bar: Add encoding indicator (#45476)
## Context / Related PRs This PR is the third part of the encoding
support improvements, following:
- #44819: Introduced initial legacy encoding support (Shift-JIS, etc.).
- #45243: Fixed UTF-16 saving behavior and improved binary detection.

## Summary
This PR implements a status bar item that displays the character
encoding of the active buffer (e.g., `UTF-8`, `Shift_JIS`). It provides
visibility into the file's encoding and indicates the presence of a Byte
Order Mark (BOM).

## Features
- **Encoding Indicator**: Displays the encoding name in the status bar.
- **BOM Support**: Appends `(BOM)` to the encoding name if a BOM is
detected (e.g., `UTF-8 (BOM)`).
- **Configuration**: The active_encoding_button setting in status_bar
accepts "enabled", "disabled", or "non_utf8". The default is "non_utf8",
which displays the indicator for all encodings except standard UTF-8
(without BOM).
- **Settings UI**: Provides a dropdown menu in the Settings UI to
control this behavior.
- **Documentation**: Updated `configuring-zed.md` and
`visual-customization.md`.

## Implementation Details
- Created `ActiveBufferEncoding` component in
`crates/encoding_selector`.
- The click handler for the button is currently a **no-op**.
Implementing the functionality to reopen files with a specific encoding
has potential implications for real-time collaboration (e.g., syncing
buffer interpretation across peers). Therefore, this PR focuses strictly
on the visualization and configuration aspects to keep the scope simple
and focused.
- Updated schema and default settings to include
`active_encoding_button`.

## Screenshots

<img width="487" height="104" alt="image"
src="https://github.com/user-attachments/assets/041f096d-ac69-4bad-ac53-20cdcb41f733"
/>
<img width="454" height="99" alt="image"
src="https://github.com/user-attachments/assets/ed76daa2-2733-484f-bb1f-4688357c035a"
/>


## Configuration
To hide the button, add the following to `settings.json`:
```json
"status_bar": {
  "active_encoding_button": "disabled"
}
```

- **enabled**: Always show the encoding.
- **disabled**: Never show the encoding.
- **non_utf8**: Shows for non-UTF-8 encodings and UTF-8 with BOM. Only
hides for standard UTF-8 (Default).

<img width="1347" height="415" alt="image"
src="https://github.com/user-attachments/assets/7f4f4938-3320-4d21-852c-53ee886d9a44"
/>

## Heuristic Limitations:
The underlying detection logic (implemented in #44819 and #45243)
prioritizes UTF-8 opening performance and does not guarantee perfect
detection for all encodings. We consider this margin of error
acceptable, similar to the behavior seen in VS Code. A future "Reopen
with Encoding" feature would serve as the primary fallback for any
misdetections.

Release Notes:

- Added a status bar item to display the active file's character encoding (e.g. `UTF-16`). This shows for non-utf8 files by default and can be configured with `{"status_bar":{"active_encoding_button":"disabled|enabled|non_utf8"}}`
2026-01-07 07:24:46 +00:00
..
src status_bar: Add encoding indicator (#45476) 2026-01-07 07:24:46 +00:00
theme docs: Fix bug on table of contents (#43840) 2025-11-30 16:11:20 +00:00
.gitignore Setup docs deployments with mdBook (#11369) 2024-05-03 15:52:15 -04:00
.prettierignore docs: Check formatting in CI (#15355) 2024-07-27 15:47:48 -04:00
.prettierrc ci: Add check for formatting default.json (#30034) 2025-05-06 18:55:26 +00:00
.rules docs: Add migrate docs for Webstorm / Pycharm / RustRover (#45128) 2025-12-17 08:44:48 -08:00
AGENTS.md docs: Automatic Documentation Github Action using Droid (#45374) 2025-12-19 11:19:12 -06:00
book.toml Add collaboration redirects (#43471) 2025-11-25 11:28:33 -05:00
README.md Docs README.md small fixes (#43904) 2025-12-01 14:57:00 +00:00

Zed Docs

Welcome to Zed's documentation.

This is built on push to main and published automatically to https://zed.dev/docs.

To preview the docs locally you will need to install mdBook (cargo install mdbook@0.4.40) and then run:

mdbook serve docs

It's important to note the version number above. For an unknown reason, as of 2025-04-23, running 0.4.48 will cause odd URL behavior that breaks things.

Before committing, verify that the docs are formatted in the way Prettier expects with:

cd docs && pnpm dlx prettier@3.5.0 . --write && cd ..

Preprocessor

We have a custom mdBook preprocessor for interfacing with our crates (crates/docs_preprocessor).

If for some reason you need to bypass the docs preprocessor, you can comment out [preprocessor.zed_docs_preprocessor] from the book.toml.

Images and videos

To add images or videos to the docs, upload them to another location (e.g., zed.dev, GitHub's asset storage) and then link out to them from the docs.

Putting binary assets such as images in the Git repository will bloat the repository size over time.

Internal notes:

  • We have a Cloudflare router called docs-proxy that intercepts requests to zed.dev/docs and forwards them to the "docs" Cloudflare Pages project.
  • The CI uploads a new version to the Cloudflare Pages project from .github/workflows/deploy_docs.yml on every push to main.

Table of Contents

The table of contents files (theme/page-toc.js and theme/page-doc.css) were initially generated by mdbook-pagetoc.

Since all this preprocessor does is generate the static assets, we don't need to keep it around once they have been generated.

Referencing Keybindings and Actions

When referencing keybindings or actions, use the following formats:

Keybindings

{#kb scope::Action} - e.g., {#kb zed::OpenSettings}.

This will output a code element like: <code>Cmd + , | Ctrl + ,</code>. We then use a client-side plugin to show the actual keybinding based on the user's platform.

By using the action name, we can ensure that the keybinding is always up-to-date rather than hardcoding the keybinding.

Actions

{#action scope::Action} - e.g., {#action zed::OpenSettings}.

This will render a human-readable version of the action name, e.g., "zed: open settings", and will allow us to implement things like additional context on hover, etc.

Creating New Templates

Templates are functions that modify the source of the docs pages (usually with a regex match and replace). You can see how the actions and keybindings are templated in crates/docs_preprocessor/src/main.rs for reference on how to create new templates.

References

  • Template Trait: crates/docs_preprocessor/src/templates.rs
  • Example template: crates/docs_preprocessor/src/templates/keybinding.rs
  • Client-side plugins: docs/theme/plugins.js

Postprocessor

A postprocessor is implemented as a sub-command of docs_preprocessor that wraps the built-in HTML renderer and applies post-processing to the HTML files, to add support for page-specific title and meta tag description values.

An example of the syntax can be found in git.md, as well as below:

---
title: Some more detailed title for this page
description: A page-specific description
---

# Editor

The above code will be transformed into (with non-relevant tags removed):

<head>
  <title>Editor | Some more detailed title for this page</title>
  <meta name="description" contents="A page-specific description" />
</head>
<body>
  <h1>Editor</h1>
</body>

If no front matter is provided, or if one or both keys aren't provided, the title and description will be set based on the default-title and default-description keys in book.toml respectively.

Implementation details

Unfortunately, mdBook does not support post-processing like it does pre-processing, and only supports defining one description to put in the meta tag per book rather than per file. So in order to apply post-processing (necessary to modify the HTML head tags) the global book description is set to a marker value #description# and the HTML renderer is replaced with a sub-command of docs_preprocessor that wraps the built-in HTML renderer and applies post-processing to the HTML files, replacing the marker value and the <title>(.*)</title> with the contents of the front matter if there is one.

Known limitations

The front matter parsing is extremely simple, which avoids needing to take on an additional dependency, or implement full YAML parsing.

  • Double quotes and multi-line values are not supported, i.e. Keys and values must be entirely on the same line, with no double quotes around the value.

The following will not work:

---
title: Some
  Multi-line
  Title
---

neither this:

---
title: "Some title"
---
  • The front matter must be at the top of the file, with only white-space preceding it.
  • The contents of the title and description will not be HTML escaped. They should be simple ASCII text with no unicode or emoji characters.