add idle timer to editor view
@@ -41,6 +41,7 @@ pub struct LapceEditorView {
pub editor: WidgetPod<LapceTabData, LapceEditorContainer>,
pub find: Option<WidgetPod<LapceTabData, Box<dyn Widget<LapceTabData>>>>,
cursor_blink_timer: TimerToken,
+ last_idle_timer: TimerToken,
}
pub fn editor_tab_child_widget(
@@ -75,6 +76,7 @@ pub fn new(
editor: WidgetPod::new(editor),
find,
cursor_blink_timer: TimerToken::INVALID,
+ last_idle_timer: TimerToken::INVALID,
}
}
@@ -515,6 +517,10 @@ fn event(
return;
}
+ let editor = data.main_split.editors.get(&self.view_id).unwrap().clone();
+ let mut editor_data = data.editor_view_content(self.view_id);
+ let doc = editor_data.doc.clone();
+
match event {
Event::MouseDown(mouse_event) => match mouse_event.button {
druid::MouseButton::Left => {
@@ -529,7 +535,6 @@ fn event(
let command = cmd.get_unchecked(LAPCE_UI_COMMAND);
if let LapceUICommand::Focus = command {
self.request_focus(ctx, data, true);
- let editor_data = data.editor_view_content(self.view_id);
self.ensure_cursor_visible(
ctx,
&editor_data,
@@ -549,14 +554,19 @@ fn event(
self.cursor_blink_timer = TimerToken::INVALID;
}
}
- _ => (),
+ Event::Timer(id) if self.last_idle_timer == *id => {
+ ctx.set_handled();
+ if let BufferContent::Value(name) = &editor_data.editor.content {
+ // ctx.submit_command(Command::new(
+ // LAPCE_UI_COMMAND,
+ // LapceUICommand::UpdateSettingsFile(
+ // name.to_string(),
+ // editor_data.doc.buffer().text().to_string(),
+ // ),
+ // Target::Widget(data.id),
+ // ));
+ }
}
-
- let editor = data.main_split.editors.get(&self.view_id).unwrap().clone();
- let mut editor_data = data.editor_view_content(self.view_id);
- let doc = editor_data.doc.clone();
-
- match event {
Event::KeyDown(key_event) => {
ctx.set_handled();
let mut keypress = data.keypress.clone();
@@ -697,6 +707,16 @@ fn update(
let old_editor_data = old_data.editor_view_content(self.view_id);
let editor_data = data.editor_view_content(self.view_id);
+ if let BufferContent::Value(_) = &editor_data.editor.content {
+ if editor_data.doc.buffer().len() != old_editor_data.doc.buffer().len()
+ || editor_data.doc.buffer().text().slice_to_cow(..)
+ != old_editor_data.doc.buffer().text().slice_to_cow(..)
+ {
+ self.last_idle_timer =
+ ctx.request_timer(Duration::from_millis(500), None);
+ }
+ }
+
if data.focus == self.view_id {
let reset = if old_data.focus != self.view_id {
true
