Skip to content

Commit

Permalink
Avoid repeatedly loading config
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Nov 19, 2022
1 parent 8be2d1d commit a640ab6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
17 changes: 5 additions & 12 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl EditorView {
let inner = view.inner_area(doc);
let area = view.area;
let theme = &editor.theme;
let config = editor.config();

// DAP: Highlight current stack frame position
let stack_frame = editor.debugger.as_ref().and_then(|debugger| {
Expand Down Expand Up @@ -117,10 +118,10 @@ impl EditorView {
}
}

if is_focused && editor.config().cursorline {
if is_focused && config.cursorline {
Self::highlight_cursorline(doc, view, surface, theme);
}
if is_focused && editor.config().cursorcolumn {
if is_focused && config.cursorcolumn {
Self::highlight_cursorcolumn(doc, view, surface, theme);
}

Expand All @@ -141,22 +142,14 @@ impl EditorView {
doc,
view,
theme,
&editor.config().cursor_shape,
&config.cursor_shape,
),
))
} else {
Box::new(highlights)
};

Self::render_text_highlights(
doc,
view.offset,
inner,
surface,
theme,
highlights,
&editor.config(),
);
Self::render_text_highlights(doc, view.offset, inner, surface, theme, highlights, &config);
Self::render_gutter(editor, doc, view, view.area, surface, theme, is_focused);
Self::render_rulers(editor, doc, view, inner, surface, theme);

Expand Down
13 changes: 8 additions & 5 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface

// Left side of the status line.

let element_ids = &context.editor.config().statusline.left;
let config = context.editor.config();

let element_ids = &config.statusline.left;
element_ids
.iter()
.map(|element_id| get_render_function(*element_id))
Expand All @@ -84,7 +86,7 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface

// Right side of the status line.

let element_ids = &context.editor.config().statusline.right;
let element_ids = &config.statusline.right;
element_ids
.iter()
.map(|element_id| get_render_function(*element_id))
Expand All @@ -102,7 +104,7 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface

// Center of the status line.

let element_ids = &context.editor.config().statusline.center;
let element_ids = &config.statusline.center;
element_ids
.iter()
.map(|element_id| get_render_function(*element_id))
Expand Down Expand Up @@ -160,7 +162,8 @@ where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let visible = context.focused;
let modenames = &context.editor.config().statusline.mode;
let config = context.editor.config();
let modenames = &config.statusline.mode;
write(
context,
format!(
Expand All @@ -176,7 +179,7 @@ where
" "
}
),
if visible && context.editor.config().color_modes {
if visible && config.color_modes {
match context.editor.mode() {
Mode::Insert => Some(context.editor.theme.get("ui.statusline.insert")),
Mode::Select => Some(context.editor.theme.get("ui.statusline.select")),
Expand Down

0 comments on commit a640ab6

Please sign in to comment.