1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-08 00:15:50 +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() { if md.is_file() {
let mut textarea: TextArea = io::BufReader::new(fs::File::open(&path)?) let mut textarea: TextArea = io::BufReader::new(fs::File::open(&path)?)
.lines() .lines()
.collect::<Result<_, _>>()?; .collect::<io::Result<_>>()?;
let hard_tab = textarea.lines().iter().any(|l| l.starts_with('\t')); if textarea.lines().iter().any(|l| l.starts_with('\t')) {
textarea.set_hard_tab(hard_tab); textarea.set_hard_tab_indent(true);
}
textarea textarea
} else { } else {
return error!("{:?} is not a file", path); return error!("{:?} is not a file", path);

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

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