Add style configuration for tabline, make tabline compatible with bufferline

pull/7109/head
Nikodem Rabuliński 1 year ago
parent a767408e4c
commit 66f009b873
No known key found for this signature in database

@ -583,18 +583,21 @@ impl EditorView {
viewport, viewport,
editor editor
.theme .theme
.try_get("ui.bufferline.background") .try_get("ui.tabline.background")
.or_else(|| editor.theme.try_get("ui.bufferline.background"))
.unwrap_or_else(|| editor.theme.get("ui.statusline")), .unwrap_or_else(|| editor.theme.get("ui.statusline")),
); );
let bufferline_active = editor let tabline_active = editor
.theme .theme
.try_get("ui.bufferline.active") .try_get("ui.tabline.active")
.or_else(|| editor.theme.try_get("ui.bufferline.active"))
.unwrap_or_else(|| editor.theme.get("ui.statusline.active")); .unwrap_or_else(|| editor.theme.get("ui.statusline.active"));
let bufferline_inactive = editor let tabline_inactive = editor
.theme .theme
.try_get("ui.bufferline") .try_get("ui.tabline")
.or_else(|| editor.theme.try_get("ui.bufferline"))
.unwrap_or_else(|| editor.theme.get("ui.statusline.inactive")); .unwrap_or_else(|| editor.theme.get("ui.statusline.inactive"));
let mut x = viewport.x; let mut x = viewport.x;
@ -602,9 +605,9 @@ impl EditorView {
let current_tab = editor.tabs.focus; let current_tab = editor.tabs.focus;
for (id, tab) in editor.tabs.iter_tabs() { for (id, tab) in editor.tabs.iter_tabs() {
let style = if current_tab == id { let style = if current_tab == id {
bufferline_active tabline_active
} else { } else {
bufferline_inactive tabline_inactive
}; };
let text = format!(" {} ", tab.name); let text = format!(" {} ", tab.name);
@ -1511,6 +1514,14 @@ impl Component for EditorView {
surface.set_style(area, cx.editor.theme.get("ui.background")); surface.set_style(area, cx.editor.theme.get("ui.background"));
let config = cx.editor.config(); let config = cx.editor.config();
// check if tabline should be rendered
use helix_view::editor::TabLine;
let use_tabline = if let TabLine::Multiple = config.tabline {
cx.editor.tabs.len() > 1
} else {
true
};
// check if bufferline should be rendered // check if bufferline should be rendered
use helix_view::editor::BufferLine; use helix_view::editor::BufferLine;
let use_bufferline = match config.bufferline { let use_bufferline = match config.bufferline {
@ -1519,8 +1530,15 @@ impl Component for EditorView {
_ => false, _ => false,
}; };
// -1 for commandline and -1 for bufferline // -1 for commandline and -1 for tabline
let mut bufferline_area = area;
let mut editor_area = area.clip_bottom(1); let mut editor_area = area.clip_bottom(1);
if use_tabline {
editor_area = editor_area.clip_top(1);
bufferline_area = bufferline_area.clip_top(1);
}
// -1 for bufferline
if use_bufferline { if use_bufferline {
editor_area = editor_area.clip_top(1); editor_area = editor_area.clip_top(1);
} }
@ -1528,10 +1546,14 @@ impl Component for EditorView {
// if the terminal size suddenly changed, we need to trigger a resize // if the terminal size suddenly changed, we need to trigger a resize
cx.editor.resize(editor_area); cx.editor.resize(editor_area);
if use_bufferline { if use_tabline {
Self::render_tabline(cx.editor, area.with_height(1), surface); Self::render_tabline(cx.editor, area.with_height(1), surface);
} }
if use_bufferline {
Self::render_bufferline(cx.editor, bufferline_area.with_height(1), surface);
}
for (view, is_focused) in cx.editor.tabs.curr_tree().views() { for (view, is_focused) in cx.editor.tabs.curr_tree().views() {
let doc = cx.editor.document(view.doc).unwrap(); let doc = cx.editor.document(view.doc).unwrap();
self.render_view(cx.editor, doc, view, area, surface, is_focused); self.render_view(cx.editor, doc, view, area, surface, is_focused);

@ -311,6 +311,8 @@ pub struct Config {
pub rulers: Vec<u16>, pub rulers: Vec<u16>,
#[serde(default)] #[serde(default)]
pub whitespace: WhitespaceConfig, pub whitespace: WhitespaceConfig,
/// Display open tabs along the top
pub tabline: TabLine,
/// Persistently display open buffers along the top /// Persistently display open buffers along the top
pub bufferline: BufferLine, pub bufferline: BufferLine,
/// Vertical indent width guides. /// Vertical indent width guides.
@ -625,6 +627,17 @@ impl Default for CursorShapeConfig {
} }
} }
/// tabline render modes
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum TabLine {
/// Always render
Always,
/// Only if multiple tabs are open
#[default]
Multiple,
}
/// bufferline render modes /// bufferline render modes
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
@ -898,6 +911,7 @@ impl Default for Config {
terminal: get_terminal_provider(), terminal: get_terminal_provider(),
rulers: Vec::new(), rulers: Vec::new(),
whitespace: WhitespaceConfig::default(), whitespace: WhitespaceConfig::default(),
tabline: TabLine::default(),
bufferline: BufferLine::default(), bufferline: BufferLine::default(),
indent_guides: IndentGuidesConfig::default(), indent_guides: IndentGuidesConfig::default(),
color_modes: false, color_modes: false,

@ -76,4 +76,14 @@ impl Tabs {
self.focus = id; self.focus = id;
id id
} }
#[inline]
pub fn len(&self) -> usize {
self.tabs.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.tabs.is_empty()
}
} }

Loading…
Cancel
Save