Merge pull request #80 from christopher-l/fix/change-dir-loop

Fix bug where rapid `cd`s cause infinite loop
This commit is contained in:
daa84 2018-03-25 11:17:36 +03:00 committed by GitHub
commit 6bea20d406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -180,7 +180,9 @@ impl FileBrowserWidget {
cd_action.connect_activate(clone!(state_ref, nvim_ref => move |_, _| {
let mut nvim = nvim_ref.nvim().unwrap();
if let Some(ref path) = state_ref.borrow().selected_path {
nvim.set_current_dir(&path).report_err();
nvim.set_current_dir_async(&path)
.cb(|r| r.report_err())
.call();
}
}));
actions.add_action(cd_action);
@ -201,11 +203,10 @@ impl FileBrowserWidget {
&["getcwd()"],
clone!(store, state_ref, dir_list_model, dir_list => move |args| {
let dir = args.into_iter().next().unwrap();
let mut state = state_ref.borrow_mut();
if dir != *state.current_dir {
if dir != state_ref.borrow().current_dir {
state_ref.borrow_mut().current_dir = dir.to_owned();
update_dir_list(&dir, &dir_list_model, &dir_list);
state.current_dir = dir;
tree_reload(&store, &state);
tree_reload(&store, &state_ref.borrow());
}
}),
);
@ -277,18 +278,20 @@ impl FileBrowserWidget {
// Connect directory list.
let nvim_ref = self.nvim.as_ref().unwrap();
self.comps.dir_list.connect_changed(clone!(nvim_ref => move |dir_list| {
self.comps.dir_list.connect_changed(clone!(nvim_ref, state_ref => move |dir_list| {
if let Some(iter) = dir_list.get_active_iter() {
let model = dir_list.get_model().unwrap();
if let Some(dir) = model.get_value(&iter, 2).get::<&str>() {
if dir != state_ref.borrow().current_dir {
let mut nvim = nvim_ref.nvim().unwrap();
nvim.set_current_dir(dir).report_err();
nvim.set_current_dir_async(dir)
.cb(|r| r.report_err())
.call();
}
}
}
}));
let store = &self.store;
let state_ref = &self.state;
let context_menu = &self.comps.context_menu;
let cd_action = &self.comps.cd_action;
self.tree.connect_button_press_event(