prevent opening the same file multiple times
This commit is contained in:
parent
c4f0d85e24
commit
f17a78f088
2 changed files with 23 additions and 8 deletions
|
@ -93,6 +93,10 @@ impl Editor {
|
|||
"untitled".into()
|
||||
}
|
||||
|
||||
pub fn path(&self) -> Option<&PathBuf> {
|
||||
self.path.as_ref()
|
||||
}
|
||||
|
||||
pub fn has_unsaved_changes(&self) -> bool {
|
||||
self.unsaved_changes
|
||||
}
|
||||
|
@ -240,7 +244,7 @@ impl Editor {
|
|||
self.cursor.line -= 1;
|
||||
self.cursor.column = self.current_line().len();
|
||||
}
|
||||
self.scroll_to_cursor()
|
||||
self.scroll_to_cursor();
|
||||
}
|
||||
|
||||
fn move_right(&mut self) {
|
||||
|
@ -250,7 +254,7 @@ impl Editor {
|
|||
self.cursor.line += 1;
|
||||
self.cursor.column = 0;
|
||||
}
|
||||
self.scroll_to_cursor()
|
||||
self.scroll_to_cursor();
|
||||
}
|
||||
|
||||
fn move_up(&mut self, lines: usize) {
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -169,14 +169,25 @@ impl Navigator {
|
|||
env::set_current_dir(&self.path).unwrap();
|
||||
self.selected = self.editors.len();
|
||||
} else if path.is_file() {
|
||||
let path = path.canonicalize().unwrap();
|
||||
self.selected = self.editors.len();
|
||||
for (i, editor) in self.editors.iter().enumerate() {
|
||||
if editor.path() == Some(&path) {
|
||||
self.selected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if self.selected == self.editors.len() {
|
||||
if let Some(editor) =
|
||||
Editor::open_file(self.clipboard.clone(), path.canonicalize().unwrap())
|
||||
{
|
||||
self.selected = self.editors.len();
|
||||
self.editors.push(editor);
|
||||
self.open_selected();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.open_selected();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue