Compare commits

...

1 Commits

Author SHA1 Message Date
Bennet Bo Fenner
1cbd9b5a7a edit prediction: Ensure that the cursor is always visible during jump animation 2025-02-11 18:12:01 +01:00
3 changed files with 38 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
use crate::EditorSettings;
use gpui::Context;
use gpui::Task;
use settings::Settings;
use settings::SettingsStore;
use smol::Timer;
@@ -12,6 +13,7 @@ pub struct BlinkManager {
blinking_paused: bool,
visible: bool,
enabled: bool,
blink_task: Option<Task<()>>,
}
impl BlinkManager {
@@ -29,6 +31,7 @@ impl BlinkManager {
blinking_paused: false,
visible: true,
enabled: false,
blink_task: None,
}
}
@@ -49,6 +52,13 @@ impl BlinkManager {
.detach();
}
pub fn reset_blinking(&mut self, cx: &mut Context<Self>) {
self.visible = true;
self.blink_task = None;
self.start_blink_task(cx);
cx.notify();
}
fn resume_cursor_blinking(&mut self, epoch: usize, cx: &mut Context<Self>) {
if epoch == self.blink_epoch {
self.blinking_paused = false;
@@ -61,17 +71,9 @@ impl BlinkManager {
if epoch == self.blink_epoch && self.enabled && !self.blinking_paused {
self.visible = !self.visible;
cx.notify();
let epoch = self.next_blink_epoch();
let interval = self.blink_interval;
cx.spawn(|this, mut cx| async move {
Timer::after(interval).await;
if let Some(this) = this.upgrade() {
this.update(&mut cx, |this, cx| this.blink_cursors(epoch, cx))
.ok();
}
})
.detach();
if self.blink_task.is_none() {
self.start_blink_task(cx);
}
}
} else {
self.show_cursor(cx);
@@ -105,4 +107,19 @@ impl BlinkManager {
pub fn visible(&self) -> bool {
self.visible
}
fn start_blink_task(&mut self, cx: &mut Context<Self>) {
let epoch = self.next_blink_epoch();
let interval = self.blink_interval;
self.blink_task = Some(cx.spawn(|this, mut cx| async move {
cx.background_executor().timer(interval).await;
if let Some(this) = this.upgrade() {
this.update(&mut cx, |this, cx| {
this.blink_task = None;
this.blink_cursors(epoch, cx);
})
.ok();
}
}));
}
}

View File

@@ -725,6 +725,8 @@ impl EditPredictionPreview {
line_height: Pixels,
target: Anchor,
cursor: Option<DisplayPoint>,
blink_manager: Entity<BlinkManager>,
cx: &mut App,
) -> Option<EditPredictionMoveState> {
let delta = match self {
Self::Inactive => return None,
@@ -751,6 +753,7 @@ impl EditPredictionPreview {
let now = Instant::now();
if animation.end < now {
*self = Self::Inactive;
blink_manager.update(cx, BlinkManager::reset_blinking);
return None;
} else {
let delta = (now - animation.start).as_secs_f32()

View File

@@ -1,5 +1,6 @@
use crate::{
blame_entry_tooltip::{blame_entry_relative_timestamp, BlameEntryTooltip},
blink_manager::BlinkManager,
code_context_menus::{CodeActionsMenu, MENU_ASIDE_MAX_WIDTH, MENU_ASIDE_MIN_WIDTH, MENU_GAP},
display_map::{
Block, BlockContext, BlockStyle, DisplaySnapshot, HighlightedChunk, ToDisplayPoint,
@@ -1124,6 +1125,8 @@ impl EditorElement {
let cursor_layouts = self.editor.update(cx, |editor, cx| {
let mut cursors = Vec::new();
let blink_manager = editor.blink_manager.clone();
let previewing_move =
if let Some((target, preview)) = editor.previewing_edit_prediction_move() {
cursors.extend(self.layout_edit_prediction_preview_cursor(
@@ -1137,6 +1140,7 @@ impl EditorElement {
preview,
target,
newest_selection_head,
blink_manager,
window,
cx,
));
@@ -1301,6 +1305,7 @@ impl EditorElement {
preview: &mut EditPredictionPreview,
target: Anchor,
cursor: Option<DisplayPoint>,
blink_manager: Entity<BlinkManager>,
window: &mut Window,
cx: &mut App,
) -> Option<CursorLayout> {
@@ -1312,6 +1317,8 @@ impl EditorElement {
line_height,
target,
cursor,
blink_manager,
cx,
)?;
if !state.is_animation_completed() {