Don't need getters/setters for line_ending property.

It's plain-old-data.  If we want to do fancier things later, it's
easy to switch back.
This commit is contained in:
Nathan Vegdahl 2021-06-21 09:52:21 -07:00
parent 3d3149e0d5
commit 714002048c
2 changed files with 5 additions and 13 deletions

View file

@ -1009,7 +1009,7 @@ fn append_mode(cx: &mut Context) {
if selection.iter().any(|range| range.head == end) { if selection.iter().any(|range| range.head == end) {
let transaction = Transaction::change( let transaction = Transaction::change(
doc.text(), doc.text(),
std::array::IntoIter::new([(end, end, Some(doc.line_ending().as_str().into()))]), std::array::IntoIter::new([(end, end, Some(doc.line_ending.as_str().into()))]),
); );
doc.apply(&transaction, view.id); doc.apply(&transaction, view.id);
} }
@ -2349,7 +2349,7 @@ pub mod insert {
); );
let indent = doc.indent_unit().repeat(indent_level); let indent = doc.indent_unit().repeat(indent_level);
let mut text = String::with_capacity(1 + indent.len()); let mut text = String::with_capacity(1 + indent.len());
text.push_str(doc.line_ending().as_str()); text.push_str(doc.line_ending.as_str());
text.push_str(&indent); text.push_str(&indent);
let head = pos + offs + text.chars().count(); let head = pos + offs + text.chars().count();
@ -2370,7 +2370,7 @@ pub mod insert {
if helix_core::auto_pairs::PAIRS.contains(&(prev, curr)) { if helix_core::auto_pairs::PAIRS.contains(&(prev, curr)) {
// another newline, indent the end bracket one level less // another newline, indent the end bracket one level less
let indent = doc.indent_unit().repeat(indent_level.saturating_sub(1)); let indent = doc.indent_unit().repeat(indent_level.saturating_sub(1));
text.push_str(doc.line_ending().as_str()); text.push_str(doc.line_ending.as_str());
text.push_str(&indent); text.push_str(&indent);
} }
@ -2537,7 +2537,7 @@ fn paste_impl(
// if any of values ends \n it's linewise paste // if any of values ends \n it's linewise paste
let linewise = values let linewise = values
.iter() .iter()
.any(|value| value.ends_with(doc.line_ending().as_str())); .any(|value| value.ends_with(doc.line_ending.as_str()));
let mut values = values.iter().cloned().map(Tendril::from).chain(repeat); let mut values = values.iter().cloned().map(Tendril::from).chain(repeat);

View file

@ -268,7 +268,7 @@ impl Document {
// set the path and try detecting the language // set the path and try detecting the language
doc.set_path(&path)?; doc.set_path(&path)?;
doc.detect_indent_style(); doc.detect_indent_style();
doc.set_line_ending(line_ending); doc.line_ending = line_ending;
if let Some(loader) = config_loader { if let Some(loader) = config_loader {
doc.detect_language(theme, loader); doc.detect_language(theme, loader);
@ -531,10 +531,6 @@ impl Document {
self.selections.insert(view_id, selection); self.selections.insert(view_id, selection);
} }
pub fn set_line_ending(&mut self, line_ending: LineEnding) {
self.line_ending = line_ending;
}
fn _apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool { fn _apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
let old_doc = self.text().clone(); let old_doc = self.text().clone();
@ -805,10 +801,6 @@ impl Document {
pub fn set_diagnostics(&mut self, diagnostics: Vec<Diagnostic>) { pub fn set_diagnostics(&mut self, diagnostics: Vec<Diagnostic>) {
self.diagnostics = diagnostics; self.diagnostics = diagnostics;
} }
pub fn line_ending(&self) -> LineEnding {
self.line_ending
}
} }
#[cfg(test)] #[cfg(test)]