| Crates.io | iced-code-editor |
| lib.rs | iced-code-editor |
| version | 0.3.3 |
| created_at | 2025-12-19 17:21:18.53747+00 |
| updated_at | 2026-01-22 12:55:07.052272+00 |
| description | A custom code editor widget for the Iced GUI framework with syntax highlighting, line numbers, and scrolling support. |
| homepage | https://github.com/LuDog71FR/iced-code-editor |
| repository | https://github.com/LuDog71FR/iced-code-editor |
| max_upload_size | |
| id | 1995158 |
| size | 426,238 |
This crate provides a fully-featured code editor widget with syntax highlighting, line numbers, text selection, and comprehensive keyboard navigation for the Iced GUI framework.
Screenshot of the demo application:

Add this to your Cargo.toml:
[dependencies]
iced = "0.14"
iced-code-editor = "0.3"
Here's a minimal example to integrate the code editor into your Iced application:
use iced::widget::container;
use iced::{Element, Task};
use iced_code_editor::{CodeEditor, Message as EditorMessage};
struct MyApp {
editor: CodeEditor,
}
#[derive(Debug, Clone)]
enum Message {
EditorEvent(EditorMessage),
}
impl Default for MyApp {
fn default() -> Self {
let code = r#"fn main() {
println!("Hello, world!");
}
"#;
Self { editor: CodeEditor::new(code, "rust") }
}
}
impl MyApp {
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::EditorEvent(event) => {
self.editor.update(&event).map(Message::EditorEvent)
}
}
}
fn view(&self) -> Element<'_, Message> {
container(self.editor.view().map(Message::EditorEvent))
.padding(20)
.into()
}
}
fn main() -> iced::Result {
iced::run(MyApp::update, MyApp::view)
}
The editor supports a comprehensive set of keyboard shortcuts:
| Shortcut | Action |
|---|---|
| Arrow Keys (Up, Down, Left, Right) | Move cursor |
| Shift + Arrows | Move cursor with selection |
| Home / End | Jump to start/end of line |
| Shift + Home / Shift + End | Select to start/end of line |
| Ctrl + Home / Ctrl + End | Jump to start/end of document |
| Page Up / Page Down | Scroll one page up/down |
| Shortcut | Action |
|---|---|
| Backspace | Delete character before cursor (or delete selection if text is selected) |
| Delete | Delete character after cursor (or delete selection if text is selected) |
| Shift + Delete | Delete selected text (same as Delete when selection exists) |
| Enter | Insert new line |
| Shortcut | Action |
|---|---|
| Ctrl + C or Ctrl + Insert | Copy selected text |
| Ctrl + V or Shift + Insert | Paste from clipboard |
| Shortcut | Action |
|---|---|
| Ctrl + Z | Undo last operation |
| Ctrl + Y | Redo last undone operation |
The editor features smart command grouping - consecutive typing is grouped into single undo operations, while navigation or deletion actions create separate undo points.
| Shortcut | Action |
|---|---|
| Ctrl + F | Open search dialog |
| Ctrl + H | Open search and replace dialog |
The editor uses TokyoNightStorm as the default theme. It automatically adapts to any Iced theme. All 23+ built-in Iced themes are supported:
use iced_code_editor::theme;
// Apply any built-in Iced theme
editor.set_theme(theme::from_iced_theme(&iced::Theme::TokyoNightStorm));
editor.set_theme(theme::from_iced_theme(&iced::Theme::Dracula));
editor.set_theme(theme::from_iced_theme(&iced::Theme::Nord));
editor.set_theme(theme::from_iced_theme(&iced::Theme::CatppuccinMocha));
editor.set_theme(theme::from_iced_theme(&iced::Theme::GruvboxDark));
// Or use any theme from Theme::ALL
for theme in iced::Theme::ALL {
editor.set_theme(theme::from_iced_theme(theme));
}
// Get current content
let content = editor.content();
// Check if content has been modified
if editor.is_modified() {
println!("Editor has unsaved changes");
}
// Mark content as saved (e.g., after saving to file)
editor.mark_saved();
The search/replace functionality is enabled by default. It can be toggled on or off. When disabled, search shortcuts (Ctrl+F, Ctrl+H, F3) are ignored and the search dialog is hidden:
// Disable search/replace functionality
editor.set_search_replace_enabled(false);
// Or use builder pattern during initialization
let editor = CodeEditor::new("code", "rs")
.with_search_replace_enabled(false);
// Check current state
if editor.search_replace_enabled() {
println!("Search and replace is available");
}
This is useful for read-only editors or when you want to provide your own search interface.
Line wrapping is enabled by default at viewport width. Long lines can be wrapped automatically at the viewport width or at a fixed column:
// Enable line wrapping at viewport width
editor.set_wrap_enabled(true);
// Wrap at a fixed column (e.g., 80 characters)
let editor = CodeEditor::new("code", "rs")
.with_wrap_enabled(true)
.with_wrap_column(Some(80));
// Disable wrapping
editor.set_wrap_enabled(false);
// Check current state
if editor.wrap_enabled() {
println!("Line wrapping is active");
}
When enabled, wrapped lines show a continuation indicator (↪) in the line number gutter.
Line numbers are displayed by default. They can be hidden to maximize space for code:
// Hide line numbers
editor.set_line_numbers_enabled(false);
// Or use builder pattern during initialization
let editor = CodeEditor::new("code", "rs")
.with_line_numbers_enabled(false);
// Show line numbers (default behavior)
editor.set_line_numbers_enabled(true);
// Check current state
if editor.line_numbers_enabled() {
println!("Line numbers are visible");
}
When disabled, the gutter is completely removed (0px width), providing more horizontal space for code display.
The default font of the editor is iced::Font::MONOSPACE. It can be changed with one of the default iced font or by loading a specific font:
let font = iced::font::Family::SansSerif;
self.editor_left.set_font(font);
The editor natively supports all built-in Iced themes with automatic color adaptation.
Each theme automatically provides:
The editor intelligently adapts colors from the Iced theme palette for optimal code readability.

The editor supports syntax highlighting for numerous languages via the syntect crate:
"rs" or "rust")"py" or "python")"js", "javascript", "ts", "typescript")"lua")"c", "cpp", "c++")"java")"go")"html", "css")"md", "markdown")For a complete list, refer to the syntect documentation.
A full-featured demo application is included in the demo-app directory, showcasing:
Run it with:
cargo run --package demo-app --release
Contributions are welcome! Please feel free to submit a Pull Request.
Check docs\DEV.md for more details.
This project is licensed under the MIT License - see the LICENSE file for details.