Fixed a major bug and now use the same cursor paint logic as the editor
This commit is contained in:
parent
64d3dc32d2
commit
ae836e1465
2 changed files with 50 additions and 20 deletions
|
@ -1630,7 +1630,7 @@ impl Default for CursorShape {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Cursor {
|
pub struct Cursor {
|
||||||
origin: Vector2F,
|
origin: Vector2F,
|
||||||
block_width: f32,
|
block_width: f32,
|
||||||
line_height: f32,
|
line_height: f32,
|
||||||
|
@ -1640,7 +1640,25 @@ struct Cursor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cursor {
|
impl Cursor {
|
||||||
fn paint(&self, cx: &mut PaintContext) {
|
pub fn new(
|
||||||
|
origin: Vector2F,
|
||||||
|
block_width: f32,
|
||||||
|
line_height: f32,
|
||||||
|
color: Color,
|
||||||
|
shape: CursorShape,
|
||||||
|
block_text: Option<Line>,
|
||||||
|
) -> Cursor {
|
||||||
|
Cursor {
|
||||||
|
origin,
|
||||||
|
block_width,
|
||||||
|
line_height,
|
||||||
|
color,
|
||||||
|
shape,
|
||||||
|
block_text,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint(&self, cx: &mut PaintContext) {
|
||||||
let bounds = match self.shape {
|
let bounds = match self.shape {
|
||||||
CursorShape::Bar => RectF::new(self.origin, vec2f(2.0, self.line_height)),
|
CursorShape::Bar => RectF::new(self.origin, vec2f(2.0, self.line_height)),
|
||||||
CursorShape::Block => {
|
CursorShape::Block => {
|
||||||
|
|
|
@ -7,11 +7,15 @@ use alacritty_terminal::{
|
||||||
SizeInfo,
|
SizeInfo,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use editor::{Cursor, CursorShape};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
color::Color,
|
color::Color,
|
||||||
elements::*,
|
elements::*,
|
||||||
fonts::{HighlightStyle, TextStyle, Underline},
|
fonts::{HighlightStyle, TextStyle, Underline},
|
||||||
geometry::{rect::RectF, vector::vec2f},
|
geometry::{
|
||||||
|
rect::RectF,
|
||||||
|
vector::{vec2f, Vector2F},
|
||||||
|
},
|
||||||
json::json,
|
json::json,
|
||||||
text_layout::Line,
|
text_layout::Line,
|
||||||
Event, FontCache, MouseRegion, PaintContext, Quad, SizeConstraint, WeakViewHandle,
|
Event, FontCache, MouseRegion, PaintContext, Quad, SizeConstraint, WeakViewHandle,
|
||||||
|
@ -74,7 +78,7 @@ pub struct LayoutState {
|
||||||
lines: Vec<Line>,
|
lines: Vec<Line>,
|
||||||
line_height: LineHeight,
|
line_height: LineHeight,
|
||||||
em_width: CellWidth,
|
em_width: CellWidth,
|
||||||
cursor: Option<(RectF, Color)>,
|
cursor: Option<(Vector2F, Color)>,
|
||||||
cur_size: SizeInfo,
|
cur_size: SizeInfo,
|
||||||
background_color: Color,
|
background_color: Color,
|
||||||
background_rects: Vec<(RectF, Color)>, //Vec index == Line index for the LineSpan
|
background_rects: Vec<(RectF, Color)>, //Vec index == Line index for the LineSpan
|
||||||
|
@ -138,12 +142,11 @@ impl Element for TerminalEl {
|
||||||
.collect();
|
.collect();
|
||||||
let background_rects = make_background_rects(backgrounds, &shaped_lines, &line_height);
|
let background_rects = make_background_rects(backgrounds, &shaped_lines, &line_height);
|
||||||
|
|
||||||
let cursor = make_cursor_rect(
|
let cursor = get_cursor_position(
|
||||||
content.cursor.point,
|
content.cursor.point,
|
||||||
&shaped_lines,
|
&shaped_lines,
|
||||||
content.display_offset,
|
content.display_offset,
|
||||||
&line_height,
|
&line_height,
|
||||||
&cell_width,
|
|
||||||
)
|
)
|
||||||
.map(|cursor_rect| (cursor_rect, terminal_theme.cursor));
|
.map(|cursor_rect| (cursor_rect, terminal_theme.cursor));
|
||||||
|
|
||||||
|
@ -179,6 +182,16 @@ impl Element for TerminalEl {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//TODO: Implement cursor region based styling
|
||||||
|
// cx.scene.push_cursor_region(CursorRegion {
|
||||||
|
// bounds,
|
||||||
|
// style: if !view.link_go_to_definition_state.definitions.is_empty() {
|
||||||
|
// CursorStyle::PointingHand
|
||||||
|
// } else {
|
||||||
|
// CursorStyle::IBeam
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
let origin = bounds.origin() + vec2f(layout.em_width.0, 0.);
|
let origin = bounds.origin() + vec2f(layout.em_width.0, 0.);
|
||||||
|
|
||||||
//Start us off with a nice simple background color
|
//Start us off with a nice simple background color
|
||||||
|
@ -212,13 +225,16 @@ impl Element for TerminalEl {
|
||||||
|
|
||||||
//Draw cursor
|
//Draw cursor
|
||||||
if let Some((c, color)) = layout.cursor {
|
if let Some((c, color)) = layout.cursor {
|
||||||
let new_origin = origin + c.origin();
|
let editor_cursor = Cursor::new(
|
||||||
cx.scene.push_quad(Quad {
|
origin + c,
|
||||||
bounds: RectF::new(new_origin, c.size()),
|
layout.em_width.0,
|
||||||
background: Some(color),
|
layout.line_height.0,
|
||||||
border: Default::default(),
|
color,
|
||||||
corner_radius: 0.,
|
CursorShape::Block,
|
||||||
});
|
None, //TODO fix this
|
||||||
|
);
|
||||||
|
|
||||||
|
editor_cursor.paint(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
@ -374,20 +390,16 @@ fn make_background_rects(
|
||||||
}
|
}
|
||||||
|
|
||||||
///Create the rectangle for a cursor, exactly positioned according to the text
|
///Create the rectangle for a cursor, exactly positioned according to the text
|
||||||
fn make_cursor_rect(
|
fn get_cursor_position(
|
||||||
cursor_point: Point,
|
cursor_point: Point,
|
||||||
shaped_lines: &Vec<Line>,
|
shaped_lines: &Vec<Line>,
|
||||||
display_offset: usize,
|
display_offset: usize,
|
||||||
line_height: &LineHeight,
|
line_height: &LineHeight,
|
||||||
cell_width: &CellWidth,
|
) -> Option<Vector2F> {
|
||||||
) -> Option<RectF> {
|
|
||||||
let cursor_line = cursor_point.line.0 as usize + display_offset;
|
let cursor_line = cursor_point.line.0 as usize + display_offset;
|
||||||
shaped_lines.get(cursor_line).map(|layout_line| {
|
shaped_lines.get(cursor_line).map(|layout_line| {
|
||||||
let cursor_x = layout_line.x_for_index(cursor_point.column.0);
|
let cursor_x = layout_line.x_for_index(cursor_point.column.0);
|
||||||
RectF::new(
|
vec2f(cursor_x, cursor_line as f32 * line_height.0)
|
||||||
vec2f(cursor_x, cursor_line as f32 * line_height.0),
|
|
||||||
vec2f(cell_width.0, line_height.0),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue