Skip to main content

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 inline_line;
12pub(crate) use inline_line::{InlineFragment, InputLine};
13mod fold_map;
14mod folding;
15mod text_wrapper;
16mod wrap_map;
17
18// Re-export public API
19pub use self::display_map::{DisplayMap, WrappingIndent};
20pub(crate) use self::text_wrapper::LineLayout;
21
22// Re-export FoldRange and extract_fold_ranges
23pub use folding::FoldRange;
24
25/// Position in the buffer (logical text).
26///
27/// - `line`: 0-based logical line number (split by `\n`)
28/// - `col`: 0-based column offset (byte offset)
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30pub struct BufferPoint {
31    pub line: usize,
32    pub col: usize,
33}
34
35impl BufferPoint {
36    pub fn new(line: usize, col: usize) -> Self {
37        Self { line, col }
38    }
39}
40
41/// Position after soft-wrapping but before folding (internal).
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
43pub(super) struct WrapPoint {
44    pub row: usize,
45    pub col: usize,
46}
47
48impl WrapPoint {
49    pub(super) fn new(row: usize, col: usize) -> Self {
50        Self { row, col }
51    }
52}
53
54/// Final display position (after soft-wrapping and folding).
55///
56/// - `row`: 0-based display row (final visible row)
57/// - `col`: 0-based display column
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
59pub struct DisplayPoint {
60    pub row: usize,
61    pub col: usize,
62}
63
64impl DisplayPoint {
65    pub fn new(row: usize, col: usize) -> Self {
66        Self { row, col }
67    }
68}