cursor blink when switching window tab

This commit is contained in:
Dongdong Zhou 2022-07-06 21:52:20 +01:00
parent a79254b445
commit 1268fb9ec8
2 changed files with 7 additions and 7 deletions

View File

@ -550,6 +550,8 @@ fn event(
Event::Command(cmd) if cmd.is(LAPCE_UI_COMMAND) => { Event::Command(cmd) if cmd.is(LAPCE_UI_COMMAND) => {
let command = cmd.get_unchecked(LAPCE_UI_COMMAND); let command = cmd.get_unchecked(LAPCE_UI_COMMAND);
if let LapceUICommand::Focus = command { if let LapceUICommand::Focus = command {
self.cursor_blink_timer =
ctx.request_timer(Duration::from_millis(500), None);
self.request_focus(ctx, data, true); self.request_focus(ctx, data, true);
let editor_data = data.editor_view_content(self.view_id); let editor_data = data.editor_view_content(self.view_id);
self.ensure_cursor_visible( self.ensure_cursor_visible(
@ -563,7 +565,7 @@ fn event(
} }
Event::Timer(id) if self.cursor_blink_timer == *id => { Event::Timer(id) if self.cursor_blink_timer == *id => {
ctx.set_handled(); ctx.set_handled();
if data.focus == self.view_id { if ctx.is_focused() {
ctx.request_paint(); ctx.request_paint();
self.cursor_blink_timer = self.cursor_blink_timer =
ctx.request_timer(Duration::from_millis(500), None); ctx.request_timer(Duration::from_millis(500), None);

View File

@ -1,9 +1,9 @@
use druid::{ use druid::{
kurbo::Line, kurbo::Line,
widget::{LensWrap, WidgetExt}, widget::{LensWrap, WidgetExt},
BoxConstraints, Command, Env, Event, EventCtx, InternalEvent, LayoutCtx, BoxConstraints, Command, Env, Event, EventCtx, LayoutCtx, LifeCycle,
LifeCycle, LifeCycleCtx, PaintCtx, Point, RenderContext, Size, Target, Widget, LifeCycleCtx, PaintCtx, Point, RenderContext, Size, Target, Widget, WidgetId,
WidgetId, WidgetPod, WindowState, WidgetPod, WindowState,
}; };
use lapce_data::{ use lapce_data::{
command::{LapceUICommand, LAPCE_UI_COMMAND}, command::{LapceUICommand, LAPCE_UI_COMMAND},
@ -356,10 +356,8 @@ fn event(
| Event::MouseUp(_) | Event::MouseUp(_)
| Event::MouseMove(_) | Event::MouseMove(_)
| Event::Wheel(_) | Event::Wheel(_)
| Event::KeyDown(_)
| Event::Timer(_)
| Event::AnimFrame(_) | Event::AnimFrame(_)
| Event::Internal(InternalEvent::RouteTimer(..)) | Event::KeyDown(_)
| Event::KeyUp(_) => {} | Event::KeyUp(_) => {}
_ => { _ => {
for (i, tab) in self.tabs.iter_mut().enumerate() { for (i, tab) in self.tabs.iter_mut().enumerate() {