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.rs69
1 files changed, 61 insertions, 8 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index ad7aa5c5..7d28b62c 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,
}
@@ -1288,6 +1290,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,
@@ -1445,6 +1452,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 {
@@ -1453,17 +1462,47 @@ 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 bufferline_area = area.with_height(1);
+ let (editor_area, bufferline_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),
+ bufferline_area.clip_left(explorer_column_width),
+ ),
+ ExplorerPosition::Right => (
+ editor_area.clip_right(explorer_column_width),
+ bufferline_area.clip_left(explorer_column_width),
+ ),
+ }
+ } else {
+ (editor_area, bufferline_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() {
+ explorer.render(area, surface, cx);
+ }
+ }
+
if use_bufferline {
- Self::render_bufferline(cx.editor, area.with_height(1), surface);
+ Self::render_bufferline(cx.editor, bufferline_area, surface);
}
for (view, is_focused) in cx.editor.tree.views() {
@@ -1540,9 +1579,23 @@ 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() {
+ 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) => {