Refactor TextLayoutDetails construction

This commit is contained in:
Conrad Irwin
2023-10-18 22:56:11 -06:00
parent 138fa45ecb
commit 3eb8aa8085
10 changed files with 52 additions and 64 deletions
+1 -1
View File
@@ -1288,7 +1288,7 @@ pub mod tests {
cx.update_window(window, |cx| {
let text_layout_details =
editor.read_with(cx, |editor, cx| TextLayoutDetails::new(editor, cx));
editor.read_with(cx, |editor, cx| editor.text_layout_details(cx));
let font_cache = cx.font_cache().clone();
+17 -9
View File
@@ -3065,6 +3065,14 @@ impl Editor {
.collect()
}
pub fn text_layout_details(&self, cx: &WindowContext) -> TextLayoutDetails {
TextLayoutDetails {
font_cache: cx.font_cache().clone(),
text_layout_cache: cx.text_layout_cache().clone(),
editor_style: self.style(cx),
}
}
fn splice_inlay_hints(
&self,
to_remove: Vec<InlayId>,
@@ -4988,7 +4996,7 @@ impl Editor {
}
pub fn transpose(&mut self, _: &Transpose, cx: &mut ViewContext<Self>) {
let text_layout_details = TextLayoutDetails::new(&self, cx);
let text_layout_details = &self.text_layout_details(cx);
self.transact(cx, |this, cx| {
let edits = this.change_selections(Some(Autoscroll::fit()), cx, |s| {
let mut edits: Vec<(Range<usize>, String)> = Default::default();
@@ -5279,7 +5287,7 @@ impl Editor {
return;
}
let text_layout_details = TextLayoutDetails::new(&self, cx);
let text_layout_details = &self.text_layout_details(cx);
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
let line_mode = s.line_mode;
@@ -5321,7 +5329,7 @@ impl Editor {
Autoscroll::fit()
};
let text_layout_details = TextLayoutDetails::new(&self, cx);
let text_layout_details = &self.text_layout_details(cx);
self.change_selections(Some(autoscroll), cx, |s| {
let line_mode = s.line_mode;
@@ -5343,7 +5351,7 @@ impl Editor {
}
pub fn select_up(&mut self, _: &SelectUp, cx: &mut ViewContext<Self>) {
let text_layout_details = TextLayoutDetails::new(&self, cx);
let text_layout_details = &self.text_layout_details(cx);
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.move_heads_with(|map, head, goal| {
movement::up(map, head, goal, false, &text_layout_details)
@@ -5359,7 +5367,7 @@ impl Editor {
return;
}
let text_layout_details = TextLayoutDetails::new(&self, cx);
let text_layout_details = &self.text_layout_details(cx);
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
let line_mode = s.line_mode;
s.move_with(|map, selection| {
@@ -5409,7 +5417,7 @@ impl Editor {
Autoscroll::fit()
};
let text_layout_details = TextLayoutDetails::new(&self, cx);
let text_layout_details = &self.text_layout_details(cx);
self.change_selections(Some(autoscroll), cx, |s| {
let line_mode = s.line_mode;
s.move_with(|map, selection| {
@@ -5430,7 +5438,7 @@ impl Editor {
}
pub fn select_down(&mut self, _: &SelectDown, cx: &mut ViewContext<Self>) {
let text_layout_details = TextLayoutDetails::new(&self, cx);
let text_layout_details = &self.text_layout_details(cx);
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
s.move_heads_with(|map, head, goal| {
movement::down(map, head, goal, false, &text_layout_details)
@@ -5953,7 +5961,7 @@ impl Editor {
fn add_selection(&mut self, above: bool, cx: &mut ViewContext<Self>) {
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let mut selections = self.selections.all::<Point>(cx);
let text_layout_details = TextLayoutDetails::new(self, cx);
let text_layout_details = self.text_layout_details(cx);
let mut state = self.add_selections_state.take().unwrap_or_else(|| {
let oldest_selection = selections.iter().min_by_key(|s| s.id).unwrap().clone();
let range = oldest_selection.display_range(&display_map).sorted();
@@ -6315,7 +6323,7 @@ impl Editor {
}
pub fn toggle_comments(&mut self, action: &ToggleComments, cx: &mut ViewContext<Self>) {
let text_layout_details = TextLayoutDetails::new(&self, cx);
let text_layout_details = &self.text_layout_details(cx);
self.transact(cx, |this, cx| {
let mut selections = this.selections.all::<Point>(cx);
let mut edits = Vec::new();
+3 -13
View File
@@ -1,6 +1,6 @@
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
use crate::{char_kind, CharKind, Editor, EditorStyle, ToOffset, ToPoint};
use gpui::{FontCache, TextLayoutCache, WindowContext};
use crate::{char_kind, CharKind, EditorStyle, ToOffset, ToPoint};
use gpui::{FontCache, TextLayoutCache};
use language::Point;
use std::{ops::Range, sync::Arc};
@@ -18,16 +18,6 @@ pub struct TextLayoutDetails {
pub editor_style: EditorStyle,
}
impl TextLayoutDetails {
pub fn new(editor: &Editor, cx: &WindowContext) -> TextLayoutDetails {
TextLayoutDetails {
font_cache: cx.font_cache().clone(),
text_layout_cache: cx.text_layout_cache().clone(),
editor_style: editor.style(cx),
}
}
}
pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
if point.column() > 0 {
*point.column_mut() -= 1;
@@ -743,7 +733,7 @@ mod tests {
let window = cx.window.clone();
cx.update_window(window, |cx| {
let text_layout_details =
editor.read_with(cx, |editor, cx| TextLayoutDetails::new(editor, cx));
editor.read_with(cx, |editor, cx| editor.text_layout_details(cx));
let family_id = cx
.font_cache()