added disable cursor animation in insert mode

current approach to disable cursor animation during typing relied on a hack, now it’s an option <animate_in_insert_mode> (default to true) whether to use cursor animations in insert mode
macos-click-through
exoticus 5 years ago
parent 3da11e09d8
commit cc783adeb4

@ -39,6 +39,7 @@ pub struct Editor {
pub default_style: Arc<Style>, pub default_style: Arc<Style>,
pub defined_styles: HashMap<u64, Arc<Style>>, pub defined_styles: HashMap<u64, Arc<Style>>,
pub previous_style: Option<Arc<Style>>, pub previous_style: Option<Arc<Style>>,
pub mode: u64,
} }
impl Editor { impl Editor {
@ -57,6 +58,7 @@ impl Editor {
))), ))),
defined_styles: HashMap::new(), defined_styles: HashMap::new(),
previous_style: None, previous_style: None,
mode: 0,
}; };
editor.grid.clear(); editor.grid.clear();
@ -69,6 +71,7 @@ impl Editor {
RedrawEvent::ModeInfoSet { cursor_modes } => self.cursor.mode_list = cursor_modes, RedrawEvent::ModeInfoSet { cursor_modes } => self.cursor.mode_list = cursor_modes,
RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option), RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option),
RedrawEvent::ModeChange { mode_index } => { RedrawEvent::ModeChange { mode_index } => {
self.mode = mode_index;
self.cursor.change_mode(mode_index, &self.defined_styles) self.cursor.change_mode(mode_index, &self.defined_styles)
} }
RedrawEvent::MouseOn => { RedrawEvent::MouseOn => {

@ -23,6 +23,7 @@ const STANDARD_CORNERS: &[(f32, f32); 4] = &[(-0.5, -0.5), (0.5, -0.5), (0.5, 0.
pub struct CursorSettings { pub struct CursorSettings {
antialiasing: bool, antialiasing: bool,
animation_length: f32, animation_length: f32,
animate_in_insert_mode: bool,
trail_size: f32, trail_size: f32,
vfx_mode: cursor_vfx::VfxMode, vfx_mode: cursor_vfx::VfxMode,
vfx_opacity: f32, vfx_opacity: f32,
@ -37,6 +38,7 @@ pub fn initialize_settings() {
SETTINGS.set(&CursorSettings { SETTINGS.set(&CursorSettings {
antialiasing: true, antialiasing: true,
animation_length: 0.13, animation_length: 0.13,
animate_in_insert_mode: true,
trail_size: 0.7, trail_size: 0.7,
vfx_mode: cursor_vfx::VfxMode::Disabled, vfx_mode: cursor_vfx::VfxMode::Disabled,
vfx_opacity: 200.0, vfx_opacity: 200.0,
@ -48,6 +50,10 @@ pub fn initialize_settings() {
}); });
register_nvim_setting!("cursor_antialiasing", CursorSettings::antialiasing); register_nvim_setting!("cursor_antialiasing", CursorSettings::antialiasing);
register_nvim_setting!(
"cursor_animate_in_insert_mode",
CursorSettings::animate_in_insert_mode
);
register_nvim_setting!("cursor_animation_length", CursorSettings::animation_length); register_nvim_setting!("cursor_animation_length", CursorSettings::animation_length);
register_nvim_setting!("cursor_trail_size", CursorSettings::trail_size); register_nvim_setting!("cursor_trail_size", CursorSettings::trail_size);
register_nvim_setting!("cursor_vfx_mode", CursorSettings::vfx_mode); register_nvim_setting!("cursor_vfx_mode", CursorSettings::vfx_mode);
@ -102,17 +108,15 @@ impl Corner {
font_dimensions: Point, font_dimensions: Point,
destination: Point, destination: Point,
dt: f32, dt: f32,
mode: u64,
) -> bool { ) -> bool {
// Update destination if needed // Update destination if needed
let mut immediate_movement = false; let mut immediate_movement = false;
if destination != self.previous_destination { if destination != self.previous_destination {
let travel_distance = destination - self.previous_destination; // 2 for insert mode as it's the only mode where
let chars_travel_x = travel_distance.x / font_dimensions.x; // the cursor might appear to lag behind
if !settings.animate_in_insert_mode && mode == 2 {
if travel_distance.y == 0.0 && (chars_travel_x - 1.0).abs() < 0.1 {
// We're moving one character to the right. Make movement immediate to avoid lag
// while typing
immediate_movement = true; immediate_movement = true;
} }
@ -272,7 +276,7 @@ impl CursorRenderer {
}; };
let (grid_x, grid_y) = self.previous_position; let (grid_x, grid_y) = self.previous_position;
let (character, font_dimensions): (String, Point) = { let (character, font_dimensions, mode): (String, Point, u64) = {
let editor = EDITOR.lock(); let editor = EDITOR.lock();
let character = match editor.grid.get_cell(grid_x, grid_y) { let character = match editor.grid.get_cell(grid_x, grid_y) {
Some(Some((character, _))) => character.clone(), Some(Some((character, _))) => character.clone(),
@ -288,7 +292,8 @@ impl CursorRenderer {
(true, CursorShape::Block) => font_width * 2.0, (true, CursorShape::Block) => font_width * 2.0,
_ => font_width, _ => font_width,
}; };
(character, (font_width, font_height).into())
(character, (font_width, font_height).into(), editor.mode)
}; };
let destination: Point = (grid_x as f32 * font_width, grid_y as f32 * font_height).into(); let destination: Point = (grid_x as f32 * font_width, grid_y as f32 * font_height).into();
@ -312,7 +317,8 @@ impl CursorRenderer {
if !center_destination.is_zero() { if !center_destination.is_zero() {
for corner in self.corners.iter_mut() { for corner in self.corners.iter_mut() {
let corner_animating = let corner_animating =
corner.update(&settings, font_dimensions, center_destination, dt); corner.update(&settings, font_dimensions, center_destination, dt, mode);
animating |= corner_animating; animating |= corner_animating;
} }

Loading…
Cancel
Save