Skip to content

Commit

Permalink
fix(explorer): fix explorer mode
Browse files Browse the repository at this point in the history
  • Loading branch information
metiftikci committed Sep 30, 2023
1 parent 5ca6a66 commit 1b89491
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/buffer/maps.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::HashMap;

use crate::buffer::actions::find_next_word_position::find_next_word_position;
use crate::{
buffer::actions::find_next_word_position::find_next_word_position, core::Size,
plugins::explorer::explorer_buffer::create_explorer_buffer,
};

use super::ActionMap;

Expand Down Expand Up @@ -104,7 +107,23 @@ pub fn get_default_command_maps() -> ActionMap {
editor.get_active_buffer_mut().enter_normal_mode()
});
map.insert("enter", |editor| {
editor.get_active_buffer_mut().run_command()
// TODO: Move this
let command = editor.get_active_buffer().command.text.trim();
if command == "e" {
let window = editor.get_active_window();
let buffer = create_explorer_buffer(
String::from("."),
Size {
width: window.size.width,
height: window.size.height - 2,
},
);
let window = editor.get_active_window_mut();
window.buffers.push(buffer);
window.active_buffer = window.buffers.len() - 1;
} else {
editor.get_active_buffer_mut().run_command()
}
});
map.insert("backspace", |editor| {
editor.get_active_buffer_mut().command.delete_char()
Expand Down
6 changes: 4 additions & 2 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Window {
pub position: Point<u16>,
pub size: Size<u16>,
pub buffers: Vec<Buffer>,
pub active_buffer: usize,
}

impl Window {
Expand All @@ -15,6 +16,7 @@ impl Window {
position: Point { x: 0, y: 0 },
size,
buffers: vec![],
active_buffer: 0,
}
}

Expand All @@ -28,11 +30,11 @@ impl Window {
}

pub fn get_active_buffer(&self) -> &Buffer {
self.buffers.get(0).unwrap()
self.buffers.get(self.active_buffer).unwrap()
}

pub fn get_active_buffer_mut(&mut self) -> &mut Buffer {
self.buffers.get_mut(0).unwrap()
self.buffers.get_mut(self.active_buffer).unwrap()
}

pub fn set_size(&mut self, width: u16, height: u16) {
Expand Down

0 comments on commit 1b89491

Please sign in to comment.