mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-23 01:46:18 +04:00
add on/off config options for persistence
This commit is contained in:
parent
56f47f04f6
commit
71217afc0c
@ -143,6 +143,15 @@ pub fn new(args: Args, config: Config, lang_loader: syntax::Loader) -> Result<Se
|
||||
let mut compositor = Compositor::new(area);
|
||||
let config = Arc::new(ArcSwap::from_pointee(config));
|
||||
let handlers = handlers::setup(config.clone());
|
||||
let old_file_locs = if config.load().editor.persist_old_files {
|
||||
HashMap::from_iter(
|
||||
persistence::read_file_history()
|
||||
.into_iter()
|
||||
.map(|entry| (entry.path.clone(), (entry.view_position, entry.selection))),
|
||||
)
|
||||
} else {
|
||||
HashMap::new()
|
||||
};
|
||||
let mut editor = Editor::new(
|
||||
area,
|
||||
theme_loader.clone(),
|
||||
@ -151,29 +160,31 @@ pub fn new(args: Args, config: Config, lang_loader: syntax::Loader) -> Result<Se
|
||||
&config.editor
|
||||
})),
|
||||
handlers,
|
||||
HashMap::from_iter(
|
||||
persistence::read_file_history()
|
||||
.into_iter()
|
||||
.map(|entry| (entry.path.clone(), (entry.view_position, entry.selection))),
|
||||
),
|
||||
old_file_locs,
|
||||
);
|
||||
|
||||
// TODO: do most of this in the background?
|
||||
editor
|
||||
.registers
|
||||
.write(':', persistence::read_command_history())
|
||||
// TODO: do something about this unwrap
|
||||
.unwrap();
|
||||
editor
|
||||
.registers
|
||||
.write('/', persistence::read_search_history())
|
||||
// TODO: do something about this unwrap
|
||||
.unwrap();
|
||||
editor
|
||||
.registers
|
||||
.write('"', persistence::read_clipboard_file())
|
||||
// TODO: do something about this unwrap
|
||||
.unwrap();
|
||||
if config.load().editor.persist_commands {
|
||||
editor
|
||||
.registers
|
||||
.write(':', persistence::read_command_history())
|
||||
// TODO: do something about this unwrap
|
||||
.unwrap();
|
||||
}
|
||||
if config.load().editor.persist_search {
|
||||
editor
|
||||
.registers
|
||||
.write('/', persistence::read_search_history())
|
||||
// TODO: do something about this unwrap
|
||||
.unwrap();
|
||||
}
|
||||
if config.load().editor.persist_clipboard {
|
||||
editor
|
||||
.registers
|
||||
.write('"', persistence::read_clipboard_file())
|
||||
// TODO: do something about this unwrap
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let keys = Box::new(Map::new(Arc::clone(&config), |config: &Config| {
|
||||
&config.keys
|
||||
|
@ -4206,7 +4206,9 @@ fn yank_impl(editor: &mut Editor, register: char) {
|
||||
.collect();
|
||||
let selections = values.len();
|
||||
|
||||
persistence::write_clipboard_file(&values);
|
||||
if editor.config().persist_clipboard {
|
||||
persistence::write_clipboard_file(&values);
|
||||
}
|
||||
|
||||
match editor.registers.write(register, values) {
|
||||
Ok(_) => editor.set_status(format!(
|
||||
|
@ -614,7 +614,11 @@ fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
|
||||
{
|
||||
cx.editor.set_error(err.to_string());
|
||||
}
|
||||
persistence::push_reg_history(register, &self.line);
|
||||
if (cx.editor.config().persist_commands && register == ':')
|
||||
|| (cx.editor.config().persist_search && register == '/')
|
||||
{
|
||||
persistence::push_reg_history(register, &self.line);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -347,6 +347,10 @@ pub struct Config {
|
||||
/// Display diagnostic below the line they occur.
|
||||
pub inline_diagnostics: InlineDiagnosticsConfig,
|
||||
pub end_of_line_diagnostics: DiagnosticFilter,
|
||||
pub persist_old_files: bool,
|
||||
pub persist_commands: bool,
|
||||
pub persist_search: bool,
|
||||
pub persist_clipboard: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
|
||||
@ -981,6 +985,10 @@ fn default() -> Self {
|
||||
jump_label_alphabet: ('a'..='z').collect(),
|
||||
inline_diagnostics: InlineDiagnosticsConfig::default(),
|
||||
end_of_line_diagnostics: DiagnosticFilter::Disable,
|
||||
persist_old_files: false,
|
||||
persist_commands: false,
|
||||
persist_search: false,
|
||||
persist_clipboard: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1777,10 +1785,12 @@ pub fn close(&mut self, id: ViewId) {
|
||||
doc.remove_view(id);
|
||||
}
|
||||
|
||||
for loc in file_locs {
|
||||
persistence::push_file_history(&loc);
|
||||
self.old_file_locs
|
||||
.insert(loc.path, (loc.view_position, loc.selection));
|
||||
if self.config().persist_old_files {
|
||||
for loc in file_locs {
|
||||
persistence::push_file_history(&loc);
|
||||
self.old_file_locs
|
||||
.insert(loc.path, (loc.view_position, loc.selection));
|
||||
}
|
||||
}
|
||||
|
||||
self.tree.remove(id);
|
||||
@ -1840,10 +1850,12 @@ enum Action {
|
||||
})
|
||||
.collect();
|
||||
|
||||
for loc in file_locs {
|
||||
persistence::push_file_history(&loc);
|
||||
self.old_file_locs
|
||||
.insert(loc.path, (loc.view_position, loc.selection));
|
||||
if self.config().persist_old_files {
|
||||
for loc in file_locs {
|
||||
persistence::push_file_history(&loc);
|
||||
self.old_file_locs
|
||||
.insert(loc.path, (loc.view_position, loc.selection));
|
||||
}
|
||||
}
|
||||
|
||||
for action in actions {
|
||||
|
Loading…
Reference in New Issue
Block a user