From 681d34b9b9735eae62f514a2ae4152b72b37f488 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Mon, 13 Jun 2022 00:27:35 -0400 Subject: [PATCH 01/18] initial implementation of bufferline --- helix-term/src/ui/editor.rs | 59 ++++++++++++++++++++++++++++++++++--- helix-view/src/editor.rs | 3 ++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index f074d9f1c97f..5ee44c59e7a6 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -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; @@ -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 @@ -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); 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)); + Self::render_tabs(editor, doc, view, tabs_area, surface, theme); + } + if is_focused { Self::render_focused_view_elements(view, doc, inner, theme, surface); } @@ -541,6 +554,44 @@ impl EditorView { } } + /// Render bufferline at the top + pub fn render_tabs( + editor: &Editor, + doc: &Document, + view: &View, + viewport: Rect, + surface: &mut Surface, + theme: &Theme, + ) { + let pb = PathBuf::from(" [scratch] "); // default filename to use for scratch buffer + surface.clear_with(viewport, theme.get("ui.statusline")); + let mut len = 0usize; + editor.documents().for_each(|doc| { + let fname = doc + .path() + .unwrap_or_else(|| &pb) + .file_name() + .unwrap_or_default() + .to_str() + .unwrap(); + + let style = if view.doc == doc.id() { + theme.get("ui.background") + } else { + theme.get("ui.statusline") + }; + + surface.set_string( + 1 + viewport.x + len as u16, + viewport.y, + format!(" {fname} "), + style, + ); + + len += fname.len() + 2; // add some padding between tabs + }); + } + pub fn render_gutter( editor: &Editor, doc: &Document, diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 8e53936a4197..bebd8f186b21 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -152,6 +152,8 @@ pub struct Config { pub rulers: Vec, #[serde(default)] pub whitespace: WhitespaceConfig, + /// Persistently display open buffers with tabs + pub tabs: bool, } #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] @@ -387,6 +389,7 @@ impl Default for Config { lsp: LspConfig::default(), rulers: Vec::new(), whitespace: WhitespaceConfig::default(), + tabs: true, } } } From fc8df1894941bacd6c2662c48fa4df1ed18ab643 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Mon, 13 Jun 2022 00:38:16 -0400 Subject: [PATCH 02/18] fixed lint --- helix-term/src/ui/editor.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 5ee44c59e7a6..8d634df40179 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -146,7 +146,7 @@ impl EditorView { if editor.config().tabs { let tabs_area = view.area.clip_bottom(view.area.height.saturating_sub(1)); - Self::render_tabs(editor, doc, view, tabs_area, surface, theme); + Self::render_tabs(editor, view, tabs_area, surface, theme); } if is_focused { @@ -557,7 +557,6 @@ impl EditorView { /// Render bufferline at the top pub fn render_tabs( editor: &Editor, - doc: &Document, view: &View, viewport: Rect, surface: &mut Surface, From 860ec7c5944c88d32689af6751125f40955e48b9 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Mon, 13 Jun 2022 15:18:22 -0400 Subject: [PATCH 03/18] changed to 'bufferline', added enum for config modes, some cleanup --- book/src/configuration.md | 1 + helix-term/src/ui/editor.rs | 62 ++++++++++++++++++------------------- helix-view/src/editor.rs | 24 ++++++++++++-- 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index 4d7e440a09fe..e17a8ac18a91 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -45,6 +45,7 @@ hidden = false | `auto-info` | Whether to display infoboxes | `true` | | `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` | +| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `multiple` ### `[editor.lsp]` Section diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 8d634df40179..20ef07994c2d 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -75,16 +75,8 @@ impl EditorView { surface: &mut Surface, is_focused: bool, ) { - 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 inner = view.inner_area(); + let area = view.area; let theme = &editor.theme; // DAP: Highlight current stack frame position @@ -144,11 +136,6 @@ impl EditorView { Self::render_gutter(editor, doc, view, area, surface, theme, is_focused); 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)); - Self::render_tabs(editor, view, tabs_area, surface, theme); - } - if is_focused { Self::render_focused_view_elements(view, doc, inner, theme, surface); } @@ -555,17 +542,11 @@ 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 - surface.clear_with(viewport, theme.get("ui.statusline")); + pub fn render_bufferline(editor: &Editor, viewport: Rect, surface: &mut Surface) { + let pb = PathBuf::from(SCRATCH_BUFFER_NAME); // default filename to use for scratch buffer + surface.clear_with(viewport, editor.theme.get("ui.statusline")); let mut len = 0usize; - editor.documents().for_each(|doc| { + for doc in editor.documents() { let fname = doc .path() .unwrap_or_else(|| &pb) @@ -574,21 +555,21 @@ impl EditorView { .to_str() .unwrap(); - let style = if view.doc == doc.id() { - theme.get("ui.background") + let style = if view!(editor).doc == doc.id() { + editor.theme.get("ui.background") } else { - theme.get("ui.statusline") + editor.theme.get("ui.statusline") }; surface.set_string( 1 + viewport.x + len as u16, viewport.y, - format!(" {fname} "), + format!(" {} ", fname), style, ); len += fname.len() + 2; // add some padding between tabs - }); + } } pub fn render_gutter( @@ -1361,8 +1342,27 @@ impl Component for EditorView { // clear with background color surface.set_style(area, cx.editor.theme.get("ui.background")); 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().count() > 1 => true, + _ => false, + }; + + // -1 for commandline and -1 for bufferline + let editor_area = if use_bufferline { + area.clip_bottom(1).clip_top(1) + } else { + area.clip_bottom(1) + }; // if the terminal size suddenly changed, we need to trigger a resize - cx.editor.resize(area.clip_bottom(1)); // -1 from bottom for commandline + cx.editor.resize(editor_area); + + if use_bufferline { + Self::render_bufferline(cx.editor, area.with_height(1), surface); + } for (view, is_focused) in cx.editor.tree.views() { let doc = cx.editor.document(view.doc).unwrap(); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index bebd8f186b21..218de37b3c27 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -152,8 +152,8 @@ pub struct Config { pub rulers: Vec, #[serde(default)] pub whitespace: WhitespaceConfig, - /// Persistently display open buffers with tabs - pub tabs: bool, + /// Persistently display open buffers along the top + pub bufferline: BufferLine, } #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] @@ -225,6 +225,24 @@ impl Default for CursorShapeConfig { } } +/// bufferline render modes +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum BufferLine { + /// Don't render bufferline + Never, + /// Always render + Always, + /// Only if multiple buffers are open + Multiple, +} + +impl Default for BufferLine { + fn default() -> Self { + BufferLine::Multiple + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub enum LineNumber { @@ -389,7 +407,7 @@ impl Default for Config { lsp: LspConfig::default(), rulers: Vec::new(), whitespace: WhitespaceConfig::default(), - tabs: true, + bufferline: BufferLine::default(), } } } From 4cb66c39a4a6ced08d5181e67bf3fd509cca30a0 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Mon, 13 Jun 2022 15:43:04 -0400 Subject: [PATCH 04/18] fixed lint --- helix-term/src/ui/editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 20ef07994c2d..e3cbce986311 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -549,7 +549,7 @@ impl EditorView { for doc in editor.documents() { let fname = doc .path() - .unwrap_or_else(|| &pb) + .unwrap_or(&pb) .file_name() .unwrap_or_default() .to_str() From 479823d4a21f5749f618534b3be66d8a78006485 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Mon, 13 Jun 2022 18:05:58 -0400 Subject: [PATCH 05/18] added file modification indicator --- helix-term/src/ui/editor.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index e3cbce986311..4736bf33dca3 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -564,11 +564,18 @@ impl EditorView { surface.set_string( 1 + viewport.x + len as u16, viewport.y, - format!(" {} ", fname), + format!(" {} {}", fname, if doc.is_modified() { "● " } else { "" }), style, ); - len += fname.len() + 2; // add some padding between tabs + let (text, offset) = if doc.is_modified() { + (format!(" {} ● ", fname), fname.len() + 4) + } else { + (format!(" {} ", fname), fname.len() + 2) + }; + + surface.set_string(1 + viewport.x + len as u16, viewport.y, text, style); + len += offset; } } From a2c619921190198bc71e19d01e3c3d8d0fad36dd Mon Sep 17 00:00:00 2001 From: aaron404 Date: Tue, 14 Jun 2022 10:08:23 -0400 Subject: [PATCH 06/18] removed redundant code, added proper themeing with fallback, changed 'file modified' indicator --- book/src/configuration.md | 2 +- helix-term/src/ui/editor.rs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index e17a8ac18a91..27d74bc7ea06 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -45,7 +45,7 @@ hidden = false | `auto-info` | Whether to display infoboxes | `true` | | `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` | -| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `multiple` +| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `multiple` | ### `[editor.lsp]` Section diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 4736bf33dca3..8ed507c3e399 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -556,20 +556,21 @@ impl EditorView { .unwrap(); let style = if view!(editor).doc == doc.id() { - editor.theme.get("ui.background") + // editor.theme.get("ui.background") + editor + .theme + .try_get("ui.bufferline.active") + .unwrap_or_else(|| editor.theme.get("ui.background")) } else { - editor.theme.get("ui.statusline") + // editor.theme.get("ui.statusline") + editor + .theme + .try_get("ui.bufferline") + .unwrap_or_else(|| editor.theme.get("ui.statusline")) }; - surface.set_string( - 1 + viewport.x + len as u16, - viewport.y, - format!(" {} {}", fname, if doc.is_modified() { "● " } else { "" }), - style, - ); - let (text, offset) = if doc.is_modified() { - (format!(" {} ● ", fname), fname.len() + 4) + (format!(" {}[+] ", fname), fname.len() + 5) } else { (format!(" {} ", fname), fname.len() + 2) }; From 2bbd3164db44afcb329b360701d5b3b9e15d9544 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Wed, 22 Jun 2022 21:48:18 -0400 Subject: [PATCH 07/18] remove commented code --- helix-term/src/ui/editor.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 8ed507c3e399..81002ace62f4 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -556,13 +556,11 @@ impl EditorView { .unwrap(); let style = if view!(editor).doc == doc.id() { - // editor.theme.get("ui.background") editor .theme .try_get("ui.bufferline.active") .unwrap_or_else(|| editor.theme.get("ui.background")) } else { - // editor.theme.get("ui.statusline") editor .theme .try_get("ui.bufferline") From ecb9c23d54bc7530921194052dbb638c95290d14 Mon Sep 17 00:00:00 2001 From: aaron404 <54856541+aaron404@users.noreply.github.com> Date: Thu, 23 Jun 2022 16:23:16 -0400 Subject: [PATCH 08/18] Update helix-term/src/ui/editor.rs simplify text and offset computation Co-authored-by: Gokul Soumya --- helix-term/src/ui/editor.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 99d31a638f61..0c9f350e61e5 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -604,11 +604,8 @@ impl EditorView { .unwrap_or_else(|| editor.theme.get("ui.statusline")) }; - let (text, offset) = if doc.is_modified() { - (format!(" {}[+] ", fname), fname.len() + 5) - } else { - (format!(" {} ", fname), fname.len() + 2) - }; + let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" }); + let offset = text.len(); surface.set_string(1 + viewport.x + len as u16, viewport.y, text, style); len += offset; From f39b2faf09d8f14a2563fd6c53069acb6bc9741a Mon Sep 17 00:00:00 2001 From: aaron404 <54856541+aaron404@users.noreply.github.com> Date: Tue, 28 Jun 2022 17:25:08 -0400 Subject: [PATCH 09/18] add ui.bufferline.background key for themes Co-authored-by: lazytanuki <43273245+lazytanuki@users.noreply.github.com> --- helix-term/src/ui/editor.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 0c9f350e61e5..9f3d8aa26cd4 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -581,7 +581,13 @@ impl EditorView { /// Render bufferline at the top pub fn render_bufferline(editor: &Editor, viewport: Rect, surface: &mut Surface) { let pb = PathBuf::from(SCRATCH_BUFFER_NAME); // default filename to use for scratch buffer - surface.clear_with(viewport, editor.theme.get("ui.statusline")); + surface.clear_with( + viewport, + editor + .theme + .try_get("ui.bufferline.background") + .unwrap_or_else(|| editor.theme.get("ui.statusline")), + ); let mut len = 0usize; for doc in editor.documents() { let fname = doc From d80a9fd6cb4d705d4506c0f6c5b23e264241955b Mon Sep 17 00:00:00 2001 From: aaron404 Date: Wed, 29 Jun 2022 00:36:42 -0400 Subject: [PATCH 10/18] address PR comments --- helix-term/src/ui/editor.rs | 12 ++++++++---- helix-view/src/editor.rs | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 81002ace62f4..b0c07365f74d 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -543,17 +543,17 @@ impl EditorView { /// Render bufferline at the top pub fn render_bufferline(editor: &Editor, viewport: Rect, surface: &mut Surface) { - let pb = PathBuf::from(SCRATCH_BUFFER_NAME); // default filename to use for scratch buffer + let scratch = PathBuf::from(SCRATCH_BUFFER_NAME); // default filename to use for scratch buffer surface.clear_with(viewport, editor.theme.get("ui.statusline")); let mut len = 0usize; for doc in editor.documents() { let fname = doc .path() - .unwrap_or(&pb) + .unwrap_or(&scratch) .file_name() .unwrap_or_default() .to_str() - .unwrap(); + .unwrap_or_default(); let style = if view!(editor).doc == doc.id() { editor @@ -575,6 +575,10 @@ impl EditorView { surface.set_string(1 + viewport.x + len as u16, viewport.y, text, style); len += offset; + + if len > surface.area.width as usize { + break; + } } } @@ -1353,7 +1357,7 @@ impl Component for EditorView { use helix_view::editor::BufferLine; let use_bufferline = match config.bufferline { BufferLine::Always => true, - BufferLine::Multiple if cx.editor.documents().count() > 1 => true, + BufferLine::Multiple if cx.editor.documents.len() > 1 => true, _ => false, }; diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 218de37b3c27..e16953439b79 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -239,7 +239,7 @@ pub enum BufferLine { impl Default for BufferLine { fn default() -> Self { - BufferLine::Multiple + BufferLine::Never } } From 8dfb9fe51864ba4432aaa260ec7aff11af71496e Mon Sep 17 00:00:00 2001 From: aaron404 <54856541+aaron404@users.noreply.github.com> Date: Wed, 29 Jun 2022 00:51:24 -0400 Subject: [PATCH 11/18] Update helix-term/src/ui/editor.rs --- helix-term/src/ui/editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index b34e4c71f8cd..d3324bd7b8a8 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -580,7 +580,7 @@ impl EditorView { /// Render bufferline at the top pub fn render_bufferline(editor: &Editor, viewport: Rect, surface: &mut Surface) { - let editor = PathBuf::from(SCRATCH_BUFFER_NAME); // default filename to use for scratch buffer + let scratch = PathBuf::from(SCRATCH_BUFFER_NAME); // default filename to use for scratch buffer surface.clear_with( viewport, editor From db5f30a4d373bdcb228aab6a54137368c6f81070 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Wed, 29 Jun 2022 17:41:38 -0400 Subject: [PATCH 12/18] simplify computation of editor area: --- helix-term/src/ui/editor.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index d3324bd7b8a8..8a4592e10cdc 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1400,11 +1400,11 @@ impl Component for EditorView { }; // -1 for commandline and -1 for bufferline - let editor_area = if use_bufferline { - area.clip_bottom(1).clip_top(1) - } else { - area.clip_bottom(1) - }; + let mut editor_area = area.clip_bottom(1); + if use_bufferline { + editor_area = editor_area.clip_top(1); + } + // if the terminal size suddenly changed, we need to trigger a resize cx.editor.resize(editor_area); From 7ff2ff54951e4b718e288f7e8a3bb960d66ad0bf Mon Sep 17 00:00:00 2001 From: aaron404 Date: Sun, 3 Jul 2022 14:21:41 -0400 Subject: [PATCH 13/18] change to set_stringn to avoid overflow --- helix-term/src/ui/editor.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 8a4592e10cdc..83f7f57f30d9 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -613,7 +613,14 @@ impl EditorView { let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" }); let offset = text.len(); - surface.set_string(1 + viewport.x + len as u16, viewport.y, text, style); + surface.set_stringn( + 1 + viewport.x + len as u16, + viewport.y, + text, + surface.area.width as usize, + style, + ); + len += offset; if len > surface.area.width as usize { From 8d59fe9c620010d5e23e411dc045e5f8e40cacfb Mon Sep 17 00:00:00 2001 From: Seth Bromberger Date: Fri, 22 Jul 2022 09:54:50 +0100 Subject: [PATCH 14/18] Update configuration.md Updates documentation to reflect decision re: defaulting to never showing bufferline. --- book/src/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index afd0e700559f..2ad07399f001 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -46,7 +46,7 @@ hidden = false | `auto-info` | Whether to display infoboxes | `true` | | `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` | -| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `multiple` | +| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` | | `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | ### `[editor.lsp]` Section From 0cb3dff2faa7e55a3f5ee33113dd328dc9f7a0d8 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Sun, 24 Jul 2022 17:46:08 -0400 Subject: [PATCH 15/18] addressed pr comments --- book/src/configuration.md | 2 +- helix-term/src/ui/editor.rs | 40 ++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index afd0e700559f..2ad07399f001 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -46,7 +46,7 @@ hidden = false | `auto-info` | Whether to display infoboxes | `true` | | `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` | -| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `multiple` | +| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` | | `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | ### `[editor.lsp]` Section diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 35108536398a..6ba62c08da00 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -592,7 +592,18 @@ impl EditorView { .try_get("ui.bufferline.background") .unwrap_or_else(|| editor.theme.get("ui.statusline")), ); - let mut len = 0usize; + + let bufferline_active = editor + .theme + .try_get("ui.bufferline.active") + .unwrap_or_else(|| editor.theme.get("ui.background")); + + let bufferline_inactive = editor + .theme + .try_get("ui.bufferline") + .unwrap_or_else(|| editor.theme.get("ui.statusline")); + + let mut x = viewport.x; for doc in editor.documents() { let fname = doc .path() @@ -603,31 +614,20 @@ impl EditorView { .unwrap_or_default(); let style = if view!(editor).doc == doc.id() { - editor - .theme - .try_get("ui.bufferline.active") - .unwrap_or_else(|| editor.theme.get("ui.background")) + bufferline_active } else { - editor - .theme - .try_get("ui.bufferline") - .unwrap_or_else(|| editor.theme.get("ui.statusline")) + bufferline_inactive }; let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" }); - let offset = text.len(); - - surface.set_stringn( - 1 + viewport.x + len as u16, - viewport.y, - text, - surface.area.width as usize, - style, - ); + let used_width = viewport.x.saturating_sub(x); + let rem_width = surface.area.width.saturating_sub(used_width); - len += offset; + x = surface + .set_stringn(x, viewport.y, text, rem_width as usize, style) + .0; - if len > surface.area.width as usize { + if x >= surface.area.right() { break; } } From ec6d12f5869fffea8c397705e8a7b9c9b5219094 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Wed, 27 Jul 2022 00:47:33 -0400 Subject: [PATCH 16/18] fix build error --- helix-term/src/ui/editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 781c4e0ba2f3..845e127e9295 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -16,7 +16,7 @@ use helix_core::{ LineEnding, Position, Range, Selection, Transaction, }; use helix_view::{ - document::Mode, + document::{Mode, SCRATCH_BUFFER_NAME}, editor::{CompleteAction, CursorShapeConfig}, graphics::{Color, CursorKind, Modifier, Rect, Style}, input::KeyEvent, From 042805db434d1ddace68f5bf938f0b2588be66f2 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Wed, 31 Aug 2022 19:23:25 -0400 Subject: [PATCH 17/18] address pr comments --- helix-term/src/ui/editor.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 845e127e9295..be92b4463a67 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -606,14 +606,16 @@ impl EditorView { let bufferline_active = editor .theme .try_get("ui.bufferline.active") - .unwrap_or_else(|| editor.theme.get("ui.background")); + .unwrap_or_else(|| editor.theme.get("ui.statusline.active")); let bufferline_inactive = editor .theme .try_get("ui.bufferline") - .unwrap_or_else(|| editor.theme.get("ui.statusline")); + .unwrap_or_else(|| editor.theme.get("ui.statusline.inactive")); let mut x = viewport.x; + let current_doc = view!(editor).doc; + for doc in editor.documents() { let fname = doc .path() @@ -623,7 +625,7 @@ impl EditorView { .to_str() .unwrap_or_default(); - let style = if view!(editor).doc == doc.id() { + let style = if current_doc == doc.id() { bufferline_active } else { bufferline_inactive From 12846be043c3fbb28c8900151f87cbfa829ca5f4 Mon Sep 17 00:00:00 2001 From: aaron404 Date: Wed, 31 Aug 2022 19:41:29 -0400 Subject: [PATCH 18/18] revert accidental change --- helix-term/src/ui/editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index be92b4463a67..d1c7baac89c2 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -138,7 +138,7 @@ impl EditorView { highlights, &editor.config(), ); - Self::render_gutter(editor, doc, view, area, surface, theme, is_focused); + Self::render_gutter(editor, doc, view, view.area, surface, theme, is_focused); Self::render_rulers(editor, doc, view, inner, surface, theme); if is_focused {