Highlight first line of multi-line comments
This commit is contained in:
parent
8169adcb2f
commit
62df35a751
@ -24,11 +24,15 @@ pub struct Position {
|
|||||||
pub y: usize,
|
pub y: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The message to display on the status line */
|
||||||
struct StatusMessage {
|
struct StatusMessage {
|
||||||
text: String,
|
text: String,
|
||||||
time: Instant,
|
time: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add methods to the StatusMessage
|
||||||
|
*/
|
||||||
impl StatusMessage {
|
impl StatusMessage {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::from("")
|
Self::from("")
|
||||||
@ -42,6 +46,7 @@ impl StatusMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The main editor object
|
||||||
pub struct Editor {
|
pub struct Editor {
|
||||||
should_quit: bool,
|
should_quit: bool,
|
||||||
terminal: Terminal,
|
terminal: Terminal,
|
||||||
|
@ -147,6 +147,6 @@ impl HighlightingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn multiline_comments(&self) -> bool {
|
pub fn multiline_comments(&self) -> bool {
|
||||||
&self.multiline_comments
|
self.multiline_comments
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
32
src/row.rs
32
src/row.rs
@ -356,6 +356,37 @@ impl Row {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::indexing_slicing, clippy::integer_arithmetic)]
|
||||||
|
fn highlight_multiline_comment(
|
||||||
|
&mut self,
|
||||||
|
index: &mut usize,
|
||||||
|
opts: &HighlightingOptions,
|
||||||
|
c: char,
|
||||||
|
chars: &[char],
|
||||||
|
) -> bool {
|
||||||
|
if opts.multiline_comments() && c == '/' && *index < chars.len() {
|
||||||
|
if let Some(next_char) = chars.get(index.saturating_add(1)) {
|
||||||
|
if *next_char == '*' {
|
||||||
|
let closing_index =
|
||||||
|
if let Some(closing_index) = self.string[*index + 2..].find("*/") {
|
||||||
|
*index + closing_index + 4
|
||||||
|
} else {
|
||||||
|
chars.len()
|
||||||
|
};
|
||||||
|
|
||||||
|
for _ in *index..closing_index {
|
||||||
|
self.highlighting.push(highlighting::Type::MultilineComment);
|
||||||
|
*index +=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
fn highlight_string(
|
fn highlight_string(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: &mut usize,
|
index: &mut usize,
|
||||||
@ -427,6 +458,7 @@ impl Row {
|
|||||||
while let Some(c) = chars.get(index) {
|
while let Some(c) = chars.get(index) {
|
||||||
if self.highlight_char(&mut index, opts, *c, &chars)
|
if self.highlight_char(&mut index, opts, *c, &chars)
|
||||||
|| self.highlight_comment(&mut index, opts, *c, &chars)
|
|| self.highlight_comment(&mut index, opts, *c, &chars)
|
||||||
|
|| self.highlight_multiline_comment(&mut index, opts, *c, &chars)
|
||||||
|| self.highlight_primary_keywords(&mut index, &opts, &chars)
|
|| self.highlight_primary_keywords(&mut index, &opts, &chars)
|
||||||
|| self.highlight_secondary_keywords(&mut index, &opts, &chars)
|
|| self.highlight_secondary_keywords(&mut index, &opts, &chars)
|
||||||
|| self.highlight_string(&mut index, opts, *c, &chars)
|
|| self.highlight_string(&mut index, opts, *c, &chars)
|
||||||
|
Loading…
Reference in New Issue
Block a user