Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub enum Action {
ThemeEditorOpenPicker,
ThemeEditorPickerLeft,
ThemeEditorPickerRight,
/// Toggle the active editor pane to fill the entire dual-pane area.
ToggleEditorFullscreen,
// Task runner
TaskLine(String),
TaskComplete(i32),
Expand Down
13 changes: 12 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ impl App {
self.dual_pane.draw(frame, chunks[0], &self.theme);
draw_status_bar(frame, chunks[1], &self.dual_pane, &self.input_mode, &self.theme);
let active_editor = self.dual_pane.active_editor().is_some();
let editor_fullscreen = self.dual_pane.editor_fullscreen;
draw_command_bar(
frame,
chunks[2],
&self.input_mode,
active_editor,
editor_fullscreen,
self.task.as_ref(),
&self.theme,
);
Expand Down Expand Up @@ -255,8 +257,12 @@ impl App {
InputMode::Normal => {}
}

// If the active pane is an editor, route all remaining keys into it.
// If the active pane is an editor, intercept the fullscreen toggle before
// routing everything else into the editor.
if self.dual_pane.active_editor().is_some() {
if let (KeyModifiers::CONTROL, KeyCode::Char('e')) = (key.modifiers, key.code) {
return Action::ToggleEditorFullscreen;
}
return Action::EditorKeyInput(key);
}

Expand Down Expand Up @@ -600,6 +606,11 @@ impl App {
self.dual_pane.close_editor_in_active();
}
}
Action::ToggleEditorFullscreen => {
if self.dual_pane.active_editor().is_some() {
self.dual_pane.editor_fullscreen = !self.dual_pane.editor_fullscreen;
}
}
Action::EditorKeyInput(key) => {
if let Some(inner_action) = self.dual_pane.handle_editor_key(key) {
self.dispatch(inner_action);
Expand Down
38 changes: 28 additions & 10 deletions src/components/command_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn draw_command_bar(
area: Rect,
input_mode: &InputMode,
active_editor: bool,
editor_fullscreen: bool,
task: Option<&TaskState>,
theme: &Theme,
) {
Expand All @@ -24,16 +25,33 @@ pub fn draw_command_bar(
let line = match input_mode {
InputMode::Normal => {
if active_editor {
Line::from(vec![
Span::styled("Ctrl+S", hint_style),
Span::raw(":Save "),
Span::styled("Ctrl+Q", hint_style),
Span::raw("/"),
Span::styled("Esc", hint_style),
Span::raw(":Close "),
Span::styled("Tab", hint_style),
Span::raw(":Switch pane"),
])
if editor_fullscreen {
Line::from(vec![
Span::styled("Ctrl+S", hint_style),
Span::raw(":Save "),
Span::styled("Ctrl+Q", hint_style),
Span::raw("/"),
Span::styled("Esc", hint_style),
Span::raw(":Close "),
Span::styled("Tab", hint_style),
Span::raw(":Switch pane "),
Span::styled("Ctrl+E", hint_style),
Span::raw(":Exit fullscreen"),
])
} else {
Line::from(vec![
Span::styled("Ctrl+S", hint_style),
Span::raw(":Save "),
Span::styled("Ctrl+Q", hint_style),
Span::raw("/"),
Span::styled("Esc", hint_style),
Span::raw(":Close "),
Span::styled("Tab", hint_style),
Span::raw(":Switch pane "),
Span::styled("Ctrl+E", hint_style),
Span::raw(":Fullscreen"),
])
}
} else {
let mut spans = vec![
Span::styled("F1", fkey_style),
Expand Down
20 changes: 20 additions & 0 deletions src/components/dual_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct DualPane {
pub left: PaneContent,
pub right: PaneContent,
pub active: PaneSide,
/// When true, the active editor fills the whole dual-pane area.
pub editor_fullscreen: bool,
}

impl DualPane {
Expand All @@ -45,6 +47,7 @@ impl DualPane {
left: PaneContent::Explorer(Explorer::new(left_dir)),
right: PaneContent::Explorer(Explorer::new(right_dir)),
active,
editor_fullscreen: false,
}
}

Expand Down Expand Up @@ -133,6 +136,7 @@ impl DualPane {
PaneContent::Editor(e) => e.origin_dir.clone(),
PaneContent::Explorer(_) => return,
};
self.editor_fullscreen = false;
match self.active {
PaneSide::Left => self.left = PaneContent::Explorer(Explorer::new(origin_dir)),
PaneSide::Right => self.right = PaneContent::Explorer(Explorer::new(origin_dir)),
Expand All @@ -150,6 +154,7 @@ impl DualPane {
pub fn handle_action(&mut self, action: &Action) -> Option<Action> {
match action {
Action::SwitchPane => {
self.editor_fullscreen = false;
self.active = match self.active {
PaneSide::Left => PaneSide::Right,
PaneSide::Right => PaneSide::Left,
Expand Down Expand Up @@ -179,6 +184,21 @@ impl DualPane {
}

pub fn draw(&mut self, frame: &mut Frame, area: Rect, theme: &Theme) {
if self.editor_fullscreen {
// Give the entire area to the active pane (must be an editor).
match self.active {
PaneSide::Left => match &mut self.left {
PaneContent::Editor(e) => e.draw(frame, area, true, theme),
PaneContent::Explorer(e) => e.draw(frame, area, true, theme),
},
PaneSide::Right => match &mut self.right {
PaneContent::Editor(e) => e.draw(frame, area, true, theme),
PaneContent::Explorer(e) => e.draw(frame, area, true, theme),
},
}
return;
}

let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
Expand Down
Loading