refactor(explorer): remove overlay option

pull/9/head
wongjiahau 1 year ago
parent afda68a11d
commit e5dfde2a9b

@ -1386,7 +1386,6 @@ impl Component for EditorView {
// 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),
ExplorerPosition::Right => editor_area.clip_right(explorer_column_width),
}
@ -1399,14 +1398,12 @@ impl Component for EditorView {
if let Some(explorer) = self.explorer.as_mut() {
if !explorer.is_focus() {
if let Some(position) = config.explorer.is_embed() {
let area = if use_bufferline {
area.clip_top(1)
} else {
area
};
explorer.render_embed(area, surface, cx, &position);
}
let area = if use_bufferline {
area.clip_top(1)
} else {
area
};
explorer.render(area, surface, cx);
}
}
@ -1491,16 +1488,12 @@ impl Component for EditorView {
if let Some(explore) = self.explorer.as_mut() {
if explore.is_focus() {
if let Some(position) = config.explorer.is_embed() {
let area = if use_bufferline {
area.clip_top(1)
} else {
area
};
explore.render_embed(area, surface, cx, &position);
let area = if use_bufferline {
area.clip_top(1)
} else {
explore.render(area, surface, cx);
}
area
};
explore.render(area, surface, cx);
}
}
}
@ -1508,9 +1501,6 @@ impl Component for EditorView {
fn cursor(&self, _area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {
if let Some(explore) = &self.explorer {
if explore.is_focus() {
if editor.config().explorer.is_overlay() {
return explore.cursor(_area, editor);
}
let cursor = explore.cursor(_area, editor);
if cursor.0.is_some() {
return cursor;

@ -6,7 +6,7 @@ use crate::{
use anyhow::{bail, ensure, Result};
use helix_core::Position;
use helix_view::{
editor::{Action, ExplorerPositionEmbed},
editor::{Action, ExplorerPosition},
graphics::{CursorKind, Rect},
info::Info,
input::{Event, KeyEvent},
@ -400,29 +400,6 @@ impl Explorer {
})
}
fn render_float(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
let float_area_box = area.overlayed();
let background = cx.editor.theme.get("ui.background");
surface.clear_with(float_area_box, background);
let float_area = render_block(float_area_box, surface, Borders::ALL);
let help_area = float_area.clip_left(self.column_width + 1);
if let Some((_, prompt)) = self.prompt.as_mut() {
prompt.render(area, surface, cx);
}
if self.show_help {
self.render_help(help_area, surface, cx);
}
let list_area = render_block(
float_area.clip_right(help_area.width),
surface,
Borders::RIGHT,
);
self.render_tree(list_area, area, surface, cx)
}
fn render_tree(
&mut self,
area: Rect,
@ -446,12 +423,12 @@ impl Explorer {
self.tree.render(area.clip_top(1), prompt_area, surface, cx);
}
pub fn render_embed(
fn render_embed(
&mut self,
area: Rect,
surface: &mut Surface,
cx: &mut Context,
position: &ExplorerPositionEmbed,
position: &ExplorerPosition,
) {
if !self.state.open {
return;
@ -461,8 +438,8 @@ impl Explorer {
self.state.area_width = area.width;
let side_area = match position {
ExplorerPositionEmbed::Left => Rect { width, ..area },
ExplorerPositionEmbed::Right => Rect {
ExplorerPosition::Left => Rect { width, ..area },
ExplorerPosition::Right => Rect {
x: area.width - width,
width,
..area
@ -475,10 +452,10 @@ impl Explorer {
let prompt_area = area.clip_top(side_area.height);
let list_area = match position {
ExplorerPositionEmbed::Left => {
ExplorerPosition::Left => {
render_block(side_area.clip_left(1), surface, Borders::RIGHT).clip_bottom(1)
}
ExplorerPositionEmbed::Right => {
ExplorerPosition::Right => {
render_block(side_area.clip_right(1), surface, Borders::LEFT).clip_bottom(1)
}
};
@ -492,16 +469,16 @@ impl Explorer {
};
let area = side_area.clip_top(list_area.height);
let area = match position {
ExplorerPositionEmbed::Left => area.clip_right(1),
ExplorerPositionEmbed::Right => area.clip_left(1),
ExplorerPosition::Left => area.clip_right(1),
ExplorerPosition::Right => area.clip_left(1),
};
surface.clear_with(area, statusline);
}
if self.is_focus() && self.show_help {
let help_area = match position {
ExplorerPositionEmbed::Left => area,
ExplorerPositionEmbed::Right => area.clip_right(list_area.width.saturating_add(2)),
ExplorerPosition::Left => area,
ExplorerPosition::Right => area.clip_right(list_area.width.saturating_add(2)),
};
self.render_help(help_area, surface, cx);
}
@ -740,11 +717,8 @@ impl Component for Explorer {
return;
}
let config = &cx.editor.config().explorer;
if let Some(position) = config.is_embed() {
self.render_embed(area, surface, cx, &position);
} else {
self.render_float(area, surface, cx);
}
let position = config.position;
self.render_embed(area, surface, cx, &position);
}
fn cursor(&self, area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {

@ -221,30 +221,10 @@ pub struct ExplorerConfig {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum ExplorerPosition {
Overlay,
Left,
Right,
}
pub enum ExplorerPositionEmbed {
Left,
Right,
}
impl ExplorerConfig {
pub fn is_embed(&self) -> Option<ExplorerPositionEmbed> {
match self.position {
ExplorerPosition::Overlay => None,
ExplorerPosition::Left => Some(ExplorerPositionEmbed::Left),
ExplorerPosition::Right => Some(ExplorerPositionEmbed::Right),
}
}
pub fn is_overlay(&self) -> bool {
matches!(self.position, ExplorerPosition::Overlay)
}
}
impl Default for ExplorerConfig {
fn default() -> Self {
Self {

Loading…
Cancel
Save