Merge pull request #697 from FreddyFunk/fix/unfocused-cursor-scroll
fix: hide cursor when scrolled in unfocused terminal
This commit is contained in:
commit
17b830c74c
1 changed files with 65 additions and 56 deletions
|
|
@ -720,66 +720,75 @@ where
|
||||||
state.scrollbar_rect.set(Rectangle::default())
|
state.scrollbar_rect.set(Rectangle::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw cursor
|
// Draw cursor (only when not scrolled, as cursor is at bottom of active area)
|
||||||
{
|
{
|
||||||
let cursor = terminal.term.lock().renderable_content().cursor;
|
let term = terminal.term.lock();
|
||||||
let col = cursor.point.column.0;
|
let display_offset = term.grid().display_offset();
|
||||||
let line = cursor.point.line.0;
|
let cursor = term.renderable_content().cursor;
|
||||||
let color = terminal.term.lock().colors()[NamedColor::Cursor]
|
drop(term);
|
||||||
.or(terminal.colors()[NamedColor::Cursor])
|
|
||||||
.map(|rgb| Color::from_rgb8(rgb.r, rgb.g, rgb.b))
|
// Skip drawing cursor when scrolled - the cursor is below the visible viewport
|
||||||
.unwrap_or(Color::WHITE); // TODO default color from theme?
|
if display_offset > 0 {
|
||||||
let width = terminal.size().cell_width;
|
// Cursor is off-screen when scrolled up
|
||||||
let height = terminal.size().cell_height;
|
} else {
|
||||||
let top_left = view_position
|
let col = cursor.point.column.0;
|
||||||
+ Vector::new((col as f32 * width).floor(), (line as f32 * height).floor());
|
let line = cursor.point.line.0;
|
||||||
match cursor.shape {
|
let color = terminal.term.lock().colors()[NamedColor::Cursor]
|
||||||
CursorShape::Beam => {
|
.or(terminal.colors()[NamedColor::Cursor])
|
||||||
let quad = Quad {
|
.map(|rgb| Color::from_rgb8(rgb.r, rgb.g, rgb.b))
|
||||||
bounds: Rectangle::new(top_left, Size::new(1.0, height)),
|
.unwrap_or(Color::WHITE); // TODO default color from theme?
|
||||||
..Default::default()
|
let width = terminal.size().cell_width;
|
||||||
};
|
let height = terminal.size().cell_height;
|
||||||
renderer.fill_quad(quad, color);
|
let top_left = view_position
|
||||||
}
|
+ Vector::new((col as f32 * width).floor(), (line as f32 * height).floor());
|
||||||
CursorShape::Underline => {
|
match cursor.shape {
|
||||||
let quad = Quad {
|
CursorShape::Beam => {
|
||||||
bounds: Rectangle::new(
|
let quad = Quad {
|
||||||
view_position
|
bounds: Rectangle::new(top_left, Size::new(1.0, height)),
|
||||||
+ Vector::new(
|
|
||||||
(col as f32 * width).floor(),
|
|
||||||
((line + 1) as f32 * height).floor(),
|
|
||||||
),
|
|
||||||
Size::new(width, 1.0),
|
|
||||||
),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
renderer.fill_quad(quad, color);
|
|
||||||
}
|
|
||||||
CursorShape::Block if !state.is_focused => {
|
|
||||||
let quad = Quad {
|
|
||||||
bounds: Rectangle::new(top_left, Size::new(width, height)),
|
|
||||||
border: Border {
|
|
||||||
width: 1.0,
|
|
||||||
color,
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
};
|
||||||
..Default::default()
|
renderer.fill_quad(quad, color);
|
||||||
};
|
}
|
||||||
renderer.fill_quad(quad, Color::TRANSPARENT);
|
CursorShape::Underline => {
|
||||||
}
|
let quad = Quad {
|
||||||
CursorShape::HollowBlock => {
|
bounds: Rectangle::new(
|
||||||
let quad = Quad {
|
view_position
|
||||||
bounds: Rectangle::new(top_left, Size::new(width, height)),
|
+ Vector::new(
|
||||||
border: Border {
|
(col as f32 * width).floor(),
|
||||||
width: 1.0,
|
((line + 1) as f32 * height).floor(),
|
||||||
color,
|
),
|
||||||
|
Size::new(width, 1.0),
|
||||||
|
),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
};
|
||||||
..Default::default()
|
renderer.fill_quad(quad, color);
|
||||||
};
|
}
|
||||||
renderer.fill_quad(quad, Color::TRANSPARENT);
|
CursorShape::Block if !state.is_focused => {
|
||||||
|
let quad = Quad {
|
||||||
|
bounds: Rectangle::new(top_left, Size::new(width, height)),
|
||||||
|
border: Border {
|
||||||
|
width: 1.0,
|
||||||
|
color,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
renderer.fill_quad(quad, Color::TRANSPARENT);
|
||||||
|
}
|
||||||
|
CursorShape::HollowBlock => {
|
||||||
|
let quad = Quad {
|
||||||
|
bounds: Rectangle::new(top_left, Size::new(width, height)),
|
||||||
|
border: Border {
|
||||||
|
width: 1.0,
|
||||||
|
color,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
renderer.fill_quad(quad, Color::TRANSPARENT);
|
||||||
|
}
|
||||||
|
CursorShape::Block | CursorShape::Hidden => {} // Block is handled seperately
|
||||||
}
|
}
|
||||||
CursorShape::Block | CursorShape::Hidden => {} // Block is handled seperately
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue