aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs57
1 files changed, 1 insertions, 56 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 2bac5be0..1310417e 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2672,62 +2672,7 @@ fn open_above(cx: &mut Context) {
}
fn normal_mode(cx: &mut Context) {
- if cx.editor.mode == Mode::Normal {
- return;
- }
-
- cx.editor.mode = Mode::Normal;
- let (view, doc) = current!(cx.editor);
-
- try_restore_indent(doc, view);
-
- // if leaving append mode, move cursor back by 1
- if doc.restore_cursor {
- let text = doc.text().slice(..);
- let selection = doc.selection(view.id).clone().transform(|range| {
- Range::new(
- range.from(),
- graphemes::prev_grapheme_boundary(text, range.to()),
- )
- });
-
- doc.set_selection(view.id, selection);
- doc.restore_cursor = false;
- }
-}
-
-fn try_restore_indent(doc: &mut Document, view: &mut View) {
- use helix_core::chars::char_is_whitespace;
- use helix_core::Operation;
-
- fn inserted_a_new_blank_line(changes: &[Operation], pos: usize, line_end_pos: usize) -> bool {
- if let [Operation::Retain(move_pos), Operation::Insert(ref inserted_str), Operation::Retain(_)] =
- changes
- {
- move_pos + inserted_str.len() == pos
- && inserted_str.starts_with('\n')
- && inserted_str.chars().skip(1).all(char_is_whitespace)
- && pos == line_end_pos // ensure no characters exists after current position
- } else {
- false
- }
- }
-
- let doc_changes = doc.changes().changes();
- let text = doc.text().slice(..);
- let range = doc.selection(view.id).primary();
- let pos = range.cursor(text);
- let line_end_pos = line_end_char_index(&text, range.cursor_line(text));
-
- if inserted_a_new_blank_line(doc_changes, pos, line_end_pos) {
- // Removes tailing whitespaces.
- let transaction =
- Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
- let line_start_pos = text.line_to_char(range.cursor_line(text));
- (line_start_pos, pos, None)
- });
- apply_transaction(&transaction, doc, view);
- }
+ cx.editor.enter_normal_mode();
}
// Store a jump on the jumplist.