Start work on a Buffer API for requesting autoindent on the next parse

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2021-10-06 16:09:30 -07:00
parent a0c8b60a1b
commit b83b4ad7c7
5 changed files with 341 additions and 31 deletions

View file

@ -745,6 +745,7 @@ 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);
}
@ -792,6 +793,17 @@ 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| {