1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// SPDX-FileCopyrightText: Copyright (c) 2026 Mike Li/Mikewolfli/Wei Li(mikewolfli@163.com)
// SPDX-License-Identifier: MIT
//! CodeEditor widget — a self-contained, Zed-class source code editor model.
//!
//! # Scope boundary
//!
//! This widget deliberately implements the *whole editor surface that a single
//! widget can own*: text storage on a line index, a cursor with anchor/selection
//! (including multiple carets), an undo/redo history, viewport scrolling (line
//! and column axes), soft line wrapping, folding, multi-buffer tabs, bracket
//! matching, indent guides, in-editor find/replace with a visible find bar,
//! autocomplete, context menus, auto-pairing, line commands, configurable
//! tabs/spaces, whitespace/ruler overlays, and the input plumbing (keyboard,
//! IME, mouse, touch, wheel) for all of it.
//!
//! Everything that a real editor product would load as a *plugin crate* is
//! intentionally **not** in here, because it cannot be owned by one widget:
//!
//! | Concern | Where it belongs |
//! |---------|------------------|
//! | Tree-sitter grammar / real incremental parsing | `plugin: syntax` crate |
//! | Syntax highlight themes & semantic tokens | `plugin: theme` crate |
//! | LSP client (completion, hover, diagnostics, goto) | `plugin: lsp` crate |
//! | DAP / terminal / language REPLs | `plugin: debug` crate |
//! | Multiplayer (CRDT), collaboration | `plugin: collab` crate |
//! | File-system, workspace, VCS integration | host application |
//!
//! The widget therefore exposes *extension hooks* rather than pretending to be
//! those systems: [`SyntaxHighlighter`] (pluggable tokenizer, defaulting to a
//! keyword/string/comment/`fn`-name lexer), [`CompletionSource`] (pluggable
//! completion-provider, defaulting to document identifiers), and
//! [`DiagnosticMarker`] (host/LSP-pushed inline diagnostics).
//!
//! # Host integration: the clipboard
//!
//! The context menu's `paste` row reflects whether the clipboard holds text, and
//! that fact is **cached**, not read when the menu opens
//! ([`CodeEditor::clipboard_has_text`]). The platform clipboard is a machine-global
//! resource whose handle is exclusive, so a read can block or fail and would let a
//! transient failure disable a row for a reason the user cannot see. A host should
//! call [`CodeEditor::set_clipboard_has_text`] from the platform's clipboard-change
//! notification (or [`CodeEditor::invalidate_clipboard_has_text`] on focus regain);
//! with no host wiring the editor probes once and caches the answer.
//!
//! # Module layout
//!
//! The implementation is split into focused submodules; this file only declares
//! them and re-exports their public interface (principle.md #8). The submodules
//! are private, so their names are written as code spans rather than intra-doc
//! links (a link to a private item is a rustdoc error).
//!
//! | Module | Responsibility |
//! |--------|----------------|
//! | `types` | Positions, cursor, markers, tokens, palette, config, find/completion/menu state |
//! | `syntax` | Built-in lexer, [`LanguageId`], [`SyntaxHighlighter`] plugin seam |
//! | `buffer` | Line-indexed document model, tabs, folds, splice primitive |
//! | `coords` | Document ↔ screen coordinate map (`B3`/`B4`) |
//! | `grid` | Char index ↔ grid column ↔ byte offset (wide chars, tabs) |
//! | `multicursor` | Multiple carets: add/merge, occurrence selection, edit projection |
//! | `pairs` | Auto-pairing, bracket/quote skip-over and smart backspace |
//! | `editor` | The [`CodeEditor`] widget: state, construction, shared helpers; commands in `editor/*` |
//! | `input` | Keyboard/IME/pointer/wheel translation layer |
//! | `render` | The `Draw` entry point, metrics and hit-testing; paint helpers in `render/*` |
//! | `tests` | Behavioural test-suite |
//!
//! # Rust design notes (principle.md #28..#34)
//!
//! * No trait objects on the hot path: highlighting is a plain `enum` dispatch
//! plus a tiny [`SyntaxHighlighter`] trait for the pluggable case.
//! * All state is owned; no manual allocation, no `unsafe`.
//! * Configuration is a Builder-style type ([`CodeEditorConfig`]) rather than a
//! varargs setter cluster.
//! * Invalid configuration is rejected through `Result`, never silently ignored.
//!
//! # Device profiles
//!
//! Touch targets (find-bar buttons, completion rows, context-menu rows,
//! scrollbar hit area) are all >= 28 logical pixels so tablet/mobile remain
//! usable; triple-tap selects a line for touch devices while triple-click keeps
//! the desktop behaviour.
pub use CodeEditor;
pub use MultiCursor;
pub use ;
pub use ;
pub use ;
/// The `markers` property's record schema, re-exported so the capability table can name it
/// (the `types` module itself stays private).
pub use DIAGNOSTIC_MARKER_SCHEMA;