mirror of
https://github.com/zed-industries/zed.git
synced 2024-10-26 00:19:46 +00:00
Reduced time holding lock even more
This commit is contained in:
parent
57146b6e39
commit
81cbdcfd11
1 changed files with 78 additions and 50 deletions
|
@ -1,6 +1,6 @@
|
||||||
use alacritty_terminal::{
|
use alacritty_terminal::{
|
||||||
ansi::{Color::Named, NamedColor},
|
ansi::{Color::Named, NamedColor},
|
||||||
grid::{Dimensions, GridIterator, Indexed, Scroll},
|
grid::{Dimensions, Scroll},
|
||||||
index::{Column as GridCol, Line as GridLine, Point, Side},
|
index::{Column as GridCol, Line as GridLine, Point, Side},
|
||||||
selection::SelectionRange,
|
selection::SelectionRange,
|
||||||
term::cell::{Cell, Flags},
|
term::cell::{Cell, Flags},
|
||||||
|
@ -25,7 +25,10 @@ use settings::Settings;
|
||||||
use theme::TerminalStyle;
|
use theme::TerminalStyle;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
use std::{cmp::min, ops::Range};
|
use std::{
|
||||||
|
cmp::min,
|
||||||
|
ops::{Deref, Range},
|
||||||
|
};
|
||||||
use std::{fmt::Debug, ops::Sub};
|
use std::{fmt::Debug, ops::Sub};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -49,6 +52,20 @@ pub struct LayoutState {
|
||||||
display_offset: usize,
|
display_offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct IndexedCell {
|
||||||
|
point: Point,
|
||||||
|
cell: Cell,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for IndexedCell {
|
||||||
|
type Target = Cell;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn deref(&self) -> &Cell {
|
||||||
|
&self.cell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///Helper struct for converting data between alacritty's cursor points, and displayed cursor points
|
///Helper struct for converting data between alacritty's cursor points, and displayed cursor points
|
||||||
struct DisplayCursor {
|
struct DisplayCursor {
|
||||||
line: i32,
|
line: i32,
|
||||||
|
@ -190,7 +207,7 @@ impl TerminalEl {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_grid(
|
fn layout_grid(
|
||||||
grid: GridIterator<Cell>,
|
grid: Vec<IndexedCell>,
|
||||||
text_style: &TextStyle,
|
text_style: &TextStyle,
|
||||||
terminal_theme: &TerminalStyle,
|
terminal_theme: &TerminalStyle,
|
||||||
text_layout_cache: &TextLayoutCache,
|
text_layout_cache: &TextLayoutCache,
|
||||||
|
@ -209,7 +226,7 @@ impl TerminalEl {
|
||||||
let mut cur_alac_color = None;
|
let mut cur_alac_color = None;
|
||||||
let mut highlighted_range = None;
|
let mut highlighted_range = None;
|
||||||
|
|
||||||
let linegroups = grid.group_by(|i| i.point.line);
|
let linegroups = grid.into_iter().group_by(|i| i.point.line);
|
||||||
for (line_index, (_, line)) in linegroups.into_iter().enumerate() {
|
for (line_index, (_, line)) in linegroups.into_iter().enumerate() {
|
||||||
for (x_index, cell) in line.enumerate() {
|
for (x_index, cell) in line.enumerate() {
|
||||||
//Increase selection range
|
//Increase selection range
|
||||||
|
@ -236,7 +253,7 @@ impl TerminalEl {
|
||||||
} else {
|
} else {
|
||||||
match cur_alac_color {
|
match cur_alac_color {
|
||||||
Some(cur_color) => {
|
Some(cur_color) => {
|
||||||
if cell.bg == cur_color {
|
if cell.cell.bg == cur_color {
|
||||||
cur_rect = cur_rect.take().map(|rect| rect.extend());
|
cur_rect = cur_rect.take().map(|rect| rect.extend());
|
||||||
} else {
|
} else {
|
||||||
cur_alac_color = Some(cell.bg);
|
cur_alac_color = Some(cell.bg);
|
||||||
|
@ -326,7 +343,7 @@ impl TerminalEl {
|
||||||
|
|
||||||
///Convert the Alacritty cell styles to GPUI text styles and background color
|
///Convert the Alacritty cell styles to GPUI text styles and background color
|
||||||
fn cell_style(
|
fn cell_style(
|
||||||
indexed: &Indexed<&Cell>,
|
indexed: &IndexedCell,
|
||||||
style: &TerminalStyle,
|
style: &TerminalStyle,
|
||||||
text_style: &TextStyle,
|
text_style: &TextStyle,
|
||||||
modal: bool,
|
modal: bool,
|
||||||
|
@ -532,26 +549,41 @@ impl Element for TerminalEl {
|
||||||
terminal_theme.colors.background.clone()
|
terminal_theme.colors.background.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let (cursor, cells, rects, highlights, display_offset) = self
|
let (cells, selection, cursor, display_offset, cursor_text) = self
|
||||||
.terminal
|
.terminal
|
||||||
.upgrade(cx)
|
.upgrade(cx)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.update(cx.app, |terminal, mcx| {
|
.update(cx.app, |terminal, mcx| {
|
||||||
terminal.set_size(dimensions);
|
terminal.set_size(dimensions);
|
||||||
terminal.render_lock(mcx, |content, cursor_text| {
|
terminal.render_lock(mcx, |content, cursor_text| {
|
||||||
|
let mut cells = vec![];
|
||||||
|
cells.extend(content.display_iter.map(|ic| IndexedCell {
|
||||||
|
point: ic.point.clone(),
|
||||||
|
cell: ic.cell.clone(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
(
|
||||||
|
cells,
|
||||||
|
content.selection.clone(),
|
||||||
|
content.cursor.clone(),
|
||||||
|
content.display_offset.clone(),
|
||||||
|
cursor_text.clone(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
let (cells, rects, highlights) = TerminalEl::layout_grid(
|
let (cells, rects, highlights) = TerminalEl::layout_grid(
|
||||||
content.display_iter,
|
cells,
|
||||||
&text_style,
|
&text_style,
|
||||||
&terminal_theme,
|
&terminal_theme,
|
||||||
cx.text_layout_cache,
|
cx.text_layout_cache,
|
||||||
self.modal,
|
self.modal,
|
||||||
content.selection,
|
selection,
|
||||||
);
|
);
|
||||||
|
|
||||||
//Layout cursor
|
//Layout cursor
|
||||||
let cursor = {
|
let cursor = {
|
||||||
let cursor_point =
|
let cursor_point = DisplayCursor::from(cursor.point, display_offset);
|
||||||
DisplayCursor::from(content.cursor.point, content.display_offset);
|
|
||||||
let cursor_text = {
|
let cursor_text = {
|
||||||
let str_trxt = cursor_text.to_string();
|
let str_trxt = cursor_text.to_string();
|
||||||
cx.text_layout_cache.layout_str(
|
cx.text_layout_cache.layout_str(
|
||||||
|
@ -582,10 +614,6 @@ impl Element for TerminalEl {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
(cursor, cells, rects, highlights, content.display_offset)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
//Done!
|
//Done!
|
||||||
(
|
(
|
||||||
constraint.max,
|
constraint.max,
|
||||||
|
|
Loading…
Reference in a new issue