From 1268fb9ec8a5a628c291c27400677f73fcd785a2 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Wed, 6 Jul 2022 21:52:20 +0100 Subject: [PATCH] cursor blink when switching window tab --- lapce-ui/src/editor/view.rs | 4 +++- lapce-ui/src/window.rs | 10 ++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lapce-ui/src/editor/view.rs b/lapce-ui/src/editor/view.rs index d517bfae..5371df20 100644 --- a/lapce-ui/src/editor/view.rs +++ b/lapce-ui/src/editor/view.rs @@ -550,6 +550,8 @@ fn event( Event::Command(cmd) if cmd.is(LAPCE_UI_COMMAND) => { let command = cmd.get_unchecked(LAPCE_UI_COMMAND); if let LapceUICommand::Focus = command { + self.cursor_blink_timer = + ctx.request_timer(Duration::from_millis(500), None); self.request_focus(ctx, data, true); let editor_data = data.editor_view_content(self.view_id); self.ensure_cursor_visible( @@ -563,7 +565,7 @@ fn event( } Event::Timer(id) if self.cursor_blink_timer == *id => { ctx.set_handled(); - if data.focus == self.view_id { + if ctx.is_focused() { ctx.request_paint(); self.cursor_blink_timer = ctx.request_timer(Duration::from_millis(500), None); diff --git a/lapce-ui/src/window.rs b/lapce-ui/src/window.rs index 34a1f37d..27e076be 100644 --- a/lapce-ui/src/window.rs +++ b/lapce-ui/src/window.rs @@ -1,9 +1,9 @@ use druid::{ kurbo::Line, widget::{LensWrap, WidgetExt}, - BoxConstraints, Command, Env, Event, EventCtx, InternalEvent, LayoutCtx, - LifeCycle, LifeCycleCtx, PaintCtx, Point, RenderContext, Size, Target, Widget, - WidgetId, WidgetPod, WindowState, + BoxConstraints, Command, Env, Event, EventCtx, LayoutCtx, LifeCycle, + LifeCycleCtx, PaintCtx, Point, RenderContext, Size, Target, Widget, WidgetId, + WidgetPod, WindowState, }; use lapce_data::{ command::{LapceUICommand, LAPCE_UI_COMMAND}, @@ -356,10 +356,8 @@ fn event( | Event::MouseUp(_) | Event::MouseMove(_) | Event::Wheel(_) - | Event::KeyDown(_) - | Event::Timer(_) | Event::AnimFrame(_) - | Event::Internal(InternalEvent::RouteTimer(..)) + | Event::KeyDown(_) | Event::KeyUp(_) => {} _ => { for (i, tab) in self.tabs.iter_mut().enumerate() {