Replace Buffer::request_autoindent API with ::edit_with_autoindent
When computing the "previous autoindent suggestion", we can't just use the old tree and the current text. We need to find out what the suggestion would have been before we made any changes.
This commit is contained in:
@@ -747,7 +747,6 @@ impl Editor {
|
||||
if !self.skip_autoclose_end(text, cx) {
|
||||
self.start_transaction(cx);
|
||||
self.insert(text, cx);
|
||||
self.request_autoindent(cx);
|
||||
self.autoclose_pairs(cx);
|
||||
self.end_transaction(cx);
|
||||
}
|
||||
@@ -769,7 +768,7 @@ impl Editor {
|
||||
let mut new_selections = Vec::new();
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
let edit_ranges = old_selections.iter().map(|(_, range)| range.clone());
|
||||
buffer.edit(edit_ranges, text, cx);
|
||||
buffer.edit_with_autoindent(edit_ranges, text, cx);
|
||||
let text_len = text.len() as isize;
|
||||
let mut delta = 0_isize;
|
||||
new_selections = old_selections
|
||||
@@ -795,17 +794,6 @@ impl Editor {
|
||||
self.end_transaction(cx);
|
||||
}
|
||||
|
||||
fn request_autoindent(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let selections = self.selections(cx);
|
||||
let tab_size = self.build_settings.borrow()(cx).tab_size as u8;
|
||||
self.buffer.update(cx, |buffer, _| {
|
||||
for selection in selections.iter() {
|
||||
let row = selection.head().to_point(&*buffer).row;
|
||||
buffer.request_autoindent_for_line(row, tab_size, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn autoclose_pairs(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let selections = self.selections(cx);
|
||||
let new_autoclose_pair_state = self.buffer.update(cx, |buffer, cx| {
|
||||
|
||||
Reference in New Issue
Block a user