feat(explore): close without clearing previous state

pull/9/head
wongjiahau 1 year ago
parent 790192dfd4
commit b38a941955

@ -1269,8 +1269,16 @@ impl Component for EditorView {
// if the terminal size suddenly changed, we need to trigger a resize
let editor_area = area.clip_bottom(1);
let explorer_column_width = config.explorer.column_width as u16 + 2;
let editor_area = if self.explorer.is_some() {
let editor_area = if let Some(explorer) = &self.explorer {
let explorer_column_width = if explorer.content.is_opened() {
explorer.content.column_width().saturating_add(2)
} else {
0
};
// For future developer:
// We should have a Dock trait that allows a component to dock to the top/left/bottom/right
// of another component.
match config.explorer.position {
ExplorerPosition::Overlay => editor_area,
ExplorerPosition::Left => editor_area.clip_left(explorer_column_width),

@ -145,6 +145,7 @@ enum PromptAction {
#[derive(Clone, Debug)]
struct State {
focus: bool,
open: bool,
current_root: PathBuf,
}
@ -153,6 +154,7 @@ impl State {
Self {
focus,
current_root,
open: true,
}
}
}
@ -244,12 +246,18 @@ impl Explorer {
pub fn focus(&mut self) {
self.state.focus = true;
self.state.open = true;
}
pub fn unfocus(&mut self) {
self.state.focus = false;
}
pub fn close(&mut self) {
self.state.focus = false;
self.state.open = false;
}
pub fn is_focus(&self) -> bool {
self.state.focus
}
@ -287,7 +295,8 @@ impl Explorer {
"[ Change root to parent folder",
"] Change root to current folder",
"^o Go to previous root",
"R Refresh tree",
"R Refresh",
"q Close",
]
.into_iter()
.map(|s| s.to_string())
@ -508,6 +517,9 @@ impl Explorer {
cx: &mut Context,
position: &ExplorerPositionEmbed,
) {
if !self.state.open {
return;
}
let width = area.width.min(self.column_width + 2);
let side_area = match position {
@ -787,6 +799,14 @@ impl Explorer {
self.tree = tree
}
}
pub fn is_opened(&self) -> bool {
self.state.open
}
pub fn column_width(&self) -> u16 {
self.column_width
}
}
impl Component for Explorer {
@ -808,15 +828,9 @@ impl Component for Explorer {
return EventResult::Consumed(c);
}
let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor, _| {
if let Some(editor) = compositor.find::<ui::EditorView>() {
editor.explorer = None;
}
})));
match key_event.into() {
key!(Esc) => self.unfocus(),
ctrl!('c') => return close_fn,
key!('q') => self.close(),
key!('n') => {
if let Some(mut repeat_motion) = self.repeat_motion.take() {
repeat_motion(self, PromptAction::Search { search_next: true }, cx);

@ -152,7 +152,6 @@ impl ExplorerConfig {
_ => false,
}
}
}
impl Default for ExplorerConfig {

Loading…
Cancel
Save