summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-07-02 21:57:49 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-07-02 21:57:49 -0700
commitc081af5121f648d32826c914a83ab2119f7885c9 (patch)
treeeb4299d0d130192d97358f39a1aa3a9836a6b176 /src
parent26a32afeae757c24d829e4fbe3f9c289f8156eca (diff)
Fix fragmented highlight styles
Diffstat (limited to 'src')
-rw-r--r--src/tui/markdown.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/tui/markdown.rs b/src/tui/markdown.rs
index 369380e..c913e9d 100644
--- a/src/tui/markdown.rs
+++ b/src/tui/markdown.rs
@@ -35,7 +35,8 @@ pub fn preprocess(input: String) -> String {
}
/// Preview markdown of the given length
-/// **Note**: Assumes preprocessing has taken place
+/// Currently removes any color (i.e. code highlighting) to avoid
+/// the jarring issue of a fragmented highlight style on focused items.
pub fn preview(width: usize, input: &StyledString) -> StyledString {
let mut w = 0;
let mut new_spans = Vec::new();
@@ -43,14 +44,14 @@ pub fn preview(width: usize, input: &StyledString) -> StyledString {
// Filter newlines
if span.width == 0 {
w += 1;
- new_spans.push(IndexedSpan {
+ new_spans.push(drop_color(IndexedSpan {
content: IndexedCow::Owned(" ".to_owned()),
width: 1,
..*span
- });
+ }));
} else {
w += span.width;
- new_spans.push(span.clone());
+ new_spans.push(drop_color(span.clone()));
}
if w > width {
break;
@@ -61,6 +62,16 @@ pub fn preview(width: usize, input: &StyledString) -> StyledString {
prev
}
+fn drop_color(span: StyledIndexedSpan) -> StyledIndexedSpan {
+ IndexedSpan {
+ attr: Style {
+ color: None,
+ ..span.attr
+ },
+ ..span
+ }
+}
+
/// Parse the given markdown text into a list of spans.
/// This is a shortcut for `Parser::new(preprocessed_input).collect()`.
fn parse_spans(input: &str) -> Vec<StyledIndexedSpan> {