Support expanding tabs
This commit is contained in:
parent
56812a8348
commit
3c94352f3f
9 changed files with 82 additions and 25 deletions
|
|
@ -24,7 +24,6 @@ pub struct Editor<'buffer> {
|
|||
selection: Selection,
|
||||
cursor_moved: bool,
|
||||
auto_indent: bool,
|
||||
tab_width: u16,
|
||||
change: Option<Change>,
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +37,6 @@ impl<'buffer> Editor<'buffer> {
|
|||
selection: Selection::None,
|
||||
cursor_moved: false,
|
||||
auto_indent: false,
|
||||
tab_width: 4,
|
||||
change: None,
|
||||
}
|
||||
}
|
||||
|
|
@ -259,18 +257,11 @@ impl<'buffer> Edit<'buffer> for Editor<'buffer> {
|
|||
}
|
||||
|
||||
fn tab_width(&self) -> u16 {
|
||||
self.tab_width
|
||||
self.with_buffer(|buffer| buffer.tab_width())
|
||||
}
|
||||
|
||||
fn set_tab_width(&mut self, tab_width: u16) {
|
||||
// A tab width of 0 is not allowed
|
||||
if tab_width == 0 {
|
||||
return;
|
||||
}
|
||||
if self.tab_width != tab_width {
|
||||
self.tab_width = tab_width;
|
||||
self.with_buffer_mut(|buffer| buffer.set_redraw(true));
|
||||
}
|
||||
fn set_tab_width(&mut self, font_system: &mut FontSystem, tab_width: u16) {
|
||||
self.with_buffer_mut(|buffer| buffer.set_tab_width(font_system, tab_width));
|
||||
}
|
||||
|
||||
fn shape_as_needed(&mut self, font_system: &mut FontSystem, prune: bool) {
|
||||
|
|
@ -682,7 +673,7 @@ impl<'buffer> Edit<'buffer> for Editor<'buffer> {
|
|||
};
|
||||
|
||||
// For every line in selection
|
||||
let tab_width: usize = self.tab_width.into();
|
||||
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 = 0;
|
||||
|
|
@ -745,7 +736,7 @@ impl<'buffer> Edit<'buffer> for Editor<'buffer> {
|
|||
};
|
||||
|
||||
// For every line in selection
|
||||
let tab_width: usize = self.tab_width.into();
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ pub trait Edit<'buffer> {
|
|||
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: u16);
|
||||
fn set_tab_width(&mut self, font_system: &mut FontSystem, tab_width: u16);
|
||||
|
||||
/// Shape lines until scroll, after adjusting scroll if the cursor moved
|
||||
fn shape_as_needed(&mut self, font_system: &mut FontSystem, prune: bool);
|
||||
|
|
@ -336,6 +336,11 @@ impl<'font_system, 'buffer, E: Edit<'buffer>> BorrowedWithFontSystem<'font_syste
|
|||
})
|
||||
}
|
||||
|
||||
/// Set the current tab width. A `tab_width` of 0 is not allowed, and will be ignored
|
||||
pub fn set_tab_width(&mut self, tab_width: u16) {
|
||||
self.inner.set_tab_width(self.font_system, tab_width);
|
||||
}
|
||||
|
||||
/// Shape lines until scroll, after adjusting scroll if the cursor moved
|
||||
pub fn shape_as_needed(&mut self, prune: bool) {
|
||||
self.inner.shape_as_needed(self.font_system, prune);
|
||||
|
|
|
|||
|
|
@ -250,8 +250,8 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for SyntaxEditor<'syntax_system, 'bu
|
|||
self.editor.tab_width()
|
||||
}
|
||||
|
||||
fn set_tab_width(&mut self, tab_width: u16) {
|
||||
self.editor.set_tab_width(tab_width);
|
||||
fn set_tab_width(&mut self, font_system: &mut FontSystem, tab_width: u16) {
|
||||
self.editor.set_tab_width(font_system, tab_width);
|
||||
}
|
||||
|
||||
fn shape_as_needed(&mut self, font_system: &mut FontSystem, prune: bool) {
|
||||
|
|
|
|||
|
|
@ -550,8 +550,8 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer
|
|||
self.editor.tab_width()
|
||||
}
|
||||
|
||||
fn set_tab_width(&mut self, tab_width: u16) {
|
||||
self.editor.set_tab_width(tab_width);
|
||||
fn set_tab_width(&mut self, font_system: &mut FontSystem, tab_width: u16) {
|
||||
self.editor.set_tab_width(font_system, tab_width);
|
||||
}
|
||||
|
||||
fn shape_as_needed(&mut self, font_system: &mut FontSystem, prune: bool) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue