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