display_map.rs

   1mod block_map;
   2mod fold_map;
   3mod inlay_map;
   4mod tab_map;
   5mod wrap_map;
   6
   7use crate::EditorStyle;
   8use crate::{
   9    link_go_to_definition::InlayHighlight, movement::TextLayoutDetails, Anchor, AnchorRangeExt,
  10    InlayId, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint,
  11};
  12pub use block_map::{BlockMap, BlockPoint};
  13use collections::{BTreeMap, HashMap, HashSet};
  14use fold_map::FoldMap;
  15use gpui::{
  16    Font, FontId, HighlightStyle, Hsla, LineLayout, Model, ModelContext, Pixels, ShapedLine,
  17    TextRun, UnderlineStyle, WrappedLine,
  18};
  19use inlay_map::InlayMap;
  20use language::{
  21    language_settings::language_settings, OffsetUtf16, Point, Subscription as BufferSubscription,
  22};
  23use lsp::DiagnosticSeverity;
  24use std::{any::TypeId, borrow::Cow, fmt::Debug, num::NonZeroU32, ops::Range, sync::Arc};
  25use sum_tree::{Bias, TreeMap};
  26use tab_map::TabMap;
  27use theme::{StatusColors, SyntaxTheme, Theme};
  28use wrap_map::WrapMap;
  29
  30pub use block_map::{
  31    BlockBufferRows as DisplayBufferRows, BlockChunks as DisplayChunks, BlockContext,
  32    BlockDisposition, BlockId, BlockProperties, BlockStyle, RenderBlock, TransformBlock,
  33};
  34
  35pub use self::fold_map::{Fold, FoldPoint};
  36pub use self::inlay_map::{Inlay, InlayOffset, InlayPoint};
  37
  38#[derive(Copy, Clone, Debug, PartialEq, Eq)]
  39pub enum FoldStatus {
  40    Folded,
  41    Foldable,
  42}
  43
  44const UNNECESSARY_CODE_FADE: f32 = 0.3;
  45
  46pub trait ToDisplayPoint {
  47    fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint;
  48}
  49
  50type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;
  51type InlayHighlights = BTreeMap<TypeId, HashMap<InlayId, (HighlightStyle, InlayHighlight)>>;
  52
  53pub struct DisplayMap {
  54    buffer: Model<MultiBuffer>,
  55    buffer_subscription: BufferSubscription,
  56    fold_map: FoldMap,
  57    inlay_map: InlayMap,
  58    tab_map: TabMap,
  59    wrap_map: Model<WrapMap>,
  60    block_map: BlockMap,
  61    text_highlights: TextHighlights,
  62    inlay_highlights: InlayHighlights,
  63    pub clip_at_line_ends: bool,
  64}
  65
  66impl DisplayMap {
  67    pub fn new(
  68        buffer: Model<MultiBuffer>,
  69        font: Font,
  70        font_size: Pixels,
  71        wrap_width: Option<Pixels>,
  72        buffer_header_height: u8,
  73        excerpt_header_height: u8,
  74        cx: &mut ModelContext<Self>,
  75    ) -> Self {
  76        let buffer_subscription = buffer.update(cx, |buffer, _| buffer.subscribe());
  77
  78        let tab_size = Self::tab_size(&buffer, cx);
  79        let (inlay_map, snapshot) = InlayMap::new(buffer.read(cx).snapshot(cx));
  80        let (fold_map, snapshot) = FoldMap::new(snapshot);
  81        let (tab_map, snapshot) = TabMap::new(snapshot, tab_size);
  82        let (wrap_map, snapshot) = WrapMap::new(snapshot, font, font_size, wrap_width, cx);
  83        let block_map = BlockMap::new(snapshot, buffer_header_height, excerpt_header_height);
  84        cx.observe(&wrap_map, |_, _, cx| cx.notify()).detach();
  85        DisplayMap {
  86            buffer,
  87            buffer_subscription,
  88            fold_map,
  89            inlay_map,
  90            tab_map,
  91            wrap_map,
  92            block_map,
  93            text_highlights: Default::default(),
  94            inlay_highlights: Default::default(),
  95            clip_at_line_ends: false,
  96        }
  97    }
  98
  99    pub fn snapshot(&mut self, cx: &mut ModelContext<Self>) -> DisplaySnapshot {
 100        let buffer_snapshot = self.buffer.read(cx).snapshot(cx);
 101        let edits = self.buffer_subscription.consume().into_inner();
 102        let (inlay_snapshot, edits) = self.inlay_map.sync(buffer_snapshot, edits);
 103        let (fold_snapshot, edits) = self.fold_map.read(inlay_snapshot.clone(), edits);
 104        let tab_size = Self::tab_size(&self.buffer, cx);
 105        let (tab_snapshot, edits) = self.tab_map.sync(fold_snapshot.clone(), edits, tab_size);
 106        let (wrap_snapshot, edits) = self
 107            .wrap_map
 108            .update(cx, |map, cx| map.sync(tab_snapshot.clone(), edits, cx));
 109        let block_snapshot = self.block_map.read(wrap_snapshot.clone(), edits);
 110
 111        DisplaySnapshot {
 112            buffer_snapshot: self.buffer.read(cx).snapshot(cx),
 113            fold_snapshot,
 114            inlay_snapshot,
 115            tab_snapshot,
 116            wrap_snapshot,
 117            block_snapshot,
 118            text_highlights: self.text_highlights.clone(),
 119            inlay_highlights: self.inlay_highlights.clone(),
 120            clip_at_line_ends: self.clip_at_line_ends,
 121        }
 122    }
 123
 124    pub fn set_state(&mut self, other: &DisplaySnapshot, cx: &mut ModelContext<Self>) {
 125        self.fold(
 126            other
 127                .folds_in_range(0..other.buffer_snapshot.len())
 128                .map(|fold| fold.range.to_offset(&other.buffer_snapshot)),
 129            cx,
 130        );
 131    }
 132
 133    pub fn fold<T: ToOffset>(
 134        &mut self,
 135        ranges: impl IntoIterator<Item = Range<T>>,
 136        cx: &mut ModelContext<Self>,
 137    ) {
 138        let snapshot = self.buffer.read(cx).snapshot(cx);
 139        let edits = self.buffer_subscription.consume().into_inner();
 140        let tab_size = Self::tab_size(&self.buffer, cx);
 141        let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
 142        let (mut fold_map, snapshot, edits) = self.fold_map.write(snapshot, edits);
 143        let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
 144        let (snapshot, edits) = self
 145            .wrap_map
 146            .update(cx, |map, cx| map.sync(snapshot, edits, cx));
 147        self.block_map.read(snapshot, edits);
 148        let (snapshot, edits) = fold_map.fold(ranges);
 149        let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
 150        let (snapshot, edits) = self
 151            .wrap_map
 152            .update(cx, |map, cx| map.sync(snapshot, edits, cx));
 153        self.block_map.read(snapshot, edits);
 154    }
 155
 156    pub fn unfold<T: ToOffset>(
 157        &mut self,
 158        ranges: impl IntoIterator<Item = Range<T>>,
 159        inclusive: bool,
 160        cx: &mut ModelContext<Self>,
 161    ) {
 162        let snapshot = self.buffer.read(cx).snapshot(cx);
 163        let edits = self.buffer_subscription.consume().into_inner();
 164        let tab_size = Self::tab_size(&self.buffer, cx);
 165        let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
 166        let (mut fold_map, snapshot, edits) = self.fold_map.write(snapshot, edits);
 167        let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
 168        let (snapshot, edits) = self
 169            .wrap_map
 170            .update(cx, |map, cx| map.sync(snapshot, edits, cx));
 171        self.block_map.read(snapshot, edits);
 172        let (snapshot, edits) = fold_map.unfold(ranges, inclusive);
 173        let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
 174        let (snapshot, edits) = self
 175            .wrap_map
 176            .update(cx, |map, cx| map.sync(snapshot, edits, cx));
 177        self.block_map.read(snapshot, edits);
 178    }
 179
 180    pub fn insert_blocks(
 181        &mut self,
 182        blocks: impl IntoIterator<Item = BlockProperties<Anchor>>,
 183        cx: &mut ModelContext<Self>,
 184    ) -> Vec<BlockId> {
 185        let snapshot = self.buffer.read(cx).snapshot(cx);
 186        let edits = self.buffer_subscription.consume().into_inner();
 187        let tab_size = Self::tab_size(&self.buffer, cx);
 188        let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
 189        let (snapshot, edits) = self.fold_map.read(snapshot, edits);
 190        let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
 191        let (snapshot, edits) = self
 192            .wrap_map
 193            .update(cx, |map, cx| map.sync(snapshot, edits, cx));
 194        let mut block_map = self.block_map.write(snapshot, edits);
 195        block_map.insert(blocks)
 196    }
 197
 198    pub fn replace_blocks(&mut self, styles: HashMap<BlockId, RenderBlock>) {
 199        self.block_map.replace(styles);
 200    }
 201
 202    pub fn remove_blocks(&mut self, ids: HashSet<BlockId>, cx: &mut ModelContext<Self>) {
 203        let snapshot = self.buffer.read(cx).snapshot(cx);
 204        let edits = self.buffer_subscription.consume().into_inner();
 205        let tab_size = Self::tab_size(&self.buffer, cx);
 206        let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
 207        let (snapshot, edits) = self.fold_map.read(snapshot, edits);
 208        let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
 209        let (snapshot, edits) = self
 210            .wrap_map
 211            .update(cx, |map, cx| map.sync(snapshot, edits, cx));
 212        let mut block_map = self.block_map.write(snapshot, edits);
 213        block_map.remove(ids);
 214    }
 215
 216    pub fn highlight_text(
 217        &mut self,
 218        type_id: TypeId,
 219        ranges: Vec<Range<Anchor>>,
 220        style: HighlightStyle,
 221    ) {
 222        self.text_highlights
 223            .insert(Some(type_id), Arc::new((style, ranges)));
 224    }
 225
 226    pub fn highlight_inlays(
 227        &mut self,
 228        type_id: TypeId,
 229        highlights: Vec<InlayHighlight>,
 230        style: HighlightStyle,
 231    ) {
 232        for highlight in highlights {
 233            self.inlay_highlights
 234                .entry(type_id)
 235                .or_default()
 236                .insert(highlight.inlay, (style, highlight));
 237        }
 238    }
 239
 240    pub fn text_highlights(&self, type_id: TypeId) -> Option<(HighlightStyle, &[Range<Anchor>])> {
 241        let highlights = self.text_highlights.get(&Some(type_id))?;
 242        Some((highlights.0, &highlights.1))
 243    }
 244    pub fn clear_highlights(&mut self, type_id: TypeId) -> bool {
 245        let mut cleared = self.text_highlights.remove(&Some(type_id)).is_some();
 246        cleared |= self.inlay_highlights.remove(&type_id).is_none();
 247        cleared
 248    }
 249
 250    pub fn set_font(&self, font: Font, font_size: Pixels, cx: &mut ModelContext<Self>) -> bool {
 251        self.wrap_map
 252            .update(cx, |map, cx| map.set_font_with_size(font, font_size, cx))
 253    }
 254
 255    pub fn set_fold_ellipses_color(&mut self, color: Hsla) -> bool {
 256        self.fold_map.set_ellipses_color(color)
 257    }
 258
 259    pub fn set_wrap_width(&self, width: Option<Pixels>, cx: &mut ModelContext<Self>) -> bool {
 260        self.wrap_map
 261            .update(cx, |map, cx| map.set_wrap_width(width, cx))
 262    }
 263
 264    pub fn current_inlays(&self) -> impl Iterator<Item = &Inlay> {
 265        self.inlay_map.current_inlays()
 266    }
 267
 268    pub fn splice_inlays(
 269        &mut self,
 270        to_remove: Vec<InlayId>,
 271        to_insert: Vec<Inlay>,
 272        cx: &mut ModelContext<Self>,
 273    ) {
 274        if to_remove.is_empty() && to_insert.is_empty() {
 275            return;
 276        }
 277        let buffer_snapshot = self.buffer.read(cx).snapshot(cx);
 278        let edits = self.buffer_subscription.consume().into_inner();
 279        let (snapshot, edits) = self.inlay_map.sync(buffer_snapshot, edits);
 280        let (snapshot, edits) = self.fold_map.read(snapshot, edits);
 281        let tab_size = Self::tab_size(&self.buffer, cx);
 282        let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
 283        let (snapshot, edits) = self
 284            .wrap_map
 285            .update(cx, |map, cx| map.sync(snapshot, edits, cx));
 286        self.block_map.read(snapshot, edits);
 287
 288        let (snapshot, edits) = self.inlay_map.splice(to_remove, to_insert);
 289        let (snapshot, edits) = self.fold_map.read(snapshot, edits);
 290        let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
 291        let (snapshot, edits) = self
 292            .wrap_map
 293            .update(cx, |map, cx| map.sync(snapshot, edits, cx));
 294        self.block_map.read(snapshot, edits);
 295    }
 296
 297    fn tab_size(buffer: &Model<MultiBuffer>, cx: &mut ModelContext<Self>) -> NonZeroU32 {
 298        let language = buffer
 299            .read(cx)
 300            .as_singleton()
 301            .and_then(|buffer| buffer.read(cx).language());
 302        language_settings(language.as_deref(), None, cx).tab_size
 303    }
 304
 305    #[cfg(test)]
 306    pub fn is_rewrapping(&self, cx: &gpui::AppContext) -> bool {
 307        self.wrap_map.read(cx).is_rewrapping()
 308    }
 309}
 310
 311#[derive(Debug, Default)]
 312pub struct Highlights<'a> {
 313    pub text_highlights: Option<&'a TextHighlights>,
 314    pub inlay_highlights: Option<&'a InlayHighlights>,
 315    pub inlay_highlight_style: Option<HighlightStyle>,
 316    pub suggestion_highlight_style: Option<HighlightStyle>,
 317}
 318
 319pub struct HighlightedChunk<'a> {
 320    pub chunk: &'a str,
 321    pub style: Option<HighlightStyle>,
 322    pub is_tab: bool,
 323}
 324
 325pub struct DisplaySnapshot {
 326    pub buffer_snapshot: MultiBufferSnapshot,
 327    pub fold_snapshot: fold_map::FoldSnapshot,
 328    inlay_snapshot: inlay_map::InlaySnapshot,
 329    tab_snapshot: tab_map::TabSnapshot,
 330    wrap_snapshot: wrap_map::WrapSnapshot,
 331    block_snapshot: block_map::BlockSnapshot,
 332    text_highlights: TextHighlights,
 333    inlay_highlights: InlayHighlights,
 334    clip_at_line_ends: bool,
 335}
 336
 337impl DisplaySnapshot {
 338    #[cfg(test)]
 339    pub fn fold_count(&self) -> usize {
 340        self.fold_snapshot.fold_count()
 341    }
 342
 343    pub fn is_empty(&self) -> bool {
 344        self.buffer_snapshot.len() == 0
 345    }
 346
 347    pub fn buffer_rows(&self, start_row: u32) -> DisplayBufferRows {
 348        self.block_snapshot.buffer_rows(start_row)
 349    }
 350
 351    pub fn max_buffer_row(&self) -> u32 {
 352        self.buffer_snapshot.max_buffer_row()
 353    }
 354
 355    pub fn prev_line_boundary(&self, mut point: Point) -> (Point, DisplayPoint) {
 356        loop {
 357            let mut inlay_point = self.inlay_snapshot.to_inlay_point(point);
 358            let mut fold_point = self.fold_snapshot.to_fold_point(inlay_point, Bias::Left);
 359            fold_point.0.column = 0;
 360            inlay_point = fold_point.to_inlay_point(&self.fold_snapshot);
 361            point = self.inlay_snapshot.to_buffer_point(inlay_point);
 362
 363            let mut display_point = self.point_to_display_point(point, Bias::Left);
 364            *display_point.column_mut() = 0;
 365            let next_point = self.display_point_to_point(display_point, Bias::Left);
 366            if next_point == point {
 367                return (point, display_point);
 368            }
 369            point = next_point;
 370        }
 371    }
 372
 373    pub fn next_line_boundary(&self, mut point: Point) -> (Point, DisplayPoint) {
 374        loop {
 375            let mut inlay_point = self.inlay_snapshot.to_inlay_point(point);
 376            let mut fold_point = self.fold_snapshot.to_fold_point(inlay_point, Bias::Right);
 377            fold_point.0.column = self.fold_snapshot.line_len(fold_point.row());
 378            inlay_point = fold_point.to_inlay_point(&self.fold_snapshot);
 379            point = self.inlay_snapshot.to_buffer_point(inlay_point);
 380
 381            let mut display_point = self.point_to_display_point(point, Bias::Right);
 382            *display_point.column_mut() = self.line_len(display_point.row());
 383            let next_point = self.display_point_to_point(display_point, Bias::Right);
 384            if next_point == point {
 385                return (point, display_point);
 386            }
 387            point = next_point;
 388        }
 389    }
 390
 391    // used by line_mode selections and tries to match vim behaviour
 392    pub fn expand_to_line(&self, range: Range<Point>) -> Range<Point> {
 393        let new_start = if range.start.row == 0 {
 394            Point::new(0, 0)
 395        } else if range.start.row == self.max_buffer_row()
 396            || (range.end.column > 0 && range.end.row == self.max_buffer_row())
 397        {
 398            Point::new(range.start.row - 1, self.line_len(range.start.row - 1))
 399        } else {
 400            self.prev_line_boundary(range.start).0
 401        };
 402
 403        let new_end = if range.end.column == 0 {
 404            range.end
 405        } else if range.end.row < self.max_buffer_row() {
 406            self.buffer_snapshot
 407                .clip_point(Point::new(range.end.row + 1, 0), Bias::Left)
 408        } else {
 409            self.buffer_snapshot.max_point()
 410        };
 411
 412        new_start..new_end
 413    }
 414
 415    fn point_to_display_point(&self, point: Point, bias: Bias) -> DisplayPoint {
 416        let inlay_point = self.inlay_snapshot.to_inlay_point(point);
 417        let fold_point = self.fold_snapshot.to_fold_point(inlay_point, bias);
 418        let tab_point = self.tab_snapshot.to_tab_point(fold_point);
 419        let wrap_point = self.wrap_snapshot.tab_point_to_wrap_point(tab_point);
 420        let block_point = self.block_snapshot.to_block_point(wrap_point);
 421        DisplayPoint(block_point)
 422    }
 423
 424    fn display_point_to_point(&self, point: DisplayPoint, bias: Bias) -> Point {
 425        self.inlay_snapshot
 426            .to_buffer_point(self.display_point_to_inlay_point(point, bias))
 427    }
 428
 429    pub fn display_point_to_inlay_offset(&self, point: DisplayPoint, bias: Bias) -> InlayOffset {
 430        self.inlay_snapshot
 431            .to_offset(self.display_point_to_inlay_point(point, bias))
 432    }
 433
 434    pub fn anchor_to_inlay_offset(&self, anchor: Anchor) -> InlayOffset {
 435        self.inlay_snapshot
 436            .to_inlay_offset(anchor.to_offset(&self.buffer_snapshot))
 437    }
 438
 439    fn display_point_to_inlay_point(&self, point: DisplayPoint, bias: Bias) -> InlayPoint {
 440        let block_point = point.0;
 441        let wrap_point = self.block_snapshot.to_wrap_point(block_point);
 442        let tab_point = self.wrap_snapshot.to_tab_point(wrap_point);
 443        let fold_point = self.tab_snapshot.to_fold_point(tab_point, bias).0;
 444        fold_point.to_inlay_point(&self.fold_snapshot)
 445    }
 446
 447    pub fn display_point_to_fold_point(&self, point: DisplayPoint, bias: Bias) -> FoldPoint {
 448        let block_point = point.0;
 449        let wrap_point = self.block_snapshot.to_wrap_point(block_point);
 450        let tab_point = self.wrap_snapshot.to_tab_point(wrap_point);
 451        self.tab_snapshot.to_fold_point(tab_point, bias).0
 452    }
 453
 454    pub fn fold_point_to_display_point(&self, fold_point: FoldPoint) -> DisplayPoint {
 455        let tab_point = self.tab_snapshot.to_tab_point(fold_point);
 456        let wrap_point = self.wrap_snapshot.tab_point_to_wrap_point(tab_point);
 457        let block_point = self.block_snapshot.to_block_point(wrap_point);
 458        DisplayPoint(block_point)
 459    }
 460
 461    pub fn max_point(&self) -> DisplayPoint {
 462        DisplayPoint(self.block_snapshot.max_point())
 463    }
 464
 465    /// Returns text chunks starting at the given display row until the end of the file
 466    pub fn text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> {
 467        self.block_snapshot
 468            .chunks(
 469                display_row..self.max_point().row() + 1,
 470                false,
 471                Highlights::default(),
 472            )
 473            .map(|h| h.text)
 474    }
 475
 476    /// Returns text chunks starting at the end of the given display row in reverse until the start of the file
 477    pub fn reverse_text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> {
 478        (0..=display_row).into_iter().rev().flat_map(|row| {
 479            self.block_snapshot
 480                .chunks(row..row + 1, false, Highlights::default())
 481                .map(|h| h.text)
 482                .collect::<Vec<_>>()
 483                .into_iter()
 484                .rev()
 485        })
 486    }
 487
 488    pub fn chunks<'a>(
 489        &'a self,
 490        display_rows: Range<u32>,
 491        language_aware: bool,
 492        inlay_highlight_style: Option<HighlightStyle>,
 493        suggestion_highlight_style: Option<HighlightStyle>,
 494    ) -> DisplayChunks<'a> {
 495        self.block_snapshot.chunks(
 496            display_rows,
 497            language_aware,
 498            Highlights {
 499                text_highlights: Some(&self.text_highlights),
 500                inlay_highlights: Some(&self.inlay_highlights),
 501                inlay_highlight_style,
 502                suggestion_highlight_style,
 503            },
 504        )
 505    }
 506
 507    pub fn highlighted_chunks<'a>(
 508        &'a self,
 509        display_rows: Range<u32>,
 510        language_aware: bool,
 511        editor_style: &'a EditorStyle,
 512    ) -> impl Iterator<Item = HighlightedChunk<'a>> {
 513        self.chunks(
 514            display_rows,
 515            language_aware,
 516            Some(editor_style.inlays_style),
 517            Some(editor_style.suggestions_style),
 518        )
 519        .map(|chunk| {
 520            let mut highlight_style = chunk
 521                .syntax_highlight_id
 522                .and_then(|id| id.style(&editor_style.syntax));
 523
 524            if let Some(chunk_highlight) = chunk.highlight_style {
 525                if let Some(highlight_style) = highlight_style.as_mut() {
 526                    highlight_style.highlight(chunk_highlight);
 527                } else {
 528                    highlight_style = Some(chunk_highlight);
 529                }
 530            }
 531
 532            let mut diagnostic_highlight = HighlightStyle::default();
 533
 534            if chunk.is_unnecessary {
 535                diagnostic_highlight.fade_out = Some(UNNECESSARY_CODE_FADE);
 536            }
 537
 538            if let Some(severity) = chunk.diagnostic_severity {
 539                // Omit underlines for HINT/INFO diagnostics on 'unnecessary' code.
 540                if severity <= DiagnosticSeverity::WARNING || !chunk.is_unnecessary {
 541                    let diagnostic_color =
 542                        super::diagnostic_style(severity, true, &editor_style.diagnostic_style);
 543                    diagnostic_highlight.underline = Some(UnderlineStyle {
 544                        color: Some(diagnostic_color),
 545                        thickness: 1.0.into(),
 546                        wavy: true,
 547                    });
 548                }
 549            }
 550
 551            if let Some(highlight_style) = highlight_style.as_mut() {
 552                highlight_style.highlight(diagnostic_highlight);
 553            } else {
 554                highlight_style = Some(diagnostic_highlight);
 555            }
 556
 557            HighlightedChunk {
 558                chunk: chunk.text,
 559                style: highlight_style,
 560                is_tab: chunk.is_tab,
 561            }
 562        })
 563    }
 564
 565    pub fn layout_row(
 566        &self,
 567        display_row: u32,
 568        TextLayoutDetails {
 569            text_system,
 570            editor_style,
 571            rem_size,
 572        }: &TextLayoutDetails,
 573    ) -> Arc<LineLayout> {
 574        let mut runs = Vec::new();
 575        let mut line = String::new();
 576
 577        let range = display_row..display_row + 1;
 578        for chunk in self.highlighted_chunks(range, false, &editor_style) {
 579            line.push_str(chunk.chunk);
 580
 581            let text_style = if let Some(style) = chunk.style {
 582                Cow::Owned(editor_style.text.clone().highlight(style))
 583            } else {
 584                Cow::Borrowed(&editor_style.text)
 585            };
 586
 587            runs.push(text_style.to_run(chunk.chunk.len()))
 588        }
 589
 590        if line.ends_with('\n') {
 591            line.pop();
 592            if let Some(last_run) = runs.last_mut() {
 593                last_run.len -= 1;
 594                if last_run.len == 0 {
 595                    runs.pop();
 596                }
 597            }
 598        }
 599
 600        let font_size = editor_style.text.font_size.to_pixels(*rem_size);
 601        text_system
 602            .layout_line(&line, font_size, &runs)
 603            .expect("we expect the font to be loaded because it's rendered by the editor")
 604    }
 605
 606    pub fn x_for_display_point(
 607        &self,
 608        display_point: DisplayPoint,
 609        text_layout_details: &TextLayoutDetails,
 610    ) -> Pixels {
 611        let line = self.layout_row(display_point.row(), text_layout_details);
 612        line.x_for_index(display_point.column() as usize)
 613    }
 614
 615    pub fn display_column_for_x(
 616        &self,
 617        display_row: u32,
 618        x: Pixels,
 619        details: &TextLayoutDetails,
 620    ) -> u32 {
 621        let layout_line = self.layout_row(display_row, details);
 622        layout_line.closest_index_for_x(x) as u32
 623    }
 624
 625    pub fn chars_at(
 626        &self,
 627        mut point: DisplayPoint,
 628    ) -> impl Iterator<Item = (char, DisplayPoint)> + '_ {
 629        point = DisplayPoint(self.block_snapshot.clip_point(point.0, Bias::Left));
 630        self.text_chunks(point.row())
 631            .flat_map(str::chars)
 632            .skip_while({
 633                let mut column = 0;
 634                move |char| {
 635                    let at_point = column >= point.column();
 636                    column += char.len_utf8() as u32;
 637                    !at_point
 638                }
 639            })
 640            .map(move |ch| {
 641                let result = (ch, point);
 642                if ch == '\n' {
 643                    *point.row_mut() += 1;
 644                    *point.column_mut() = 0;
 645                } else {
 646                    *point.column_mut() += ch.len_utf8() as u32;
 647                }
 648                result
 649            })
 650    }
 651
 652    pub fn reverse_chars_at(
 653        &self,
 654        mut point: DisplayPoint,
 655    ) -> impl Iterator<Item = (char, DisplayPoint)> + '_ {
 656        point = DisplayPoint(self.block_snapshot.clip_point(point.0, Bias::Left));
 657        self.reverse_text_chunks(point.row())
 658            .flat_map(|chunk| chunk.chars().rev())
 659            .skip_while({
 660                let mut column = self.line_len(point.row());
 661                if self.max_point().row() > point.row() {
 662                    column += 1;
 663                }
 664
 665                move |char| {
 666                    let at_point = column <= point.column();
 667                    column = column.saturating_sub(char.len_utf8() as u32);
 668                    !at_point
 669                }
 670            })
 671            .map(move |ch| {
 672                if ch == '\n' {
 673                    *point.row_mut() -= 1;
 674                    *point.column_mut() = self.line_len(point.row());
 675                } else {
 676                    *point.column_mut() = point.column().saturating_sub(ch.len_utf8() as u32);
 677                }
 678                (ch, point)
 679            })
 680    }
 681
 682    pub fn column_to_chars(&self, display_row: u32, target: u32) -> u32 {
 683        let mut count = 0;
 684        let mut column = 0;
 685        for (c, _) in self.chars_at(DisplayPoint::new(display_row, 0)) {
 686            if column >= target {
 687                break;
 688            }
 689            count += 1;
 690            column += c.len_utf8() as u32;
 691        }
 692        count
 693    }
 694
 695    pub fn column_from_chars(&self, display_row: u32, char_count: u32) -> u32 {
 696        let mut column = 0;
 697
 698        for (count, (c, _)) in self.chars_at(DisplayPoint::new(display_row, 0)).enumerate() {
 699            if c == '\n' || count >= char_count as usize {
 700                break;
 701            }
 702            column += c.len_utf8() as u32;
 703        }
 704
 705        column
 706    }
 707
 708    pub fn clip_point(&self, point: DisplayPoint, bias: Bias) -> DisplayPoint {
 709        let mut clipped = self.block_snapshot.clip_point(point.0, bias);
 710        if self.clip_at_line_ends {
 711            clipped = self.clip_at_line_end(DisplayPoint(clipped)).0
 712        }
 713        DisplayPoint(clipped)
 714    }
 715
 716    pub fn clip_at_line_end(&self, point: DisplayPoint) -> DisplayPoint {
 717        let mut point = point.0;
 718        if point.column == self.line_len(point.row) {
 719            point.column = point.column.saturating_sub(1);
 720            point = self.block_snapshot.clip_point(point, Bias::Left);
 721        }
 722        DisplayPoint(point)
 723    }
 724
 725    pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Fold>
 726    where
 727        T: ToOffset,
 728    {
 729        self.fold_snapshot.folds_in_range(range)
 730    }
 731
 732    pub fn blocks_in_range(
 733        &self,
 734        rows: Range<u32>,
 735    ) -> impl Iterator<Item = (u32, &TransformBlock)> {
 736        self.block_snapshot.blocks_in_range(rows)
 737    }
 738
 739    pub fn intersects_fold<T: ToOffset>(&self, offset: T) -> bool {
 740        self.fold_snapshot.intersects_fold(offset)
 741    }
 742
 743    pub fn is_line_folded(&self, buffer_row: u32) -> bool {
 744        self.fold_snapshot.is_line_folded(buffer_row)
 745    }
 746
 747    pub fn is_block_line(&self, display_row: u32) -> bool {
 748        self.block_snapshot.is_block_line(display_row)
 749    }
 750
 751    pub fn soft_wrap_indent(&self, display_row: u32) -> Option<u32> {
 752        let wrap_row = self
 753            .block_snapshot
 754            .to_wrap_point(BlockPoint::new(display_row, 0))
 755            .row();
 756        self.wrap_snapshot.soft_wrap_indent(wrap_row)
 757    }
 758
 759    pub fn text(&self) -> String {
 760        self.text_chunks(0).collect()
 761    }
 762
 763    pub fn line(&self, display_row: u32) -> String {
 764        let mut result = String::new();
 765        for chunk in self.text_chunks(display_row) {
 766            if let Some(ix) = chunk.find('\n') {
 767                result.push_str(&chunk[0..ix]);
 768                break;
 769            } else {
 770                result.push_str(chunk);
 771            }
 772        }
 773        result
 774    }
 775
 776    pub fn line_indent(&self, display_row: u32) -> (u32, bool) {
 777        let mut indent = 0;
 778        let mut is_blank = true;
 779        for (c, _) in self.chars_at(DisplayPoint::new(display_row, 0)) {
 780            if c == ' ' {
 781                indent += 1;
 782            } else {
 783                is_blank = c == '\n';
 784                break;
 785            }
 786        }
 787        (indent, is_blank)
 788    }
 789
 790    pub fn line_indent_for_buffer_row(&self, buffer_row: u32) -> (u32, bool) {
 791        let (buffer, range) = self
 792            .buffer_snapshot
 793            .buffer_line_for_row(buffer_row)
 794            .unwrap();
 795
 796        let mut indent_size = 0;
 797        let mut is_blank = false;
 798        for c in buffer.chars_at(Point::new(range.start.row, 0)) {
 799            if c == ' ' || c == '\t' {
 800                indent_size += 1;
 801            } else {
 802                if c == '\n' {
 803                    is_blank = true;
 804                }
 805                break;
 806            }
 807        }
 808
 809        (indent_size, is_blank)
 810    }
 811
 812    pub fn line_len(&self, row: u32) -> u32 {
 813        self.block_snapshot.line_len(row)
 814    }
 815
 816    pub fn longest_row(&self) -> u32 {
 817        self.block_snapshot.longest_row()
 818    }
 819
 820    pub fn fold_for_line(self: &Self, buffer_row: u32) -> Option<FoldStatus> {
 821        if self.is_line_folded(buffer_row) {
 822            Some(FoldStatus::Folded)
 823        } else if self.is_foldable(buffer_row) {
 824            Some(FoldStatus::Foldable)
 825        } else {
 826            None
 827        }
 828    }
 829
 830    pub fn is_foldable(self: &Self, buffer_row: u32) -> bool {
 831        let max_row = self.buffer_snapshot.max_buffer_row();
 832        if buffer_row >= max_row {
 833            return false;
 834        }
 835
 836        let (indent_size, is_blank) = self.line_indent_for_buffer_row(buffer_row);
 837        if is_blank {
 838            return false;
 839        }
 840
 841        for next_row in (buffer_row + 1)..=max_row {
 842            let (next_indent_size, next_line_is_blank) = self.line_indent_for_buffer_row(next_row);
 843            if next_indent_size > indent_size {
 844                return true;
 845            } else if !next_line_is_blank {
 846                break;
 847            }
 848        }
 849
 850        false
 851    }
 852
 853    pub fn foldable_range(self: &Self, buffer_row: u32) -> Option<Range<Point>> {
 854        let start = Point::new(buffer_row, self.buffer_snapshot.line_len(buffer_row));
 855        if self.is_foldable(start.row) && !self.is_line_folded(start.row) {
 856            let (start_indent, _) = self.line_indent_for_buffer_row(buffer_row);
 857            let max_point = self.buffer_snapshot.max_point();
 858            let mut end = None;
 859
 860            for row in (buffer_row + 1)..=max_point.row {
 861                let (indent, is_blank) = self.line_indent_for_buffer_row(row);
 862                if !is_blank && indent <= start_indent {
 863                    let prev_row = row - 1;
 864                    end = Some(Point::new(
 865                        prev_row,
 866                        self.buffer_snapshot.line_len(prev_row),
 867                    ));
 868                    break;
 869                }
 870            }
 871            let end = end.unwrap_or(max_point);
 872            Some(start..end)
 873        } else {
 874            None
 875        }
 876    }
 877
 878    #[cfg(any(test, feature = "test-support"))]
 879    pub fn text_highlight_ranges<Tag: ?Sized + 'static>(
 880        &self,
 881    ) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
 882        let type_id = TypeId::of::<Tag>();
 883        self.text_highlights.get(&Some(type_id)).cloned()
 884    }
 885
 886    #[cfg(any(test, feature = "test-support"))]
 887    pub fn inlay_highlights<Tag: ?Sized + 'static>(
 888        &self,
 889    ) -> Option<&HashMap<InlayId, (HighlightStyle, InlayHighlight)>> {
 890        let type_id = TypeId::of::<Tag>();
 891        self.inlay_highlights.get(&type_id)
 892    }
 893}
 894
 895#[derive(Copy, Clone, Default, Eq, Ord, PartialOrd, PartialEq)]
 896pub struct DisplayPoint(BlockPoint);
 897
 898impl Debug for DisplayPoint {
 899    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 900        f.write_fmt(format_args!(
 901            "DisplayPoint({}, {})",
 902            self.row(),
 903            self.column()
 904        ))
 905    }
 906}
 907
 908impl DisplayPoint {
 909    pub fn new(row: u32, column: u32) -> Self {
 910        Self(BlockPoint(Point::new(row, column)))
 911    }
 912
 913    pub fn zero() -> Self {
 914        Self::new(0, 0)
 915    }
 916
 917    pub fn is_zero(&self) -> bool {
 918        self.0.is_zero()
 919    }
 920
 921    pub fn row(self) -> u32 {
 922        self.0.row
 923    }
 924
 925    pub fn column(self) -> u32 {
 926        self.0.column
 927    }
 928
 929    pub fn row_mut(&mut self) -> &mut u32 {
 930        &mut self.0.row
 931    }
 932
 933    pub fn column_mut(&mut self) -> &mut u32 {
 934        &mut self.0.column
 935    }
 936
 937    pub fn to_point(self, map: &DisplaySnapshot) -> Point {
 938        map.display_point_to_point(self, Bias::Left)
 939    }
 940
 941    pub fn to_offset(self, map: &DisplaySnapshot, bias: Bias) -> usize {
 942        let wrap_point = map.block_snapshot.to_wrap_point(self.0);
 943        let tab_point = map.wrap_snapshot.to_tab_point(wrap_point);
 944        let fold_point = map.tab_snapshot.to_fold_point(tab_point, bias).0;
 945        let inlay_point = fold_point.to_inlay_point(&map.fold_snapshot);
 946        map.inlay_snapshot
 947            .to_buffer_offset(map.inlay_snapshot.to_offset(inlay_point))
 948    }
 949}
 950
 951impl ToDisplayPoint for usize {
 952    fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint {
 953        map.point_to_display_point(self.to_point(&map.buffer_snapshot), Bias::Left)
 954    }
 955}
 956
 957impl ToDisplayPoint for OffsetUtf16 {
 958    fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint {
 959        self.to_offset(&map.buffer_snapshot).to_display_point(map)
 960    }
 961}
 962
 963impl ToDisplayPoint for Point {
 964    fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint {
 965        map.point_to_display_point(*self, Bias::Left)
 966    }
 967}
 968
 969impl ToDisplayPoint for Anchor {
 970    fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint {
 971        self.to_point(&map.buffer_snapshot).to_display_point(map)
 972    }
 973}
 974
 975pub fn next_rows(display_row: u32, display_map: &DisplaySnapshot) -> impl Iterator<Item = u32> {
 976    let max_row = display_map.max_point().row();
 977    let start_row = display_row + 1;
 978    let mut current = None;
 979    std::iter::from_fn(move || {
 980        if current == None {
 981            current = Some(start_row);
 982        } else {
 983            current = Some(current.unwrap() + 1)
 984        }
 985        if current.unwrap() > max_row {
 986            None
 987        } else {
 988            current
 989        }
 990    })
 991}
 992
 993#[cfg(test)]
 994pub mod tests {
 995    use super::*;
 996    use crate::{
 997        movement,
 998        test::{editor_test_context::EditorTestContext, marked_display_snapshot},
 999    };
1000    use client::Client;
1001    use gpui::{div, font, observe, px, AppContext, Context, Element, Hsla};
1002    use language::{
1003        language_settings::{AllLanguageSettings, AllLanguageSettingsContent},
1004        Buffer, Language, LanguageConfig, SelectionGoal,
1005    };
1006    use project::Project;
1007    use rand::{prelude::*, Rng};
1008    use settings::SettingsStore;
1009    use smol::stream::StreamExt;
1010    use std::{env, sync::Arc};
1011    use theme::{LoadThemes, SyntaxTheme};
1012    use util::{
1013        http::FakeHttpClient,
1014        test::{marked_text_ranges, sample_text},
1015    };
1016    use Bias::*;
1017
1018    #[gpui::test(iterations = 100)]
1019    async fn test_random_display_map(cx: &mut gpui::TestAppContext, mut rng: StdRng) {
1020        cx.background_executor.set_block_on_ticks(0..=50);
1021        let operations = env::var("OPERATIONS")
1022            .map(|i| i.parse().expect("invalid `OPERATIONS` variable"))
1023            .unwrap_or(10);
1024
1025        let test_platform = &cx.test_platform;
1026        let mut tab_size = rng.gen_range(1..=4);
1027        let buffer_start_excerpt_header_height = rng.gen_range(1..=5);
1028        let excerpt_header_height = rng.gen_range(1..=5);
1029        let font_size = px(14.0);
1030        let max_wrap_width = 300.0;
1031        let mut wrap_width = if rng.gen_bool(0.1) {
1032            None
1033        } else {
1034            Some(px(rng.gen_range(0.0..=max_wrap_width)))
1035        };
1036
1037        log::info!("tab size: {}", tab_size);
1038        log::info!("wrap width: {:?}", wrap_width);
1039
1040        cx.update(|cx| {
1041            init_test(cx, |s| s.defaults.tab_size = NonZeroU32::new(tab_size));
1042        });
1043
1044        let buffer = cx.update(|cx| {
1045            if rng.gen() {
1046                let len = rng.gen_range(0..10);
1047                let text = util::RandomCharIter::new(&mut rng)
1048                    .take(len)
1049                    .collect::<String>();
1050                MultiBuffer::build_simple(&text, cx)
1051            } else {
1052                MultiBuffer::build_random(&mut rng, cx)
1053            }
1054        });
1055
1056        let map = cx.build_model(|cx| {
1057            DisplayMap::new(
1058                buffer.clone(),
1059                font("Helvetica"),
1060                font_size,
1061                wrap_width,
1062                buffer_start_excerpt_header_height,
1063                excerpt_header_height,
1064                cx,
1065            )
1066        });
1067        let mut notifications = observe(&map, cx);
1068        let mut fold_count = 0;
1069        let mut blocks = Vec::new();
1070
1071        let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
1072        log::info!("buffer text: {:?}", snapshot.buffer_snapshot.text());
1073        log::info!("fold text: {:?}", snapshot.fold_snapshot.text());
1074        log::info!("tab text: {:?}", snapshot.tab_snapshot.text());
1075        log::info!("wrap text: {:?}", snapshot.wrap_snapshot.text());
1076        log::info!("block text: {:?}", snapshot.block_snapshot.text());
1077        log::info!("display text: {:?}", snapshot.text());
1078
1079        for _i in 0..operations {
1080            match rng.gen_range(0..100) {
1081                0..=19 => {
1082                    wrap_width = if rng.gen_bool(0.2) {
1083                        None
1084                    } else {
1085                        Some(px(rng.gen_range(0.0..=max_wrap_width)))
1086                    };
1087                    log::info!("setting wrap width to {:?}", wrap_width);
1088                    map.update(cx, |map, cx| map.set_wrap_width(wrap_width, cx));
1089                }
1090                20..=29 => {
1091                    let mut tab_sizes = vec![1, 2, 3, 4];
1092                    tab_sizes.remove((tab_size - 1) as usize);
1093                    tab_size = *tab_sizes.choose(&mut rng).unwrap();
1094                    log::info!("setting tab size to {:?}", tab_size);
1095                    cx.update(|cx| {
1096                        cx.update_global::<SettingsStore, _>(|store, cx| {
1097                            store.update_user_settings::<AllLanguageSettings>(cx, |s| {
1098                                s.defaults.tab_size = NonZeroU32::new(tab_size);
1099                            });
1100                        });
1101                    });
1102                }
1103                30..=44 => {
1104                    map.update(cx, |map, cx| {
1105                        if rng.gen() || blocks.is_empty() {
1106                            let buffer = map.snapshot(cx).buffer_snapshot;
1107                            let block_properties = (0..rng.gen_range(1..=1))
1108                                .map(|_| {
1109                                    let position =
1110                                        buffer.anchor_after(buffer.clip_offset(
1111                                            rng.gen_range(0..=buffer.len()),
1112                                            Bias::Left,
1113                                        ));
1114
1115                                    let disposition = if rng.gen() {
1116                                        BlockDisposition::Above
1117                                    } else {
1118                                        BlockDisposition::Below
1119                                    };
1120                                    let height = rng.gen_range(1..5);
1121                                    log::info!(
1122                                        "inserting block {:?} {:?} with height {}",
1123                                        disposition,
1124                                        position.to_point(&buffer),
1125                                        height
1126                                    );
1127                                    BlockProperties {
1128                                        style: BlockStyle::Fixed,
1129                                        position,
1130                                        height,
1131                                        disposition,
1132                                        render: Arc::new(|_| div().into_any()),
1133                                    }
1134                                })
1135                                .collect::<Vec<_>>();
1136                            blocks.extend(map.insert_blocks(block_properties, cx));
1137                        } else {
1138                            blocks.shuffle(&mut rng);
1139                            let remove_count = rng.gen_range(1..=4.min(blocks.len()));
1140                            let block_ids_to_remove = (0..remove_count)
1141                                .map(|_| blocks.remove(rng.gen_range(0..blocks.len())))
1142                                .collect();
1143                            log::info!("removing block ids {:?}", block_ids_to_remove);
1144                            map.remove_blocks(block_ids_to_remove, cx);
1145                        }
1146                    });
1147                }
1148                45..=79 => {
1149                    let mut ranges = Vec::new();
1150                    for _ in 0..rng.gen_range(1..=3) {
1151                        buffer.read_with(cx, |buffer, cx| {
1152                            let buffer = buffer.read(cx);
1153                            let end = buffer.clip_offset(rng.gen_range(0..=buffer.len()), Right);
1154                            let start = buffer.clip_offset(rng.gen_range(0..=end), Left);
1155                            ranges.push(start..end);
1156                        });
1157                    }
1158
1159                    if rng.gen() && fold_count > 0 {
1160                        log::info!("unfolding ranges: {:?}", ranges);
1161                        map.update(cx, |map, cx| {
1162                            map.unfold(ranges, true, cx);
1163                        });
1164                    } else {
1165                        log::info!("folding ranges: {:?}", ranges);
1166                        map.update(cx, |map, cx| {
1167                            map.fold(ranges, cx);
1168                        });
1169                    }
1170                }
1171                _ => {
1172                    buffer.update(cx, |buffer, cx| buffer.randomly_mutate(&mut rng, 5, cx));
1173                }
1174            }
1175
1176            if map.read_with(cx, |map, cx| map.is_rewrapping(cx)) {
1177                notifications.next().await.unwrap();
1178            }
1179
1180            let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
1181            fold_count = snapshot.fold_count();
1182            log::info!("buffer text: {:?}", snapshot.buffer_snapshot.text());
1183            log::info!("fold text: {:?}", snapshot.fold_snapshot.text());
1184            log::info!("tab text: {:?}", snapshot.tab_snapshot.text());
1185            log::info!("wrap text: {:?}", snapshot.wrap_snapshot.text());
1186            log::info!("block text: {:?}", snapshot.block_snapshot.text());
1187            log::info!("display text: {:?}", snapshot.text());
1188
1189            // Line boundaries
1190            let buffer = &snapshot.buffer_snapshot;
1191            for _ in 0..5 {
1192                let row = rng.gen_range(0..=buffer.max_point().row);
1193                let column = rng.gen_range(0..=buffer.line_len(row));
1194                let point = buffer.clip_point(Point::new(row, column), Left);
1195
1196                let (prev_buffer_bound, prev_display_bound) = snapshot.prev_line_boundary(point);
1197                let (next_buffer_bound, next_display_bound) = snapshot.next_line_boundary(point);
1198
1199                assert!(prev_buffer_bound <= point);
1200                assert!(next_buffer_bound >= point);
1201                assert_eq!(prev_buffer_bound.column, 0);
1202                assert_eq!(prev_display_bound.column(), 0);
1203                if next_buffer_bound < buffer.max_point() {
1204                    assert_eq!(buffer.chars_at(next_buffer_bound).next(), Some('\n'));
1205                }
1206
1207                assert_eq!(
1208                    prev_display_bound,
1209                    prev_buffer_bound.to_display_point(&snapshot),
1210                    "row boundary before {:?}. reported buffer row boundary: {:?}",
1211                    point,
1212                    prev_buffer_bound
1213                );
1214                assert_eq!(
1215                    next_display_bound,
1216                    next_buffer_bound.to_display_point(&snapshot),
1217                    "display row boundary after {:?}. reported buffer row boundary: {:?}",
1218                    point,
1219                    next_buffer_bound
1220                );
1221                assert_eq!(
1222                    prev_buffer_bound,
1223                    prev_display_bound.to_point(&snapshot),
1224                    "row boundary before {:?}. reported display row boundary: {:?}",
1225                    point,
1226                    prev_display_bound
1227                );
1228                assert_eq!(
1229                    next_buffer_bound,
1230                    next_display_bound.to_point(&snapshot),
1231                    "row boundary after {:?}. reported display row boundary: {:?}",
1232                    point,
1233                    next_display_bound
1234                );
1235            }
1236
1237            // Movement
1238            let min_point = snapshot.clip_point(DisplayPoint::new(0, 0), Left);
1239            let max_point = snapshot.clip_point(snapshot.max_point(), Right);
1240            for _ in 0..5 {
1241                let row = rng.gen_range(0..=snapshot.max_point().row());
1242                let column = rng.gen_range(0..=snapshot.line_len(row));
1243                let point = snapshot.clip_point(DisplayPoint::new(row, column), Left);
1244
1245                log::info!("Moving from point {:?}", point);
1246
1247                let moved_right = movement::right(&snapshot, point);
1248                log::info!("Right {:?}", moved_right);
1249                if point < max_point {
1250                    assert!(moved_right > point);
1251                    if point.column() == snapshot.line_len(point.row())
1252                        || snapshot.soft_wrap_indent(point.row()).is_some()
1253                            && point.column() == snapshot.line_len(point.row()) - 1
1254                    {
1255                        assert!(moved_right.row() > point.row());
1256                    }
1257                } else {
1258                    assert_eq!(moved_right, point);
1259                }
1260
1261                let moved_left = movement::left(&snapshot, point);
1262                log::info!("Left {:?}", moved_left);
1263                if point > min_point {
1264                    assert!(moved_left < point);
1265                    if point.column() == 0 {
1266                        assert!(moved_left.row() < point.row());
1267                    }
1268                } else {
1269                    assert_eq!(moved_left, point);
1270                }
1271            }
1272        }
1273    }
1274
1275    #[gpui::test(retries = 5)]
1276    async fn test_soft_wraps(cx: &mut gpui::TestAppContext) {
1277        cx.background_executor
1278            .set_block_on_ticks(usize::MAX..=usize::MAX);
1279        cx.update(|cx| {
1280            init_test(cx, |_| {});
1281        });
1282
1283        let mut cx = EditorTestContext::new(cx).await;
1284        let editor = cx.editor.clone();
1285        let window = cx.window.clone();
1286
1287        cx.update_window(window, |_, cx| {
1288            let text_layout_details =
1289                editor.update(cx, |editor, cx| editor.text_layout_details(cx));
1290
1291            let font_size = px(12.0);
1292            let wrap_width = Some(px(64.));
1293
1294            let text = "one two three four five\nsix seven eight";
1295            let buffer = MultiBuffer::build_simple(text, cx);
1296            let map = cx.build_model(|cx| {
1297                DisplayMap::new(
1298                    buffer.clone(),
1299                    font("Helvetica"),
1300                    font_size,
1301                    wrap_width,
1302                    1,
1303                    1,
1304                    cx,
1305                )
1306            });
1307
1308            let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
1309            assert_eq!(
1310                snapshot.text_chunks(0).collect::<String>(),
1311                "one two \nthree four \nfive\nsix seven \neight"
1312            );
1313            assert_eq!(
1314                snapshot.clip_point(DisplayPoint::new(0, 8), Bias::Left),
1315                DisplayPoint::new(0, 7)
1316            );
1317            assert_eq!(
1318                snapshot.clip_point(DisplayPoint::new(0, 8), Bias::Right),
1319                DisplayPoint::new(1, 0)
1320            );
1321            assert_eq!(
1322                movement::right(&snapshot, DisplayPoint::new(0, 7)),
1323                DisplayPoint::new(1, 0)
1324            );
1325            assert_eq!(
1326                movement::left(&snapshot, DisplayPoint::new(1, 0)),
1327                DisplayPoint::new(0, 7)
1328            );
1329
1330            let x = snapshot.x_for_display_point(DisplayPoint::new(1, 10), &text_layout_details);
1331            assert_eq!(
1332                movement::up(
1333                    &snapshot,
1334                    DisplayPoint::new(1, 10),
1335                    SelectionGoal::None,
1336                    false,
1337                    &text_layout_details,
1338                ),
1339                (
1340                    DisplayPoint::new(0, 7),
1341                    SelectionGoal::HorizontalPosition(x.0)
1342                )
1343            );
1344            assert_eq!(
1345                movement::down(
1346                    &snapshot,
1347                    DisplayPoint::new(0, 7),
1348                    SelectionGoal::HorizontalPosition(x.0),
1349                    false,
1350                    &text_layout_details
1351                ),
1352                (
1353                    DisplayPoint::new(1, 10),
1354                    SelectionGoal::HorizontalPosition(x.0)
1355                )
1356            );
1357            assert_eq!(
1358                movement::down(
1359                    &snapshot,
1360                    DisplayPoint::new(1, 10),
1361                    SelectionGoal::HorizontalPosition(x.0),
1362                    false,
1363                    &text_layout_details
1364                ),
1365                (
1366                    DisplayPoint::new(2, 4),
1367                    SelectionGoal::HorizontalPosition(x.0)
1368                )
1369            );
1370
1371            let ix = snapshot.buffer_snapshot.text().find("seven").unwrap();
1372            buffer.update(cx, |buffer, cx| {
1373                buffer.edit([(ix..ix, "and ")], None, cx);
1374            });
1375
1376            let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
1377            assert_eq!(
1378                snapshot.text_chunks(1).collect::<String>(),
1379                "three four \nfive\nsix and \nseven eight"
1380            );
1381
1382            // Re-wrap on font size changes
1383            map.update(cx, |map, cx| {
1384                map.set_font(font("Helvetica"), px(font_size.0 + 3.), cx)
1385            });
1386
1387            let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
1388            assert_eq!(
1389                snapshot.text_chunks(1).collect::<String>(),
1390                "three \nfour five\nsix and \nseven \neight"
1391            )
1392        });
1393    }
1394
1395    #[gpui::test]
1396    fn test_text_chunks(cx: &mut gpui::AppContext) {
1397        init_test(cx, |_| {});
1398
1399        let text = sample_text(6, 6, 'a');
1400        let buffer = MultiBuffer::build_simple(&text, cx);
1401
1402        let font_size = px(14.0);
1403        let map = cx.build_model(|cx| {
1404            DisplayMap::new(buffer.clone(), font("Helvetica"), font_size, None, 1, 1, cx)
1405        });
1406
1407        buffer.update(cx, |buffer, cx| {
1408            buffer.edit(
1409                vec![
1410                    (Point::new(1, 0)..Point::new(1, 0), "\t"),
1411                    (Point::new(1, 1)..Point::new(1, 1), "\t"),
1412                    (Point::new(2, 1)..Point::new(2, 1), "\t"),
1413                ],
1414                None,
1415                cx,
1416            )
1417        });
1418
1419        assert_eq!(
1420            map.update(cx, |map, cx| map.snapshot(cx))
1421                .text_chunks(1)
1422                .collect::<String>()
1423                .lines()
1424                .next(),
1425            Some("    b   bbbbb")
1426        );
1427        assert_eq!(
1428            map.update(cx, |map, cx| map.snapshot(cx))
1429                .text_chunks(2)
1430                .collect::<String>()
1431                .lines()
1432                .next(),
1433            Some("c   ccccc")
1434        );
1435    }
1436
1437    #[gpui::test]
1438    async fn test_chunks(cx: &mut gpui::TestAppContext) {
1439        use unindent::Unindent as _;
1440
1441        let text = r#"
1442            fn outer() {}
1443
1444            mod module {
1445                fn inner() {}
1446            }"#
1447        .unindent();
1448
1449        let theme = SyntaxTheme::new_test(vec![
1450            ("mod.body", Hsla::red().into()),
1451            ("fn.name", Hsla::blue().into()),
1452        ]);
1453        let language = Arc::new(
1454            Language::new(
1455                LanguageConfig {
1456                    name: "Test".into(),
1457                    path_suffixes: vec![".test".to_string()],
1458                    ..Default::default()
1459                },
1460                Some(tree_sitter_rust::language()),
1461            )
1462            .with_highlights_query(
1463                r#"
1464                (mod_item name: (identifier) body: _ @mod.body)
1465                (function_item name: (identifier) @fn.name)
1466                "#,
1467            )
1468            .unwrap(),
1469        );
1470        language.set_theme(&theme);
1471
1472        cx.update(|cx| init_test(cx, |s| s.defaults.tab_size = Some(2.try_into().unwrap())));
1473
1474        let buffer = cx.build_model(|cx| {
1475            Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
1476        });
1477        cx.condition(&buffer, |buf, _| !buf.is_parsing()).await;
1478        let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
1479
1480        let font_size = px(14.0);
1481
1482        let map = cx.build_model(|cx| {
1483            DisplayMap::new(buffer, font("Helvetica"), font_size, None, 1, 1, cx)
1484        });
1485        assert_eq!(
1486            cx.update(|cx| syntax_chunks(0..5, &map, &theme, cx)),
1487            vec![
1488                ("fn ".to_string(), None),
1489                ("outer".to_string(), Some(Hsla::blue())),
1490                ("() {}\n\nmod module ".to_string(), None),
1491                ("{\n    fn ".to_string(), Some(Hsla::red())),
1492                ("inner".to_string(), Some(Hsla::blue())),
1493                ("() {}\n}".to_string(), Some(Hsla::red())),
1494            ]
1495        );
1496        assert_eq!(
1497            cx.update(|cx| syntax_chunks(3..5, &map, &theme, cx)),
1498            vec![
1499                ("    fn ".to_string(), Some(Hsla::red())),
1500                ("inner".to_string(), Some(Hsla::blue())),
1501                ("() {}\n}".to_string(), Some(Hsla::red())),
1502            ]
1503        );
1504
1505        map.update(cx, |map, cx| {
1506            map.fold(vec![Point::new(0, 6)..Point::new(3, 2)], cx)
1507        });
1508        assert_eq!(
1509            cx.update(|cx| syntax_chunks(0..2, &map, &theme, cx)),
1510            vec![
1511                ("fn ".to_string(), None),
1512                ("out".to_string(), Some(Hsla::blue())),
1513                ("⋯".to_string(), None),
1514                ("  fn ".to_string(), Some(Hsla::red())),
1515                ("inner".to_string(), Some(Hsla::blue())),
1516                ("() {}\n}".to_string(), Some(Hsla::red())),
1517            ]
1518        );
1519    }
1520
1521    #[gpui::test]
1522    async fn test_chunks_with_soft_wrapping(cx: &mut gpui::TestAppContext) {
1523        use unindent::Unindent as _;
1524
1525        cx.background_executor
1526            .set_block_on_ticks(usize::MAX..=usize::MAX);
1527
1528        let text = r#"
1529            fn outer() {}
1530
1531            mod module {
1532                fn inner() {}
1533            }"#
1534        .unindent();
1535
1536        let theme = SyntaxTheme::new_test(vec![
1537            ("mod.body", Hsla::red().into()),
1538            ("fn.name", Hsla::blue().into()),
1539        ]);
1540        let language = Arc::new(
1541            Language::new(
1542                LanguageConfig {
1543                    name: "Test".into(),
1544                    path_suffixes: vec![".test".to_string()],
1545                    ..Default::default()
1546                },
1547                Some(tree_sitter_rust::language()),
1548            )
1549            .with_highlights_query(
1550                r#"
1551                (mod_item name: (identifier) body: _ @mod.body)
1552                (function_item name: (identifier) @fn.name)
1553                "#,
1554            )
1555            .unwrap(),
1556        );
1557        language.set_theme(&theme);
1558
1559        cx.update(|cx| init_test(cx, |_| {}));
1560
1561        let buffer = cx.build_model(|cx| {
1562            Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
1563        });
1564        cx.condition(&buffer, |buf, _| !buf.is_parsing()).await;
1565        let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
1566
1567        let font_size = px(16.0);
1568
1569        let map = cx.build_model(|cx| {
1570            DisplayMap::new(buffer, font("Courier"), font_size, Some(px(40.0)), 1, 1, cx)
1571        });
1572        assert_eq!(
1573            cx.update(|cx| syntax_chunks(0..5, &map, &theme, cx)),
1574            [
1575                ("fn \n".to_string(), None),
1576                ("oute\nr".to_string(), Some(Hsla::blue())),
1577                ("() \n{}\n\n".to_string(), None),
1578            ]
1579        );
1580        assert_eq!(
1581            cx.update(|cx| syntax_chunks(3..5, &map, &theme, cx)),
1582            [("{}\n\n".to_string(), None)]
1583        );
1584
1585        map.update(cx, |map, cx| {
1586            map.fold(vec![Point::new(0, 6)..Point::new(3, 2)], cx)
1587        });
1588        assert_eq!(
1589            cx.update(|cx| syntax_chunks(1..4, &map, &theme, cx)),
1590            [
1591                ("out".to_string(), Some(Hsla::blue())),
1592                ("⋯\n".to_string(), None),
1593                ("  \nfn ".to_string(), Some(Hsla::red())),
1594                ("i\n".to_string(), Some(Hsla::blue()))
1595            ]
1596        );
1597    }
1598
1599    #[gpui::test]
1600    async fn test_chunks_with_text_highlights(cx: &mut gpui::TestAppContext) {
1601        cx.update(|cx| init_test(cx, |_| {}));
1602
1603        let theme = SyntaxTheme::new_test(vec![
1604            ("operator", Hsla::red().into()),
1605            ("string", Hsla::green().into()),
1606        ]);
1607        let language = Arc::new(
1608            Language::new(
1609                LanguageConfig {
1610                    name: "Test".into(),
1611                    path_suffixes: vec![".test".to_string()],
1612                    ..Default::default()
1613                },
1614                Some(tree_sitter_rust::language()),
1615            )
1616            .with_highlights_query(
1617                r#"
1618                ":" @operator
1619                (string_literal) @string
1620                "#,
1621            )
1622            .unwrap(),
1623        );
1624        language.set_theme(&theme);
1625
1626        let (text, highlighted_ranges) = marked_text_ranges(r#"constˇ Ā«aĀ»: B = "c Ā«dĀ»""#, false);
1627
1628        let buffer = cx.build_model(|cx| {
1629            Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
1630        });
1631        cx.condition(&buffer, |buf, _| !buf.is_parsing()).await;
1632
1633        let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
1634        let buffer_snapshot = buffer.read_with(cx, |buffer, cx| buffer.snapshot(cx));
1635
1636        let font_size = px(16.0);
1637        let map = cx
1638            .build_model(|cx| DisplayMap::new(buffer, font("Courier"), font_size, None, 1, 1, cx));
1639
1640        enum MyType {}
1641
1642        let style = HighlightStyle {
1643            color: Some(Hsla::blue()),
1644            ..Default::default()
1645        };
1646
1647        map.update(cx, |map, _cx| {
1648            map.highlight_text(
1649                TypeId::of::<MyType>(),
1650                highlighted_ranges
1651                    .into_iter()
1652                    .map(|range| {
1653                        buffer_snapshot.anchor_before(range.start)
1654                            ..buffer_snapshot.anchor_before(range.end)
1655                    })
1656                    .collect(),
1657                style,
1658            );
1659        });
1660
1661        assert_eq!(
1662            cx.update(|cx| chunks(0..10, &map, &theme, cx)),
1663            [
1664                ("const ".to_string(), None, None),
1665                ("a".to_string(), None, Some(Hsla::blue())),
1666                (":".to_string(), Some(Hsla::red()), None),
1667                (" B = ".to_string(), None, None),
1668                ("\"c ".to_string(), Some(Hsla::green()), None),
1669                ("d".to_string(), Some(Hsla::green()), Some(Hsla::blue())),
1670                ("\"".to_string(), Some(Hsla::green()), None),
1671            ]
1672        );
1673    }
1674
1675    #[gpui::test]
1676    fn test_clip_point(cx: &mut gpui::AppContext) {
1677        init_test(cx, |_| {});
1678
1679        fn assert(text: &str, shift_right: bool, bias: Bias, cx: &mut gpui::AppContext) {
1680            let (unmarked_snapshot, mut markers) = marked_display_snapshot(text, cx);
1681
1682            match bias {
1683                Bias::Left => {
1684                    if shift_right {
1685                        *markers[1].column_mut() += 1;
1686                    }
1687
1688                    assert_eq!(unmarked_snapshot.clip_point(markers[1], bias), markers[0])
1689                }
1690                Bias::Right => {
1691                    if shift_right {
1692                        *markers[0].column_mut() += 1;
1693                    }
1694
1695                    assert_eq!(unmarked_snapshot.clip_point(markers[0], bias), markers[1])
1696                }
1697            };
1698        }
1699
1700        use Bias::{Left, Right};
1701        assert("ˇˇα", false, Left, cx);
1702        assert("ˇˇα", true, Left, cx);
1703        assert("ˇˇα", false, Right, cx);
1704        assert("ˇαˇ", true, Right, cx);
1705        assert("Ė‡Ė‡āœ‹", false, Left, cx);
1706        assert("Ė‡Ė‡āœ‹", true, Left, cx);
1707        assert("Ė‡Ė‡āœ‹", false, Right, cx);
1708        assert("Ė‡āœ‹Ė‡", true, Right, cx);
1709        assert("Ė‡Ė‡šŸ", false, Left, cx);
1710        assert("Ė‡Ė‡šŸ", true, Left, cx);
1711        assert("Ė‡Ė‡šŸ", false, Right, cx);
1712        assert("Ė‡šŸĖ‡", true, Right, cx);
1713        assert("ˇˇ\t", false, Left, cx);
1714        assert("ˇˇ\t", true, Left, cx);
1715        assert("ˇˇ\t", false, Right, cx);
1716        assert("ˇ\tˇ", true, Right, cx);
1717        assert(" ˇˇ\t", false, Left, cx);
1718        assert(" ˇˇ\t", true, Left, cx);
1719        assert(" ˇˇ\t", false, Right, cx);
1720        assert(" ˇ\tˇ", true, Right, cx);
1721        assert("   ˇˇ\t", false, Left, cx);
1722        assert("   ˇˇ\t", false, Right, cx);
1723    }
1724
1725    #[gpui::test]
1726    fn test_clip_at_line_ends(cx: &mut gpui::AppContext) {
1727        init_test(cx, |_| {});
1728
1729        fn assert(text: &str, cx: &mut gpui::AppContext) {
1730            let (mut unmarked_snapshot, markers) = marked_display_snapshot(text, cx);
1731            unmarked_snapshot.clip_at_line_ends = true;
1732            assert_eq!(
1733                unmarked_snapshot.clip_point(markers[1], Bias::Left),
1734                markers[0]
1735            );
1736        }
1737
1738        assert("ˇˇ", cx);
1739        assert("ˇaˇ", cx);
1740        assert("aˇbˇ", cx);
1741        assert("aˇαˇ", cx);
1742    }
1743
1744    #[gpui::test]
1745    fn test_tabs_with_multibyte_chars(cx: &mut gpui::AppContext) {
1746        init_test(cx, |_| {});
1747
1748        let text = "āœ…\t\tα\nβ\t\nšŸ€Ī²\t\tγ";
1749        let buffer = MultiBuffer::build_simple(text, cx);
1750        let font_size = px(14.0);
1751
1752        let map = cx.build_model(|cx| {
1753            DisplayMap::new(buffer.clone(), font("Helvetica"), font_size, None, 1, 1, cx)
1754        });
1755        let map = map.update(cx, |map, cx| map.snapshot(cx));
1756        assert_eq!(map.text(), "āœ…       α\nβ   \nšŸ€Ī²      γ");
1757        assert_eq!(
1758            map.text_chunks(0).collect::<String>(),
1759            "āœ…       α\nβ   \nšŸ€Ī²      γ"
1760        );
1761        assert_eq!(map.text_chunks(1).collect::<String>(), "β   \nšŸ€Ī²      γ");
1762        assert_eq!(map.text_chunks(2).collect::<String>(), "šŸ€Ī²      γ");
1763
1764        let point = Point::new(0, "āœ…\t\t".len() as u32);
1765        let display_point = DisplayPoint::new(0, "āœ…       ".len() as u32);
1766        assert_eq!(point.to_display_point(&map), display_point);
1767        assert_eq!(display_point.to_point(&map), point);
1768
1769        let point = Point::new(1, "β\t".len() as u32);
1770        let display_point = DisplayPoint::new(1, "β   ".len() as u32);
1771        assert_eq!(point.to_display_point(&map), display_point);
1772        assert_eq!(display_point.to_point(&map), point,);
1773
1774        let point = Point::new(2, "šŸ€Ī²\t\t".len() as u32);
1775        let display_point = DisplayPoint::new(2, "šŸ€Ī²      ".len() as u32);
1776        assert_eq!(point.to_display_point(&map), display_point);
1777        assert_eq!(display_point.to_point(&map), point,);
1778
1779        // Display points inside of expanded tabs
1780        assert_eq!(
1781            DisplayPoint::new(0, "āœ…      ".len() as u32).to_point(&map),
1782            Point::new(0, "āœ…\t".len() as u32),
1783        );
1784        assert_eq!(
1785            DisplayPoint::new(0, "āœ… ".len() as u32).to_point(&map),
1786            Point::new(0, "āœ…".len() as u32),
1787        );
1788
1789        // Clipping display points inside of multi-byte characters
1790        assert_eq!(
1791            map.clip_point(DisplayPoint::new(0, "āœ…".len() as u32 - 1), Left),
1792            DisplayPoint::new(0, 0)
1793        );
1794        assert_eq!(
1795            map.clip_point(DisplayPoint::new(0, "āœ…".len() as u32 - 1), Bias::Right),
1796            DisplayPoint::new(0, "āœ…".len() as u32)
1797        );
1798    }
1799
1800    #[gpui::test]
1801    fn test_max_point(cx: &mut gpui::AppContext) {
1802        init_test(cx, |_| {});
1803
1804        let buffer = MultiBuffer::build_simple("aaa\n\t\tbbb", cx);
1805        let font_size = px(14.0);
1806        let map = cx.build_model(|cx| {
1807            DisplayMap::new(buffer.clone(), font("Helvetica"), font_size, None, 1, 1, cx)
1808        });
1809        assert_eq!(
1810            map.update(cx, |map, cx| map.snapshot(cx)).max_point(),
1811            DisplayPoint::new(1, 11)
1812        )
1813    }
1814
1815    fn syntax_chunks<'a>(
1816        rows: Range<u32>,
1817        map: &Model<DisplayMap>,
1818        theme: &'a SyntaxTheme,
1819        cx: &mut AppContext,
1820    ) -> Vec<(String, Option<Hsla>)> {
1821        chunks(rows, map, theme, cx)
1822            .into_iter()
1823            .map(|(text, color, _)| (text, color))
1824            .collect()
1825    }
1826
1827    fn chunks<'a>(
1828        rows: Range<u32>,
1829        map: &Model<DisplayMap>,
1830        theme: &'a SyntaxTheme,
1831        cx: &mut AppContext,
1832    ) -> Vec<(String, Option<Hsla>, Option<Hsla>)> {
1833        let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
1834        let mut chunks: Vec<(String, Option<Hsla>, Option<Hsla>)> = Vec::new();
1835        for chunk in snapshot.chunks(rows, true, None, None) {
1836            let syntax_color = chunk
1837                .syntax_highlight_id
1838                .and_then(|id| id.style(theme)?.color);
1839            let highlight_color = chunk.highlight_style.and_then(|style| style.color);
1840            if let Some((last_chunk, last_syntax_color, last_highlight_color)) = chunks.last_mut() {
1841                if syntax_color == *last_syntax_color && highlight_color == *last_highlight_color {
1842                    last_chunk.push_str(chunk.text);
1843                    continue;
1844                }
1845            }
1846            chunks.push((chunk.text.to_string(), syntax_color, highlight_color));
1847        }
1848        chunks
1849    }
1850
1851    fn init_test(cx: &mut AppContext, f: impl Fn(&mut AllLanguageSettingsContent)) {
1852        let settings = SettingsStore::test(cx);
1853        cx.set_global(settings);
1854        language::init(cx);
1855        crate::init(cx);
1856        Project::init_settings(cx);
1857        theme::init(LoadThemes::JustBase, cx);
1858        cx.update_global::<SettingsStore, _>(|store, cx| {
1859            store.update_user_settings::<AllLanguageSettings>(cx, f);
1860        });
1861    }
1862}