diff --git a/src/edit/editor.rs b/src/edit/editor.rs index 357ff29..43360ef 100644 --- a/src/edit/editor.rs +++ b/src/edit/editor.rs @@ -23,7 +23,7 @@ pub struct Editor { cursor_x_opt: Option, select_opt: Option, cursor_moved: bool, - tab_width: usize, + tab_width: u16, change: Option, } @@ -258,11 +258,11 @@ impl Edit for Editor { } } - fn tab_width(&self) -> usize { + fn tab_width(&self) -> u16 { self.tab_width } - fn set_tab_width(&mut self, tab_width: usize) { + fn set_tab_width(&mut self, tab_width: u16) { // A tab width of 0 is not allowed if tab_width == 0 { return; @@ -679,6 +679,7 @@ impl Edit for Editor { }; // For every line in selection + let tab_width: usize = self.tab_width.into(); for line_i in start.line..=end.line { // Determine indexes of last indent and first character after whitespace let mut after_whitespace; @@ -691,7 +692,7 @@ impl Edit for Editor { for (count, (index, c)) in text.char_indices().enumerate() { if !c.is_whitespace() { after_whitespace = index; - required_indent = self.tab_width - (count % self.tab_width); + required_indent = tab_width - (count % tab_width); break; } } @@ -699,7 +700,7 @@ impl Edit for Editor { // No indent required (not possible?) if required_indent == 0 { - required_indent = self.tab_width; + required_indent = tab_width; } self.insert_at( @@ -748,6 +749,7 @@ impl Edit for Editor { }; // For every line in selection + let tab_width: usize = self.tab_width.into(); for line_i in start.line..=end.line { // Determine indexes of last indent and first character after whitespace let mut last_indent = 0; @@ -762,7 +764,7 @@ impl Edit for Editor { after_whitespace = index; break; } - if count % self.tab_width == 0 { + if count % tab_width == 0 { last_indent = index; } } diff --git a/src/edit/mod.rs b/src/edit/mod.rs index be93795..595c704 100644 --- a/src/edit/mod.rs +++ b/src/edit/mod.rs @@ -165,10 +165,10 @@ pub trait Edit { fn set_select_opt(&mut self, select_opt: Option); /// Get the current tab width - fn tab_width(&self) -> usize; + fn tab_width(&self) -> u16; /// Set the current tab width. A `tab_width` of 0 is not allowed, and will be ignored - fn set_tab_width(&mut self, tab_width: usize); + fn set_tab_width(&mut self, tab_width: u16); /// Shape lines until scroll, after adjusting scroll if the cursor moved fn shape_as_needed(&mut self, font_system: &mut FontSystem); diff --git a/src/edit/syntect.rs b/src/edit/syntect.rs index ff6ccd5..3125d12 100644 --- a/src/edit/syntect.rs +++ b/src/edit/syntect.rs @@ -166,11 +166,11 @@ impl<'a> Edit for SyntaxEditor<'a> { self.editor.set_select_opt(select_opt); } - fn tab_width(&self) -> usize { + fn tab_width(&self) -> u16 { self.editor.tab_width() } - fn set_tab_width(&mut self, tab_width: usize) { + fn set_tab_width(&mut self, tab_width: u16) { self.editor.set_tab_width(tab_width); } diff --git a/src/edit/vi.rs b/src/edit/vi.rs index 03bb840..118f0b5 100644 --- a/src/edit/vi.rs +++ b/src/edit/vi.rs @@ -272,11 +272,11 @@ impl<'a> Edit for ViEditor<'a> { self.editor.set_select_opt(select_opt); } - fn tab_width(&self) -> usize { + fn tab_width(&self) -> u16 { self.editor.tab_width() } - fn set_tab_width(&mut self, tab_width: usize) { + fn set_tab_width(&mut self, tab_width: u16) { self.editor.set_tab_width(tab_width); }