chore: update gpui & components
This commit is contained in:
@@ -3,8 +3,8 @@ use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
fill, point, px, relative, size, App, Bounds, Corners, Element, ElementId, ElementInputHandler,
|
||||
Entity, GlobalElementId, Half, Hitbox, IntoElement, LayoutId, MouseButton, MouseMoveEvent,
|
||||
Path, Pixels, Point, ShapedLine, SharedString, Size, Style, TextAlign, TextRun, UnderlineStyle,
|
||||
Entity, GlobalElementId, Hitbox, IntoElement, LayoutId, MouseButton, MouseMoveEvent, Path,
|
||||
Pixels, Point, ShapedLine, SharedString, Size, Style, TextAlign, TextRun, UnderlineStyle,
|
||||
Window,
|
||||
};
|
||||
use rope::Rope;
|
||||
@@ -642,11 +642,8 @@ impl Element for TextElement {
|
||||
}
|
||||
|
||||
let total_wrapped_lines = state.text_wrapper.len();
|
||||
let empty_bottom_height = bounds
|
||||
.size
|
||||
.height
|
||||
.half()
|
||||
.max(BOTTOM_MARGIN_ROWS * line_height);
|
||||
let empty_bottom_height = px(0.);
|
||||
|
||||
let scroll_size = size(
|
||||
if longest_line_width + line_number_width + RIGHT_MARGIN > bounds.size.width {
|
||||
longest_line_width + line_number_width + RIGHT_MARGIN
|
||||
@@ -872,9 +869,7 @@ impl Element for TextElement {
|
||||
state.set_input_bounds(input_bounds, cx);
|
||||
state.last_selected_range = Some(selected_range);
|
||||
state.scroll_size = prepaint.scroll_size;
|
||||
state
|
||||
.scroll_handle
|
||||
.set_offset(prepaint.cursor_scroll_offset);
|
||||
state.update_scroll_offset(Some(prepaint.cursor_scroll_offset), cx);
|
||||
state.deferred_scroll_offset = None;
|
||||
|
||||
cx.notify();
|
||||
|
||||
@@ -1411,7 +1411,11 @@ impl InputState {
|
||||
self.update_scroll_offset(Some(self.scroll_handle.offset() + delta), cx);
|
||||
}
|
||||
|
||||
fn update_scroll_offset(&mut self, offset: Option<Point<Pixels>>, cx: &mut Context<Self>) {
|
||||
pub(super) fn update_scroll_offset(
|
||||
&mut self,
|
||||
offset: Option<Point<Pixels>>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let mut offset = offset.unwrap_or(self.scroll_handle.offset());
|
||||
|
||||
let safe_y_range =
|
||||
@@ -1472,13 +1476,12 @@ impl InputState {
|
||||
|
||||
// Check if row_offset_y is out of the viewport
|
||||
// If row offset is not in the viewport, scroll to make it visible
|
||||
let edge_height = 3 * line_height;
|
||||
if row_offset_y - edge_height < -scroll_offset.y {
|
||||
if row_offset_y - line_height < -scroll_offset.y {
|
||||
// Scroll up
|
||||
scroll_offset.y = -row_offset_y + edge_height;
|
||||
} else if row_offset_y + edge_height > -scroll_offset.y + bounds.size.height {
|
||||
scroll_offset.y = -row_offset_y + line_height;
|
||||
} else if row_offset_y + line_height > -scroll_offset.y + bounds.size.height {
|
||||
// Scroll down
|
||||
scroll_offset.y = -(row_offset_y - bounds.size.height + edge_height);
|
||||
scroll_offset.y = -(row_offset_y - bounds.size.height + line_height);
|
||||
}
|
||||
|
||||
scroll_offset.x = scroll_offset.x.min(px(0.));
|
||||
|
||||
@@ -150,6 +150,7 @@ impl RenderOnce for TextInput {
|
||||
|
||||
self.state.update(cx, |state, cx| {
|
||||
state.text_wrapper.set_font(font, font_size, cx);
|
||||
state.text_wrapper.prepare_if_need(&state.text, cx);
|
||||
state.disabled = self.disabled;
|
||||
});
|
||||
|
||||
|
||||
@@ -42,14 +42,19 @@ impl LineItem {
|
||||
/// After use lines to calculate the scroll size of the Editor.
|
||||
pub(super) struct TextWrapper {
|
||||
text: Rope,
|
||||
|
||||
/// Total wrapped lines (Inlucde the first line), value is start and end index of the line.
|
||||
soft_lines: usize,
|
||||
font: Font,
|
||||
font_size: Pixels,
|
||||
|
||||
/// If is none, it means the text is not wrapped
|
||||
wrap_width: Option<Pixels>,
|
||||
|
||||
/// The lines by split \n
|
||||
pub(super) lines: Vec<LineItem>,
|
||||
|
||||
_initialized: bool,
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
@@ -62,6 +67,7 @@ impl TextWrapper {
|
||||
wrap_width,
|
||||
soft_lines: 0,
|
||||
lines: Vec::new(),
|
||||
_initialized: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +92,6 @@ impl TextWrapper {
|
||||
if wrap_width == self.wrap_width {
|
||||
return;
|
||||
}
|
||||
|
||||
self.wrap_width = wrap_width;
|
||||
self.update_all(&self.text.clone(), true, cx);
|
||||
}
|
||||
@@ -95,12 +100,19 @@ impl TextWrapper {
|
||||
if self.font.eq(&font) && self.font_size == font_size {
|
||||
return;
|
||||
}
|
||||
|
||||
self.font = font;
|
||||
self.font_size = font_size;
|
||||
self.update_all(&self.text.clone(), true, cx);
|
||||
}
|
||||
|
||||
pub(super) fn prepare_if_need(&mut self, text: &Rope, cx: &mut App) {
|
||||
if self._initialized {
|
||||
return;
|
||||
}
|
||||
self._initialized = true;
|
||||
self.update_all(text, true, cx);
|
||||
}
|
||||
|
||||
/// Update the text wrapper and recalculate the wrapped lines.
|
||||
///
|
||||
/// If the `text` is the same as the current text, do nothing.
|
||||
|
||||
Reference in New Issue
Block a user