Fix cursor bold and italic rendering (#1136)

* Fix cursor bold and italic rendering

* Rename character to grid cell

* Rename character -> grid_cell in Cursor struct

* Rename get_cursor_character -> get_cursor_grid_cell
macos-click-through
Eric Pfister 3 years ago committed by GitHub
parent 224f1f2083
commit f5bb8cc89b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,8 @@ use skia_safe::Color4f;
use crate::editor::style::{Colors, Style}; use crate::editor::style::{Colors, Style};
use super::grid::GridCell;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum CursorShape { pub enum CursorShape {
Block, Block,
@ -44,7 +46,7 @@ pub struct Cursor {
pub style: Option<Arc<Style>>, pub style: Option<Arc<Style>>,
pub enabled: bool, pub enabled: bool,
pub double_width: bool, pub double_width: bool,
pub character: String, pub grid_cell: GridCell,
} }
impl Cursor { impl Cursor {
@ -60,7 +62,7 @@ impl Cursor {
blinkoff: None, blinkoff: None,
enabled: true, enabled: true,
double_width: false, double_width: false,
character: " ".to_string(), grid_cell: (" ".to_string(), None),
} }
} }

@ -387,12 +387,12 @@ impl Editor {
fn send_cursor_info(&mut self) { fn send_cursor_info(&mut self) {
let (grid_left, grid_top) = self.cursor.grid_position; let (grid_left, grid_top) = self.cursor.grid_position;
if let Some(window) = self.windows.get(&self.cursor.parent_window_id) { if let Some(window) = self.windows.get(&self.cursor.parent_window_id) {
let (character, double_width) = window.get_cursor_character(grid_left, grid_top); let (character, style, double_width) = window.get_cursor_grid_cell(grid_left, grid_top);
self.cursor.character = character; self.cursor.grid_cell = (character, style);
self.cursor.double_width = double_width; self.cursor.double_width = double_width;
} else { } else {
self.cursor.double_width = false; self.cursor.double_width = false;
self.cursor.character = " ".to_string(); self.cursor.grid_cell = (" ".to_string(), None);
} }
self.draw_command_batcher self.draw_command_batcher
.queue(DrawCommand::UpdateCursor(self.cursor.clone())) .queue(DrawCommand::UpdateCursor(self.cursor.clone()))

@ -63,10 +63,14 @@ impl Window {
}); });
} }
pub fn get_cursor_character(&self, window_left: u64, window_top: u64) -> (String, bool) { pub fn get_cursor_grid_cell(
let character = match self.grid.get_cell(window_left, window_top) { &self,
Some((character, _)) => character.clone(), window_left: u64,
_ => ' '.to_string(), window_top: u64,
) -> (String, Option<Arc<Style>>, bool) {
let grid_cell = match self.grid.get_cell(window_left, window_top) {
Some((character, style)) => (character.clone(), style.clone()),
_ => (' '.to_string(), None),
}; };
let double_width = match self.grid.get_cell(window_left + 1, window_top) { let double_width = match self.grid.get_cell(window_left + 1, window_top) {
@ -74,7 +78,7 @@ impl Window {
_ => false, _ => false,
}; };
(character, double_width) (grid_cell.0, grid_cell.1, double_width)
} }
pub fn get_width(&self) -> u64 { pub fn get_width(&self) -> u64 {

@ -273,7 +273,7 @@ impl CursorRenderer {
let mut paint = Paint::new(skia_safe::colors::WHITE, None); let mut paint = Paint::new(skia_safe::colors::WHITE, None);
paint.set_anti_alias(settings.antialiasing); paint.set_anti_alias(settings.antialiasing);
let character = self.cursor.character.clone(); let character = self.cursor.grid_cell.0.clone();
let mut cursor_width = grid_renderer.font_dimensions.width; let mut cursor_width = grid_renderer.font_dimensions.width;
if self.cursor.double_width && self.cursor.shape == CursorShape::Block { if self.cursor.double_width && self.cursor.shape == CursorShape::Block {
@ -341,7 +341,9 @@ impl CursorRenderer {
self.previous_editor_mode = current_mode.clone(); self.previous_editor_mode = current_mode.clone();
} }
if self.cursor.enabled && render { if !(self.cursor.enabled && render) {
return;
}
// Draw Background // Draw Background
let background_color = self let background_color = self
.cursor .cursor
@ -372,7 +374,12 @@ impl CursorRenderer {
canvas.clip_path(&path, None, Some(false)); canvas.clip_path(&path, None, Some(false));
let y_adjustment = grid_renderer.shaper.y_adjustment(); let y_adjustment = grid_renderer.shaper.y_adjustment();
let blobs = &grid_renderer.shaper.shape_cached(character, false, false); let style = &self.cursor.grid_cell.1;
let bold = style.as_ref().map(|x| x.bold).unwrap_or(false);
let italic = style.as_ref().map(|x| x.italic).unwrap_or(false);
let blobs = &grid_renderer.shaper.shape_cached(character, bold, italic);
for blob in blobs.iter() { for blob in blobs.iter() {
canvas.draw_text_blob( canvas.draw_text_blob(
@ -388,5 +395,4 @@ impl CursorRenderer {
vfx.render(&settings, canvas, grid_renderer, &self.cursor); vfx.render(&settings, canvas, grid_renderer, &self.cursor);
} }
} }
}
} }

Loading…
Cancel
Save