Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial implementation of bufferline #2759

Merged
merged 23 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
58 changes: 54 additions & 4 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use helix_view::{
keyboard::{KeyCode, KeyModifiers},
Document, Editor, Theme, View,
};
use std::borrow::Cow;
use std::{borrow::Cow, path::PathBuf};

use crossterm::event::{Event, MouseButton, MouseEvent, MouseEventKind};
use tui::buffer::Buffer as Surface;
Expand Down Expand Up @@ -75,8 +75,16 @@ impl EditorView {
surface: &mut Surface,
is_focused: bool,
) {
let inner = view.inner_area();
let area = view.area;
let inner = if editor.config().tabs {
view.inner_area().clip_top(1)
} else {
view.inner_area()
};
let area = if editor.config().tabs {
view.area.clip_top(1)
} else {
view.area
};
let theme = &editor.theme;

// DAP: Highlight current stack frame position
Expand Down Expand Up @@ -133,9 +141,14 @@ impl EditorView {
highlights,
&editor.config().whitespace,
);
Self::render_gutter(editor, doc, view, view.area, surface, theme, is_focused);
Self::render_gutter(editor, doc, view, area, surface, theme, is_focused);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly cannot remember.. I have reverted it for now

Self::render_rulers(editor, doc, view, inner, surface, theme);

if editor.config().tabs {
let tabs_area = view.area.clip_bottom(view.area.height.saturating_sub(1));
aaron404 marked this conversation as resolved.
Show resolved Hide resolved
Self::render_tabs(editor, view, tabs_area, surface, theme);
}

if is_focused {
Self::render_focused_view_elements(view, doc, inner, theme, surface);
}
Expand Down Expand Up @@ -541,6 +554,43 @@ impl EditorView {
}
}

/// Render bufferline at the top
pub fn render_tabs(
editor: &Editor,
view: &View,
viewport: Rect,
surface: &mut Surface,
theme: &Theme,
) {
let pb = PathBuf::from(" [scratch] "); // default filename to use for scratch buffer
aaron404 marked this conversation as resolved.
Show resolved Hide resolved
surface.clear_with(viewport, theme.get("ui.statusline"));
let mut len = 0usize;
editor.documents().for_each(|doc| {
aaron404 marked this conversation as resolved.
Show resolved Hide resolved
let fname = doc
.path()
.unwrap_or_else(|| &pb)
.file_name()
.unwrap_or_default()
.to_str()
.unwrap();
aaron404 marked this conversation as resolved.
Show resolved Hide resolved

let style = if view.doc == doc.id() {
theme.get("ui.background")
} else {
theme.get("ui.statusline")
};
aaron404 marked this conversation as resolved.
Show resolved Hide resolved

surface.set_string(
1 + viewport.x + len as u16,
viewport.y,
format!(" {fname} "),
aaron404 marked this conversation as resolved.
Show resolved Hide resolved
style,
);

len += fname.len() + 2; // add some padding between tabs
});
}

pub fn render_gutter(
editor: &Editor,
doc: &Document,
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ pub struct Config {
pub rulers: Vec<u16>,
#[serde(default)]
pub whitespace: WhitespaceConfig,
/// Persistently display open buffers with tabs
pub tabs: bool,
}

#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -387,6 +389,7 @@ impl Default for Config {
lsp: LspConfig::default(),
rulers: Vec::new(),
whitespace: WhitespaceConfig::default(),
tabs: true,
aaron404 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down