terminal_view: Reuse editor's blink manager (#43351)
Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -1,20 +1,28 @@
|
||||
use crate::EditorSettings;
|
||||
use gpui::Context;
|
||||
use settings::Settings;
|
||||
use settings::SettingsStore;
|
||||
use smol::Timer;
|
||||
use std::time::Duration;
|
||||
use ui::App;
|
||||
|
||||
pub struct BlinkManager {
|
||||
blink_interval: Duration,
|
||||
blink_epoch: usize,
|
||||
/// Whether the blinking is paused.
|
||||
blinking_paused: bool,
|
||||
/// Whether the cursor should be visibly rendered or not.
|
||||
visible: bool,
|
||||
/// Whether the blinking currently enabled.
|
||||
enabled: bool,
|
||||
/// Whether the blinking is enabled in the settings.
|
||||
blink_enabled_in_settings: fn(&App) -> bool,
|
||||
}
|
||||
|
||||
impl BlinkManager {
|
||||
pub fn new(blink_interval: Duration, cx: &mut Context<Self>) -> Self {
|
||||
pub fn new(
|
||||
blink_interval: Duration,
|
||||
blink_enabled_in_settings: fn(&App) -> bool,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
// Make sure we blink the cursors if the setting is re-enabled
|
||||
cx.observe_global::<SettingsStore>(move |this, cx| {
|
||||
this.blink_cursors(this.blink_epoch, cx)
|
||||
@@ -27,6 +35,7 @@ impl BlinkManager {
|
||||
blinking_paused: false,
|
||||
visible: true,
|
||||
enabled: false,
|
||||
blink_enabled_in_settings,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +64,7 @@ impl BlinkManager {
|
||||
}
|
||||
|
||||
fn blink_cursors(&mut self, epoch: usize, cx: &mut Context<Self>) {
|
||||
if EditorSettings::get_global(cx).cursor_blink {
|
||||
if (self.blink_enabled_in_settings)(cx) {
|
||||
if epoch == self.blink_epoch && self.enabled && !self.blinking_paused {
|
||||
self.visible = !self.visible;
|
||||
cx.notify();
|
||||
@@ -83,6 +92,7 @@ impl BlinkManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Enable the blinking of the cursor.
|
||||
pub fn enable(&mut self, cx: &mut Context<Self>) {
|
||||
if self.enabled {
|
||||
return;
|
||||
@@ -95,6 +105,7 @@ impl BlinkManager {
|
||||
self.blink_cursors(self.blink_epoch, cx);
|
||||
}
|
||||
|
||||
/// Disable the blinking of the cursor.
|
||||
pub fn disable(&mut self, _cx: &mut Context<Self>) {
|
||||
self.visible = false;
|
||||
self.enabled = false;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
//!
|
||||
//! If you're looking to improve Vim mode, you should check out Vim crate that wraps Editor and overrides its behavior.
|
||||
pub mod actions;
|
||||
mod blink_manager;
|
||||
pub mod blink_manager;
|
||||
mod bracket_colorization;
|
||||
mod clangd_ext;
|
||||
pub mod code_context_menus;
|
||||
@@ -1888,7 +1888,11 @@ impl Editor {
|
||||
let selections = SelectionsCollection::new();
|
||||
|
||||
let blink_manager = cx.new(|cx| {
|
||||
let mut blink_manager = BlinkManager::new(CURSOR_BLINK_INTERVAL, cx);
|
||||
let mut blink_manager = BlinkManager::new(
|
||||
CURSOR_BLINK_INTERVAL,
|
||||
|cx| EditorSettings::get_global(cx).cursor_blink,
|
||||
cx,
|
||||
);
|
||||
if is_minimap {
|
||||
blink_manager.disable(cx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user