resolve clippy issues and fix cursor character issue

macos-click-through
Keith Simmons 5 years ago
parent c562c78fcd
commit a1ad41247d

@ -91,7 +91,7 @@ async fn start_process(editor: Arc<Mutex<Editor>>, mut receiver: UnboundedReceiv
} }
pub struct Bridge { pub struct Bridge {
runtime: Runtime, _runtime: Runtime,
sender: UnboundedSender<UiCommand> sender: UnboundedSender<UiCommand>
} }
@ -104,10 +104,13 @@ impl Bridge {
start_process(editor, receiver, grid_dimensions).await; start_process(editor, receiver, grid_dimensions).await;
}); });
Bridge { runtime, sender } Bridge { _runtime: runtime, sender }
} }
pub fn queue_command(&mut self, command: UiCommand) { pub fn queue_command(&mut self, command: UiCommand) {
self.sender.send(command); self.sender.send(command)
.unwrap_or_explained_panic(
"Could Not Send UI Command",
"Could not send UI command from the window system to the neovim process.");
} }
} }

@ -1,5 +1,3 @@
use std::sync::Arc;
use nvim_rs::Neovim; use nvim_rs::Neovim;
use nvim_rs::compat::tokio::Compat; use nvim_rs::compat::tokio::Compat;
use tokio::process::ChildStdin; use tokio::process::ChildStdin;

@ -1,109 +0,0 @@
use std::collections::HashMap;
use crate::bridge::{RedrawEvent, StyledContent};
use crate::editor::{DrawCommand, Style};
const COMMAND_SCALE: u16 = 2;
pub struct CommandLine {
visible: bool,
prefix: String,
content: StyledContent,
cursor_position: u64,
special_char: Option<(String, bool)>,
block: Vec<StyledContent>
}
impl CommandLine {
pub fn new() -> CommandLine {
CommandLine {
visible: false,
prefix: String::new(),
content: Vec::new(),
cursor_position: 0,
special_char: None,
block: Vec::new()
}
}
pub fn draw(&self, window_size: (u64, u64), defined_styles: &HashMap<u64, Style>) -> Vec<DrawCommand> {
let mut draw_commands = Vec::new();
if self.visible {
if self.content.len() > 0 {
let (width, height) = window_size;
let text_length: usize = self.content.iter().map(|(_, text)| text.len()).sum();
let text_width = text_length * COMMAND_SCALE as usize;
let text_height = COMMAND_SCALE;
let x = (width / 2) - (text_width as u64 / 2);
let y = (height / 2) - (text_height as u64 / 2);
let mut start_x = x;
let mut commands = self.content.iter().map(|(style_id, text)| {
let command_width = text.len() * 2;
let style = defined_styles.get(style_id).map(|style| style.clone());
let mut command = DrawCommand::new(text.clone(), (start_x, y), style);
command.scale = COMMAND_SCALE;
start_x = start_x + command_width as u64;
command
}).collect::<Vec<DrawCommand>>();
draw_commands.append(&mut commands);
}
}
draw_commands
}
pub fn handle_command_events(&mut self, event: RedrawEvent) {
match event {
RedrawEvent::CommandLineShow { content, position, first_character, prompt, indent, level } => self.show(content, position, first_character, prompt, indent, level),
RedrawEvent::CommandLinePosition { position, level } => self.set_position(position, level),
RedrawEvent::CommandLineSpecialCharacter { character, shift, level } => self.set_special_character(character, shift, level),
RedrawEvent::CommandLineHide => self.hide(),
RedrawEvent::CommandLineBlockShow { lines } => self.show_block(lines),
RedrawEvent::CommandLineBlockAppend { line } => self.append_line_to_block(line),
RedrawEvent::CommandLineBlockHide => self.hide_block(),
_ => {}
}
}
fn show(&mut self, content: StyledContent, position: u64, first_character: String, prompt: String, _indent: u64, _level: u64) {
let prefix;
if first_character.len() > 0 {
prefix = first_character;
} else {
prefix = prompt;
}
self.visible = true;
self.prefix = prefix;
self.content = content;
self.cursor_position = position;
self.block = Vec::new();
}
fn set_position(&mut self, position: u64, _level: u64) {
self.cursor_position = position;
}
fn set_special_character(&mut self, character: String, shift: bool, _level: u64) {
self.special_char = Some((character, shift));
}
fn hide(&mut self) {
self.visible = false;
self.special_char = None;
}
fn show_block(&mut self, lines: Vec<StyledContent>) {
self.block = lines;
}
fn append_line_to_block(&mut self, line: StyledContent) {
self.block.push(line);
}
fn hide_block(&mut self) {
self.block.clear();
}
}

@ -1,6 +1,5 @@
mod cursor; mod cursor;
mod style; mod style;
mod command_line;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
@ -10,7 +9,6 @@ use skulpin::winit::window::Window;
pub use cursor::{Cursor, CursorShape, CursorMode}; pub use cursor::{Cursor, CursorShape, CursorMode};
pub use style::{Colors, Style}; pub use style::{Colors, Style};
use command_line::CommandLine;
use crate::bridge::{GridLineCell, GuiOption, RedrawEvent}; use crate::bridge::{GridLineCell, GuiOption, RedrawEvent};
pub type GridCell = Option<(char, Option<Style>)>; pub type GridCell = Option<(char, Option<Style>)>;
@ -24,20 +22,6 @@ pub struct DrawCommand {
pub scale: u16 pub scale: u16
} }
impl DrawCommand {
pub fn set_coverage(&self, dirty: &mut Vec<Vec<bool>>) {
let (left, top) = self.grid_position;
let text_width = self.text.chars().count() * self.scale as usize;
for y in top..(top + self.scale as u64 - 1) {
let row = &mut dirty[y as usize];
for x in left..(left + text_width as u64 - 1) {
row[x as usize] = true;
}
}
}
}
pub struct Editor { pub struct Editor {
pub grid: Vec<Vec<GridCell>>, pub grid: Vec<Vec<GridCell>>,
pub dirty: Vec<Vec<bool>>, pub dirty: Vec<Vec<bool>>,
@ -45,7 +29,6 @@ pub struct Editor {
pub window: Option<Arc<Window>>, pub window: Option<Arc<Window>>,
pub command_line: CommandLine,
pub title: String, pub title: String,
pub size: (u64, u64), pub size: (u64, u64),
pub font_name: Option<String>, pub font_name: Option<String>,
@ -65,7 +48,6 @@ impl Editor {
window: None, window: None,
command_line: CommandLine::new(),
title: "Neovide".to_string(), title: "Neovide".to_string(),
cursor: Cursor::new(), cursor: Cursor::new(),
size: dimensions, size: dimensions,
@ -96,7 +78,7 @@ impl Editor {
RedrawEvent::Clear { .. } => self.clear(), RedrawEvent::Clear { .. } => self.clear(),
RedrawEvent::CursorGoto { row, column, .. } => self.cursor.position = (row, column), RedrawEvent::CursorGoto { row, column, .. } => self.cursor.position = (row, column),
RedrawEvent::Scroll { top, bottom, left, right, rows, columns, .. } => self.scroll_region(top, bottom, left, right, rows, columns), RedrawEvent::Scroll { top, bottom, left, right, rows, columns, .. } => self.scroll_region(top, bottom, left, right, rows, columns),
event => self.command_line.handle_command_events(event) _ => {}
}; };
} }
@ -139,7 +121,7 @@ impl Editor {
} }
let should_clear = self.should_clear; let should_clear = self.should_clear;
let mut draw_commands = draw_commands.into_iter().filter(|command| { let draw_commands = draw_commands.into_iter().filter(|command| {
let (x, y) = command.grid_position; let (x, y) = command.grid_position;
let dirty_row = &self.dirty[y as usize]; let dirty_row = &self.dirty[y as usize];
@ -151,12 +133,6 @@ impl Editor {
return false; return false;
}).collect::<Vec<DrawCommand>>(); }).collect::<Vec<DrawCommand>>();
let mut command_line_draw_commands = self.command_line.draw(self.size, &self.defined_styles);
for command_line_draw_command in command_line_draw_commands.iter() {
command_line_draw_command.set_coverage(&mut self.dirty);
}
draw_commands.append(&mut command_line_draw_commands);
let (width, height) = self.size; let (width, height) = self.size;
self.dirty = vec![vec![false; width as usize]; height as usize]; self.dirty = vec![vec![false; width as usize]; height as usize];
self.should_clear = false; self.should_clear = false;

@ -1,17 +1,13 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc;
use lru::LruCache; use lru::LruCache;
use skulpin::skia_safe::{TextBlob, Font, Point, TextBlobBuilder}; use skulpin::skia_safe::{TextBlob, Font, TextBlobBuilder};
use font_kit::source::SystemSource; use font_kit::source::SystemSource;
use skribo::{ use skribo::{layout_run, FontRef, TextStyle};
layout, layout_run, make_layout, FontCollection, FontFamily, FontRef, Layout, LayoutSession,
TextStyle
};
use super::fonts::FontLookup; use super::fonts::FontLookup;
const standard_character_string: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; const STANDARD_CHARACTER_STRING: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
#[derive(new, Clone, Hash, PartialEq, Eq)] #[derive(new, Clone, Hash, PartialEq, Eq)]
struct FontKey { struct FontKey {
@ -107,7 +103,7 @@ impl CachingShaper {
let font_key = FontKey::new(font_lookup.name.to_string(), font_lookup.base_size.to_string(), 1, false, false); let font_key = FontKey::new(font_lookup.name.to_string(), font_lookup.base_size.to_string(), 1, false, false);
let font_ref = self.get_font(&font_key); let font_ref = self.get_font(&font_key);
let style = TextStyle { size: font_lookup.base_size }; let style = TextStyle { size: font_lookup.base_size };
let layout = layout_run(&style, font_ref, standard_character_string); let layout = layout_run(&style, font_ref, STANDARD_CHARACTER_STRING);
let glyph_offsets: Vec<f32> = layout.glyphs.iter().map(|glyph| glyph.offset.x).collect(); let glyph_offsets: Vec<f32> = layout.glyphs.iter().map(|glyph| glyph.offset.x).collect();
let glyph_advances: Vec<f32> = glyph_offsets.windows(2).map(|pair| pair[1] - pair[0]).collect(); let glyph_advances: Vec<f32> = glyph_offsets.windows(2).map(|pair| pair[1] - pair[0]).collect();

@ -171,7 +171,7 @@ impl CursorRenderer {
self.previous_position = { self.previous_position = {
let editor = editor.lock().unwrap(); let editor = editor.lock().unwrap();
let (grid_x, grid_y) = cursor.position; let (_, grid_y) = cursor.position;
let (_, previous_y) = self.previous_position; let (_, previous_y) = self.previous_position;
let (_, height) = editor.size; let (_, height) = editor.size;
if grid_y == height - 1 && previous_y != grid_y { if grid_y == height - 1 && previous_y != grid_y {
@ -219,10 +219,9 @@ impl CursorRenderer {
canvas.draw_path(&path, &paint); canvas.draw_path(&path, &paint);
// Draw foreground // Draw foreground
let (cursor_grid_y, cursor_grid_x) = cursor.position;
paint.set_color(cursor.foreground(&default_colors).to_color()); paint.set_color(cursor.foreground(&default_colors).to_color());
let editor = editor.lock().unwrap(); let editor = editor.lock().unwrap();
let character = editor.grid[cursor_grid_x as usize][cursor_grid_y as usize].clone() let character = editor.grid[grid_y as usize][grid_x as usize].clone()
.map(|(character, _)| character) .map(|(character, _)| character)
.unwrap_or(' '); .unwrap_or(' ');
canvas.save(); canvas.save();

@ -1,10 +1,5 @@
use std::collections::HashMap; use std::collections::HashMap;
use skulpin::skia_safe::{GlyphId, Typeface, Font, FontStyle, Paint, Point}; use skulpin::skia_safe::{Typeface, Font, FontStyle};
use font_kit::source::SystemSource;
use skribo::{
layout, layout_run, make_layout, FontCollection, FontFamily, FontRef, Layout, LayoutSession,
TextStyle,
};
use crate::editor::Style; use crate::editor::Style;
pub struct Fonts { pub struct Fonts {

Loading…
Cancel
Save