Make rewrapping take tabs more into account (#20196)

Closes #18686


https://github.com/user-attachments/assets/e87b4508-3570-4395-92b4-c5e0e9e19623


Release Notes:

- The Rewrap command now considers the width of each tab character at
the beginning of the line to be the configured tab size.

---------

Co-authored-by: Will <will@zed.dev>
This commit is contained in:
Richard Feldman 2024-11-04 18:10:40 -05:00 committed by GitHub
parent dc02894db4
commit 369de400be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 85 additions and 25 deletions

View file

@ -46,6 +46,7 @@ use std::{
future::Future,
iter::{self, Iterator, Peekable},
mem,
num::NonZeroU32,
ops::{Deref, DerefMut, Range},
path::{Path, PathBuf},
str,
@ -4325,6 +4326,13 @@ impl IndentSize {
}
self
}
pub fn len_with_expanded_tabs(&self, tab_size: NonZeroU32) -> usize {
match self.kind {
IndentKind::Space => self.len as usize,
IndentKind::Tab => self.len as usize * tab_size.get() as usize,
}
}
}
#[cfg(any(test, feature = "test-support"))]