aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-10-14 09:07:42 +0000
committerBlaž Hrastnik2020-10-14 09:07:42 +0000
commit6e658aae1c05fdd9f9ee36b39a948028bcaad446 (patch)
tree7d703103fbf12f64928a72746cd8c6aa29260c42 /helix-view
parent6ae3c26def0e4fe4b3e4ce21f1e8d569c627e738 (diff)
Auto-indent on enter based on tree-sitter scopes.
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/commands.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs
index 2cc797f8..542c28ee 100644
--- a/helix-view/src/commands.rs
+++ b/helix-view/src/commands.rs
@@ -435,7 +435,16 @@ pub mod insert {
}
pub fn insert_newline(view: &mut View, _count: usize) {
- insert_char(view, '\n');
+ let transaction = Transaction::change_by_selection(&view.state, |range| {
+ let indent_level =
+ helix_core::indent::suggested_indent_for_pos(&view.state, range.head);
+ let indent = " ".repeat(TAB_WIDTH).repeat(indent_level);
+ let mut text = String::with_capacity(1 + indent.len());
+ text.push('\n');
+ text.push_str(&indent);
+ (range.head, range.head, Some(text.into()))
+ });
+ transaction.apply(&mut view.state);
}
// TODO: handle indent-aware delete
@@ -605,3 +614,8 @@ pub fn unindent(view: &mut View, _count: usize) {
transaction.apply(&mut view.state);
append_changes_to_history(view);
}
+
+pub fn indent_selection(view: &mut View, _count: usize) {
+ // loop over each line and recompute proper indentation
+ unimplemented!()
+}