gpui_base/input/editor/display_map/mod.rs
1/// Display mapping system for Editor/Input.
2///
3/// This module implements a layered display mapping architecture:
4/// - **WrapMap**: Handles soft-wrapping (buffer → wrap rows)
5/// - **FoldMap**: Handles folding (wrap rows → display rows)
6/// - **DisplayMap**: Public facade for Editor/Input
7///
8/// The goal is to provide a clean, unified API where Editor only needs to know
9/// about `BufferPoint ↔ DisplayPoint` mapping, without worrying about internal wrap/fold complexity.
10mod display_map;
11mod fold_map;
12mod folding;
13mod text_wrapper;
14mod wrap_map;
15
16// Re-export public API
17pub use self::display_map::{DisplayMap, WrappingIndent};
18pub(crate) use self::text_wrapper::LineLayout;
19
20// Re-export FoldRange and extract_fold_ranges
21pub use folding::FoldRange;
22
23/// Position in the buffer (logical text).
24///
25/// - `line`: 0-based logical line number (split by `\n`)
26/// - `col`: 0-based column offset (byte offset)
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
28pub struct BufferPoint {
29 pub line: usize,
30 pub col: usize,
31}
32
33impl BufferPoint {
34 pub fn new(line: usize, col: usize) -> Self {
35 Self { line, col }
36 }
37}
38
39/// Position after soft-wrapping but before folding (internal).
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
41pub(super) struct WrapPoint {
42 pub row: usize,
43 pub col: usize,
44}
45
46impl WrapPoint {
47 pub(super) fn new(row: usize, col: usize) -> Self {
48 Self { row, col }
49 }
50}
51
52/// Final display position (after soft-wrapping and folding).
53///
54/// - `row`: 0-based display row (final visible row)
55/// - `col`: 0-based display column
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
57pub struct DisplayPoint {
58 pub row: usize,
59 pub col: usize,
60}
61
62impl DisplayPoint {
63 pub fn new(row: usize, col: usize) -> Self {
64 Self { row, col }
65 }
66}