aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/editor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/ui/editor.rs')
-rw-r--r--helix-term/src/ui/editor.rs70
1 files changed, 63 insertions, 7 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 31195a4e..a305907b 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -6,7 +6,7 @@ use crate::{
keymap::{KeymapResult, Keymaps},
ui::{
document::{render_document, LinePos, TextRenderer, TranslatedPosition},
- Completion, ProgressSpinners,
+ Completion, Explorer, ProgressSpinners,
},
};
@@ -23,7 +23,7 @@ use helix_core::{
};
use helix_view::{
document::{Mode, SavePoint, SCRATCH_BUFFER_NAME},
- editor::{CompleteAction, CursorShapeConfig},
+ editor::{CompleteAction, CursorShapeConfig, ExplorerPosition},
graphics::{Color, CursorKind, Modifier, Rect, Style},
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind},
keyboard::{KeyCode, KeyModifiers},
@@ -42,6 +42,7 @@ pub struct EditorView {
pseudo_pending: Vec<KeyEvent>,
pub(crate) last_insert: (commands::MappableCommand, Vec<InsertEvent>),
pub(crate) completion: Option<Completion>,
+ pub(crate) explorer: Option<Explorer>,
spinners: ProgressSpinners,
/// Tracks if the terminal window is focused by reaction to terminal focus events
terminal_focused: bool,
@@ -72,6 +73,7 @@ impl EditorView {
pseudo_pending: Vec::new(),
last_insert: (commands::MappableCommand::normal_mode, Vec::new()),
completion: None,
+ explorer: None,
spinners: ProgressSpinners::default(),
terminal_focused: true,
}
@@ -1235,6 +1237,11 @@ impl Component for EditorView {
event: &Event,
context: &mut crate::compositor::Context,
) -> EventResult {
+ if let Some(explore) = self.explorer.as_mut() {
+ if let EventResult::Consumed(callback) = explore.handle_event(event, context) {
+ return EventResult::Consumed(callback);
+ }
+ }
let mut cx = commands::Context {
editor: context.editor,
count: None,
@@ -1401,6 +1408,8 @@ impl Component for EditorView {
surface.set_style(area, cx.editor.theme.get("ui.background"));
let config = cx.editor.config();
+ let editor_area = area.clip_bottom(1);
+
// check if bufferline should be rendered
use helix_view::editor::BufferLine;
let use_bufferline = match config.bufferline {
@@ -1409,15 +1418,43 @@ impl Component for EditorView {
_ => false,
};
- // -1 for commandline and -1 for bufferline
- let mut editor_area = area.clip_bottom(1);
- if use_bufferline {
- editor_area = editor_area.clip_top(1);
- }
+ let editor_area = if use_bufferline {
+ editor_area.clip_top(1)
+ } else {
+ editor_area
+ };
+
+ let editor_area = if let Some(explorer) = &self.explorer {
+ let explorer_column_width = if explorer.is_opened() {
+ explorer.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::Left => editor_area.clip_left(explorer_column_width),
+ ExplorerPosition::Right => editor_area.clip_right(explorer_column_width),
+ }
+ } else {
+ editor_area
+ };
// if the terminal size suddenly changed, we need to trigger a resize
cx.editor.resize(editor_area);
+ if let Some(explorer) = self.explorer.as_mut() {
+ if !explorer.is_focus() {
+ let area = if use_bufferline {
+ area.clip_top(1)
+ } else {
+ area
+ };
+ explorer.render(area, surface, cx);
+ }
+ }
+
if use_bufferline {
Self::render_bufferline(cx.editor, area.with_height(1), surface);
}
@@ -1496,9 +1533,28 @@ impl Component for EditorView {
if let Some(completion) = self.completion.as_mut() {
completion.render(area, surface, cx);
}
+
+ if let Some(explore) = self.explorer.as_mut() {
+ if explore.is_focus() {
+ let area = if use_bufferline {
+ area.clip_top(1)
+ } else {
+ area
+ };
+ explore.render(area, surface, cx);
+ }
+ }
}
fn cursor(&self, _area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {
+ if let Some(explore) = &self.explorer {
+ if explore.is_focus() {
+ let cursor = explore.cursor(_area, editor);
+ if cursor.0.is_some() {
+ return cursor;
+ }
+ }
+ }
match editor.cursor() {
// All block cursors are drawn manually
(pos, CursorKind::Block) => (pos, CursorKind::Hidden),