Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add save on idle 🚀 #5303

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ on unix operating systems.
| `auto-completion` | Enable automatic pop up of auto-completion. | `true` |
| `auto-format` | Enable automatic formatting on save. | `true` |
| `auto-save` | Enable automatic saving on focus moving away from Helix. Requires [focus event support](https://github.com/helix-editor/helix/wiki/Terminal-Support) from your terminal. | `false` |
| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. | `400` |
| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion and idle-save, set to 0 for instant. | `400` |
| `idle-save` | Enable automatic saving on idle timer trigger. | `false` |
| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` |
| `auto-info` | Whether to display infoboxes | `true` |
| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` |
Expand Down
10 changes: 9 additions & 1 deletion helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,15 @@ impl Component for EditorView {
}

Event::Mouse(event) => self.handle_mouse_event(event, &mut cx),
Event::IdleTimeout => self.handle_idle_timeout(&mut cx),
Event::IdleTimeout => {
let event_result = self.handle_idle_timeout(&mut cx);
if context.editor.config().idle_save {
if let Err(e) = commands::typed::write_all_impl(context, false, false) {
context.editor.set_error(format!("{}", e));
}
}
event_result
}
Event::FocusGained => EventResult::Ignored(None),
Event::FocusLost => {
if context.editor.config().auto_save {
Expand Down
5 changes: 4 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ pub struct Config {
/// Automatic save on focus lost. Defaults to false.
pub auto_save: bool,
/// Time in milliseconds since last keypress before idle timers trigger.
/// Used for autocompletion, set to 0 for instant. Defaults to 400ms.
/// Used for autocompletion and idle-save, set to 0 for instant. Defaults to 400ms.
#[serde(
serialize_with = "serialize_duration_millis",
deserialize_with = "deserialize_duration_millis"
)]
pub idle_timeout: Duration,
/// Automatic save on idle timeout trigger. Defaults to false.
pub idle_save: bool,
pub completion_trigger_len: u8,
/// Whether to display infoboxes. Defaults to true.
pub auto_info: bool,
Expand Down Expand Up @@ -616,6 +618,7 @@ impl Default for Config {
auto_format: true,
auto_save: false,
idle_timeout: Duration::from_millis(400),
idle_save: false,
completion_trigger_len: 2,
auto_info: true,
file_picker: FilePickerConfig::default(),
Expand Down