1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-03 14:26:17 +03:00

rename set_hard_tab/hard_tab to set_hard_tab_indent/hard_tab_indent

Этот коммит содержится в:
rhysd
2022-06-22 22:50:49 +09:00
родитель 08bcc50e11
Коммит 9f54a6758e
2 изменённых файлов: 17 добавлений и 16 удалений

Просмотреть файл

@@ -35,9 +35,10 @@ impl<'a> Buffer<'a> {
if md.is_file() {
let mut textarea: TextArea = io::BufReader::new(fs::File::open(&path)?)
.lines()
.collect::<Result<_, _>>()?;
let hard_tab = textarea.lines().iter().any(|l| l.starts_with('\t'));
textarea.set_hard_tab(hard_tab);
.collect::<io::Result<_>>()?;
if textarea.lines().iter().any(|l| l.starts_with('\t')) {
textarea.set_hard_tab_indent(true);
}
textarea
} else {
return error!("{:?} is not a file", path);

Просмотреть файл

@@ -41,7 +41,7 @@ pub struct TextArea<'a> {
style: Style,
cursor: (usize, usize), // 0-base
tab_len: u8,
hard_tab: bool,
hard_tab_indent: bool,
history: History,
cursor_line_style: Style,
line_number_style: Option<Style>,
@@ -135,7 +135,7 @@ impl<'a> TextArea<'a> {
style: Style::default(),
cursor: (0, 0),
tab_len: 4,
hard_tab: false,
hard_tab_indent: false,
history: History::new(50),
cursor_line_style: Style::default().add_modifier(Modifier::UNDERLINED),
line_number_style: None,
@@ -621,7 +621,7 @@ impl<'a> TextArea<'a> {
if self.tab_len == 0 {
return false;
}
let tab = if self.hard_tab {
let tab = if self.hard_tab_indent {
"\t"
} else {
let len = self.tab_len - (self.cursor.1 % self.tab_len as usize) as u8;
@@ -1093,12 +1093,12 @@ impl<'a> TextArea<'a> {
///
/// let mut textarea = TextArea::default();
///
/// textarea.set_hard_tab(true);
/// textarea.set_hard_tab_indent(true);
/// textarea.insert_tab();
/// assert_eq!(textarea.lines(), ["\t"]);
/// ```
pub fn set_hard_tab(&mut self, enabled: bool) {
self.hard_tab = enabled;
pub fn set_hard_tab_indent(&mut self, enabled: bool) {
self.hard_tab_indent = enabled;
}
/// Get if a hard tab is used for indent or not.
@@ -1107,12 +1107,12 @@ impl<'a> TextArea<'a> {
///
/// let mut textarea = TextArea::default();
///
/// assert!(!textarea.hard_tab());
/// textarea.set_hard_tab(true);
/// assert!(textarea.hard_tab());
/// assert!(!textarea.hard_tab_indent());
/// textarea.set_hard_tab_indent(true);
/// assert!(textarea.hard_tab_indent());
/// ```
pub fn hard_tab(&self) -> bool {
self.hard_tab
pub fn hard_tab_indent(&self) -> bool {
self.hard_tab_indent
}
/// Get a string for indent. It consists of spaces by default. When hard tab is enabled, it is a tab character.
@@ -1124,11 +1124,11 @@ impl<'a> TextArea<'a> {
/// assert_eq!(textarea.indent(), " ");
/// textarea.set_tab_length(2);
/// assert_eq!(textarea.indent(), " ");
/// textarea.set_hard_tab(true);
/// textarea.set_hard_tab_indent(true);
/// assert_eq!(textarea.indent(), "\t");
/// ```
pub fn indent(&self) -> &'static str {
if self.hard_tab {
if self.hard_tab_indent {
"\t"
} else {
spaces(self.tab_len)