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

feat: render bufferline separator #11704

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ impl EditorView {
let mut x = viewport.x;
let current_doc = view!(editor).doc;

for doc in editor.documents() {
for (idx, doc) in editor.documents().enumerate() {
let fname = doc
.path()
.unwrap_or(&scratch)
Expand All @@ -630,6 +630,16 @@ impl EditorView {
bufferline_inactive
};

// Render the separator before the text if the current document is not first.
if idx > 0 {
let used_width = viewport.x.saturating_sub(x);
let rem_width = surface.area.width.saturating_sub(used_width);
let sep = &editor.config().bufferline.separator;
x = surface
.set_stringn(x, viewport.y, sep, rem_width as usize, bufferline_inactive)
.0;
}

let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" });
let used_width = viewport.x.saturating_sub(x);
let rem_width = surface.area.width.saturating_sub(used_width);
Expand Down Expand Up @@ -1479,10 +1489,10 @@ impl Component for EditorView {
let config = cx.editor.config();

// check if bufferline should be rendered
use helix_view::editor::BufferLine;
let use_bufferline = match config.bufferline {
BufferLine::Always => true,
BufferLine::Multiple if cx.editor.documents.len() > 1 => true,
use helix_view::editor::BufferLineRenderMode;
let use_bufferline = match config.bufferline.render_mode {
BufferLineRenderMode::Always => true,
BufferLineRenderMode::Multiple if cx.editor.documents.len() > 1 => true,
_ => false,
};

Expand Down
48 changes: 32 additions & 16 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ pub struct Config {
/// Whether to display infoboxes. Defaults to true.
pub auto_info: bool,
pub file_picker: FilePickerConfig,
/// Configuration of the bufferline
pub bufferline: BufferLineConfig,
/// Configuration of the statusline elements
pub statusline: StatusLineConfig,
/// Shape for cursor in each mode
Expand All @@ -316,8 +318,6 @@ pub struct Config {
pub rulers: Vec<u16>,
#[serde(default)]
pub whitespace: WhitespaceConfig,
/// Persistently display open buffers along the top
pub bufferline: BufferLine,
/// Vertical indent width guides.
pub indent_guides: IndentGuidesConfig,
/// Whether to color modes with different colors. Defaults to `false`.
Expand Down Expand Up @@ -458,6 +458,35 @@ pub struct SearchConfig {
pub wrap_around: bool,
}

/// bufferline render modes
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum BufferLineRenderMode {
/// Don't render bufferline
#[default]
Never,
/// Always render
Always,
/// Only if multiple buffers are open
Multiple,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct BufferLineConfig {
pub render_mode: BufferLineRenderMode,
pub separator: String,
}

impl Default for BufferLineConfig {
fn default() -> Self {
Self {
render_mode: BufferLineRenderMode::default(),
separator: String::from("│"),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct StatusLineConfig {
Expand Down Expand Up @@ -633,19 +662,6 @@ impl Default for CursorShapeConfig {
}
}

/// bufferline render modes
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum BufferLine {
/// Don't render bufferline
#[default]
Never,
/// Always render
Always,
/// Only if multiple buffers are open
Multiple,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum LineNumber {
Expand Down Expand Up @@ -952,6 +968,7 @@ impl Default for Config {
completion_trigger_len: 2,
auto_info: true,
file_picker: FilePickerConfig::default(),
bufferline: BufferLineConfig::default(),
statusline: StatusLineConfig::default(),
cursor_shape: CursorShapeConfig::default(),
true_color: false,
Expand All @@ -961,7 +978,6 @@ impl Default for Config {
terminal: get_terminal_provider(),
rulers: Vec::new(),
whitespace: WhitespaceConfig::default(),
bufferline: BufferLine::default(),
indent_guides: IndentGuidesConfig::default(),
color_modes: false,
soft_wrap: SoftWrap {
Expand Down