summaryrefslogtreecommitdiff
path: root/src/widgets/luaeditor
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/luaeditor')
-rw-r--r--src/widgets/luaeditor/buffer.rs10
-rw-r--r--src/widgets/luaeditor/mod.rs25
-rw-r--r--src/widgets/luaeditor/treesitter.rs4
3 files changed, 25 insertions, 14 deletions
diff --git a/src/widgets/luaeditor/buffer.rs b/src/widgets/luaeditor/buffer.rs
index 3f59b6c..1af0c08 100644
--- a/src/widgets/luaeditor/buffer.rs
+++ b/src/widgets/luaeditor/buffer.rs
@@ -18,7 +18,7 @@ impl Buffer {
fn refresh_line_max(&mut self) {
self.cursor
- .set_x_max(self.lines[self.cursor.y() as usize].len())
+ .set_x_max(self.lines[self.cursor.y()].len())
}
fn refresh_buffer_max(&mut self) {
@@ -39,7 +39,7 @@ impl Buffer {
s.starts_with(&(str.clone() + "if "))
|| s.starts_with(&(str.clone() + "for "))
|| s.starts_with(&(str.clone() + "while "))
- || (s.starts_with(&str) && s.contains("function(") && s.ends_with(")"))
+ || (s.starts_with(&str) && s.contains("function(") && s.ends_with(')'))
})
.count();
@@ -66,7 +66,7 @@ impl Buffer {
let l = a.trim();
let insert_end = (l.starts_with("if ") && l.ends_with(" then"))
|| ((l.starts_with("for ") || l.starts_with("while ")) && l.ends_with(" do"))
- || (l.contains("function(") && l.ends_with(")"));
+ || (l.contains("function(") && l.ends_with(')'));
let extra_indent = if insert_end { 1 } else { 0 };
@@ -126,11 +126,11 @@ impl Buffer {
}
pub fn current_line(&self) -> &String {
- self.line(self.cursor.y() as usize).unwrap()
+ self.line(self.cursor.y()).unwrap()
}
fn current_line_mut(&mut self) -> &mut String {
- self.line_mut(self.cursor.y() as usize).unwrap()
+ self.line_mut(self.cursor.y()).unwrap()
}
pub fn cursor(&self) -> &Cursor {
diff --git a/src/widgets/luaeditor/mod.rs b/src/widgets/luaeditor/mod.rs
index 98af9e5..939a65f 100644
--- a/src/widgets/luaeditor/mod.rs
+++ b/src/widgets/luaeditor/mod.rs
@@ -97,10 +97,10 @@ impl Widget for &mut LuaEditor {
let highlights = treesitter::highlighter_split(text.as_bytes(), &self.highlight_config);
let nr_width = (self.buffer.lines().len().to_string().len() + 1).max(4) as u16;
- let mut text_area = inner_area.clone();
+ let mut text_area = inner_area;
text_area.x += nr_width;
- let mut span_area = text_area.clone();
+ let mut span_area = text_area;
let mut current_line = 0;
for (hl, group) in highlights.iter() {
@@ -112,7 +112,7 @@ impl Widget for &mut LuaEditor {
current_line += 1;
} else if current_line >= self.scroll {
- let group = group.replace("\t", " ");
+ let group = group.replace('\t', " ");
let span = group.to_span();
if inner_area.contains(span_area.into()) {
@@ -124,7 +124,7 @@ impl Widget for &mut LuaEditor {
}
for i in self.scroll..self.buffer.lines().len() {
- let mut nr_area = span_area.clone();
+ let mut nr_area = span_area;
nr_area.x = inner_area.x;
nr_area.width = nr_width - 1;
nr_area.y = inner_area.y + (i - self.scroll) as u16;
@@ -137,7 +137,7 @@ impl Widget for &mut LuaEditor {
(i + 1).to_line().right_aligned().render(nr_area, buf);
}
- let mut cursor_area = text_area.clone();
+ let mut cursor_area = text_area;
cursor_area.width = 1;
cursor_area.height = 1;
cursor_area.y += self.buffer.cursor().y() as u16;
@@ -146,7 +146,7 @@ impl Widget for &mut LuaEditor {
let (first, _) = self
.buffer
.current_line()
- .split_at(self.buffer.cursor().x() as usize);
+ .split_at(self.buffer.cursor().x());
for c in first.chars() {
if c == '\t' {
@@ -166,7 +166,7 @@ impl Widget for &mut LuaEditor {
self.buffer
.current_line()
.chars()
- .nth(self.buffer.cursor().x() as usize)
+ .nth(self.buffer.cursor().x())
.map(|c| if c == '\t' { ' ' } else { c })
.unwrap_or(' ')
.to_span()
@@ -175,3 +175,14 @@ impl Widget for &mut LuaEditor {
}
}
}
+
+impl Default for LuaEditor {
+ fn default() -> Self {
+ Self {
+ highlight_config: treesitter::new_highlight_configuration(),
+ bar: StatusBar::default(),
+ scroll: 0,
+ buffer: Buffer::default(),
+ }
+ }
+}
diff --git a/src/widgets/luaeditor/treesitter.rs b/src/widgets/luaeditor/treesitter.rs
index 1a4dc04..1474434 100644
--- a/src/widgets/luaeditor/treesitter.rs
+++ b/src/widgets/luaeditor/treesitter.rs
@@ -1,6 +1,6 @@
use tree_sitter_highlight::{Highlight, HighlightConfiguration, HighlightEvent, Highlighter};
-static HIGHLIGHT_NAMES: [&'static str; 29] = [
+static HIGHLIGHT_NAMES: [&str; 29] = [
"attribute",
"boolean",
"comment",
@@ -71,7 +71,7 @@ pub fn highlighter_split<'a>(
splits.push((current, "\n"));
}
- if !group.ends_with("\n") {
+ if !group.ends_with('\n') {
splits.pop();
}
}