Tab size is pulled properly from settings instead of hardcoded
This commit is contained in:
parent
866ffdd4ae
commit
1812480cbb
15 changed files with 128 additions and 87 deletions
|
@ -12,7 +12,7 @@ use text::Point;
|
|||
pub struct TabMap(Mutex<TabSnapshot>);
|
||||
|
||||
impl TabMap {
|
||||
pub fn new(input: FoldSnapshot, tab_size: usize) -> (Self, TabSnapshot) {
|
||||
pub fn new(input: FoldSnapshot, tab_size: u32) -> (Self, TabSnapshot) {
|
||||
let snapshot = TabSnapshot {
|
||||
fold_snapshot: input,
|
||||
tab_size,
|
||||
|
@ -24,12 +24,13 @@ impl TabMap {
|
|||
&self,
|
||||
fold_snapshot: FoldSnapshot,
|
||||
mut fold_edits: Vec<FoldEdit>,
|
||||
tab_size: u32,
|
||||
) -> (TabSnapshot, Vec<TabEdit>) {
|
||||
let mut old_snapshot = self.0.lock();
|
||||
let max_offset = old_snapshot.fold_snapshot.len();
|
||||
let new_snapshot = TabSnapshot {
|
||||
fold_snapshot,
|
||||
tab_size: old_snapshot.tab_size,
|
||||
tab_size,
|
||||
};
|
||||
|
||||
let mut tab_edits = Vec::with_capacity(fold_edits.len());
|
||||
|
@ -87,7 +88,7 @@ impl TabMap {
|
|||
#[derive(Clone)]
|
||||
pub struct TabSnapshot {
|
||||
pub fold_snapshot: FoldSnapshot,
|
||||
pub tab_size: usize,
|
||||
pub tab_size: u32,
|
||||
}
|
||||
|
||||
impl TabSnapshot {
|
||||
|
@ -234,7 +235,7 @@ impl TabSnapshot {
|
|||
.to_buffer_point(&self.fold_snapshot)
|
||||
}
|
||||
|
||||
fn expand_tabs(chars: impl Iterator<Item = char>, column: usize, tab_size: usize) -> usize {
|
||||
fn expand_tabs(chars: impl Iterator<Item = char>, column: usize, tab_size: u32) -> usize {
|
||||
let mut expanded_chars = 0;
|
||||
let mut expanded_bytes = 0;
|
||||
let mut collapsed_bytes = 0;
|
||||
|
@ -243,7 +244,7 @@ impl TabSnapshot {
|
|||
break;
|
||||
}
|
||||
if c == '\t' {
|
||||
let tab_len = tab_size - expanded_chars % tab_size;
|
||||
let tab_len = tab_size as usize - expanded_chars % tab_size as usize;
|
||||
expanded_bytes += tab_len;
|
||||
expanded_chars += tab_len;
|
||||
} else {
|
||||
|
@ -259,7 +260,7 @@ impl TabSnapshot {
|
|||
mut chars: impl Iterator<Item = char>,
|
||||
column: usize,
|
||||
bias: Bias,
|
||||
tab_size: usize,
|
||||
tab_size: u32,
|
||||
) -> (usize, usize, usize) {
|
||||
let mut expanded_bytes = 0;
|
||||
let mut expanded_chars = 0;
|
||||
|
@ -270,7 +271,7 @@ impl TabSnapshot {
|
|||
}
|
||||
|
||||
if c == '\t' {
|
||||
let tab_len = tab_size - (expanded_chars % tab_size);
|
||||
let tab_len = tab_size as usize - (expanded_chars % tab_size as usize);
|
||||
expanded_chars += tab_len;
|
||||
expanded_bytes += tab_len;
|
||||
if expanded_bytes > column {
|
||||
|
@ -383,7 +384,7 @@ pub struct TabChunks<'a> {
|
|||
column: usize,
|
||||
output_position: Point,
|
||||
max_output_position: Point,
|
||||
tab_size: usize,
|
||||
tab_size: u32,
|
||||
skip_leading_tab: bool,
|
||||
}
|
||||
|
||||
|
@ -415,16 +416,16 @@ impl<'a> Iterator for TabChunks<'a> {
|
|||
});
|
||||
} else {
|
||||
self.chunk.text = &self.chunk.text[1..];
|
||||
let mut len = self.tab_size - self.column % self.tab_size;
|
||||
let mut len = self.tab_size - self.column as u32 % self.tab_size;
|
||||
let next_output_position = cmp::min(
|
||||
self.output_position + Point::new(0, len as u32),
|
||||
self.output_position + Point::new(0, len),
|
||||
self.max_output_position,
|
||||
);
|
||||
len = (next_output_position.column - self.output_position.column) as usize;
|
||||
self.column += len;
|
||||
len = next_output_position.column - self.output_position.column;
|
||||
self.column += len as usize;
|
||||
self.output_position = next_output_position;
|
||||
return Some(Chunk {
|
||||
text: &SPACES[0..len],
|
||||
text: &SPACES[0..len as usize],
|
||||
..self.chunk
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue