Edit: use u16 for tab_width
This commit is contained in:
parent
8024cbe504
commit
1207fd6d80
4 changed files with 14 additions and 12 deletions
|
|
@ -23,7 +23,7 @@ pub struct Editor {
|
||||||
cursor_x_opt: Option<i32>,
|
cursor_x_opt: Option<i32>,
|
||||||
select_opt: Option<Cursor>,
|
select_opt: Option<Cursor>,
|
||||||
cursor_moved: bool,
|
cursor_moved: bool,
|
||||||
tab_width: usize,
|
tab_width: u16,
|
||||||
change: Option<Change>,
|
change: Option<Change>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,11 +258,11 @@ impl Edit for Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_width(&self) -> usize {
|
fn tab_width(&self) -> u16 {
|
||||||
self.tab_width
|
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
|
// A tab width of 0 is not allowed
|
||||||
if tab_width == 0 {
|
if tab_width == 0 {
|
||||||
return;
|
return;
|
||||||
|
|
@ -679,6 +679,7 @@ impl Edit for Editor {
|
||||||
};
|
};
|
||||||
|
|
||||||
// For every line in selection
|
// For every line in selection
|
||||||
|
let tab_width: usize = self.tab_width.into();
|
||||||
for line_i in start.line..=end.line {
|
for line_i in start.line..=end.line {
|
||||||
// Determine indexes of last indent and first character after whitespace
|
// Determine indexes of last indent and first character after whitespace
|
||||||
let mut after_whitespace;
|
let mut after_whitespace;
|
||||||
|
|
@ -691,7 +692,7 @@ impl Edit for Editor {
|
||||||
for (count, (index, c)) in text.char_indices().enumerate() {
|
for (count, (index, c)) in text.char_indices().enumerate() {
|
||||||
if !c.is_whitespace() {
|
if !c.is_whitespace() {
|
||||||
after_whitespace = index;
|
after_whitespace = index;
|
||||||
required_indent = self.tab_width - (count % self.tab_width);
|
required_indent = tab_width - (count % tab_width);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -699,7 +700,7 @@ impl Edit for Editor {
|
||||||
|
|
||||||
// No indent required (not possible?)
|
// No indent required (not possible?)
|
||||||
if required_indent == 0 {
|
if required_indent == 0 {
|
||||||
required_indent = self.tab_width;
|
required_indent = tab_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.insert_at(
|
self.insert_at(
|
||||||
|
|
@ -748,6 +749,7 @@ impl Edit for Editor {
|
||||||
};
|
};
|
||||||
|
|
||||||
// For every line in selection
|
// For every line in selection
|
||||||
|
let tab_width: usize = self.tab_width.into();
|
||||||
for line_i in start.line..=end.line {
|
for line_i in start.line..=end.line {
|
||||||
// Determine indexes of last indent and first character after whitespace
|
// Determine indexes of last indent and first character after whitespace
|
||||||
let mut last_indent = 0;
|
let mut last_indent = 0;
|
||||||
|
|
@ -762,7 +764,7 @@ impl Edit for Editor {
|
||||||
after_whitespace = index;
|
after_whitespace = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if count % self.tab_width == 0 {
|
if count % tab_width == 0 {
|
||||||
last_indent = index;
|
last_indent = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,10 +165,10 @@ pub trait Edit {
|
||||||
fn set_select_opt(&mut self, select_opt: Option<Cursor>);
|
fn set_select_opt(&mut self, select_opt: Option<Cursor>);
|
||||||
|
|
||||||
/// Get the current tab width
|
/// 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
|
/// 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
|
/// Shape lines until scroll, after adjusting scroll if the cursor moved
|
||||||
fn shape_as_needed(&mut self, font_system: &mut FontSystem);
|
fn shape_as_needed(&mut self, font_system: &mut FontSystem);
|
||||||
|
|
|
||||||
|
|
@ -166,11 +166,11 @@ impl<'a> Edit for SyntaxEditor<'a> {
|
||||||
self.editor.set_select_opt(select_opt);
|
self.editor.set_select_opt(select_opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_width(&self) -> usize {
|
fn tab_width(&self) -> u16 {
|
||||||
self.editor.tab_width()
|
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);
|
self.editor.set_tab_width(tab_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -272,11 +272,11 @@ impl<'a> Edit for ViEditor<'a> {
|
||||||
self.editor.set_select_opt(select_opt);
|
self.editor.set_select_opt(select_opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_width(&self) -> usize {
|
fn tab_width(&self) -> u16 {
|
||||||
self.editor.tab_width()
|
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);
|
self.editor.set_tab_width(tab_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue