on master help sign in
Add ability to theme primary selecition
d70be55wojciechkepka
book/src/themes.md+1
@@ -89,6 +89,7 @@ Possible keys:
89| `ui.text.focus` | |
89| `ui.text.focus` | |
90| `ui.menu.selected` | |
90| `ui.menu.selected` | |
91| `ui.selection` | For selections in the editing area |
91| `ui.selection` | For selections in the editing area |
92+| `ui.selection.primary` | |
92| `warning` | LSP warning |
93| `warning` | LSP warning |
93| `error` | LSP error |
94| `error` | LSP error |
94| `info` | LSP info |
95| `info` | LSP info |
helix-term/src/ui/editor.rs+18−7
@@ -294,16 +294,27 @@ impl EditorView {
294 });
294 });
295
295
296 let selection_style = theme.get("ui.selection");
296 let selection_style = theme.get("ui.selection");
297+ let primary_style = theme
298+ .try_get("ui.selection.primary")
299+ .unwrap_or(selection_style);
300+ let selection = doc.selection(view.id);
301+ let primary_idx = selection.primary_index();
297
302
298− for selection in doc
303+ for (i, selection) in selection
299− .selection(view.id)
300 .iter()
304 .iter()
305+ .enumerate()
301− .filter(|range| range.overlaps(&screen))
306+ .filter(|(_, range)| range.overlaps(&screen))
302 {
307 {
303 // TODO: render also if only one of the ranges is in viewport
308 // TODO: render also if only one of the ranges is in viewport
304 let mut start = view.screen_coords_at_pos(doc, text, selection.anchor);
309 let mut start = view.screen_coords_at_pos(doc, text, selection.anchor);
305 let mut end = view.screen_coords_at_pos(doc, text, selection.head);
310 let mut end = view.screen_coords_at_pos(doc, text, selection.head);
306
311
312+ let style = if i != primary_idx {
313+ selection_style
314+ } else {
315+ primary_style
316+ };
317+
307 let head = end;
318 let head = end;
308
319
309 if selection.head < selection.anchor {
320 if selection.head < selection.anchor {
@@ -331,7 +342,7 @@ impl EditorView {
331 ),
342 ),
332 1,
343 1,
333 ),
344 ),
334− selection_style,
345+ style,
335 );
346 );
336 } else {
347 } else {
337 surface.set_style(
348 surface.set_style(
@@ -342,7 +353,7 @@ impl EditorView {
342 viewport.width.saturating_sub(start.col as u16),
353 viewport.width.saturating_sub(start.col as u16),
343 1,
354 1,
344 ),
355 ),
345− selection_style,
356+ style,
346 );
357 );
347 for i in start.row + 1..end.row {
358 for i in start.row + 1..end.row {
348 surface.set_style(
359 surface.set_style(
@@ -353,7 +364,7 @@ impl EditorView {
353 viewport.width,
364 viewport.width,
354 1,
365 1,
355 ),
366 ),
356− selection_style,
367+ style,
357 );
368 );
358 }
369 }
359 surface.set_style(
370 surface.set_style(
@@ -363,7 +374,7 @@ impl EditorView {
363 (end.col as u16).min(viewport.width),
374 (end.col as u16).min(viewport.width),
364 1,
375 1,
365 ),
376 ),
366− selection_style,
377+ style,
367 );
378 );
368 }
379 }
369
380
theme.toml+2−1
@@ -52,7 +52,8 @@
52"ui.text" = { fg = "#a4a0e8" } # lavender
52"ui.text" = { fg = "#a4a0e8" } # lavender
53"ui.text.focus" = { fg = "#dbbfef"} # lilac
53"ui.text.focus" = { fg = "#dbbfef"} # lilac
54
54
55−"ui.selection" = { bg = "#540099" }
55+"ui.selection" = { bg = "#44258b" }
56+"ui.selection.primary" = { bg = "#540099" }
56"ui.menu.selected" = { fg = "#281733", bg = "#ffffff" } # revolver
57"ui.menu.selected" = { fg = "#281733", bg = "#ffffff" } # revolver
57
58
58"warning" = "#ffcd1c"
59"warning" = "#ffcd1c"