on master help sign in
Automatically commit changes to history if not in insert mode
2a7ae96Blaž Hrastnik
helix-term/src/commands.rs−22
@@ -801,7 +801,6 @@ fn align_selections(cx: &mut Context) {
801 });
801 });
802
802
803 doc.apply(&transaction, view.id);
803 doc.apply(&transaction, view.id);
804− doc.append_changes_to_history(view.id);
805}
804}
806
805
807fn align_fragment_to_width(fragment: &str, width: usize, align_style: usize) -> String {
806fn align_fragment_to_width(fragment: &str, width: usize, align_style: usize) -> String {
@@ -1204,7 +1203,6 @@ fn replace(cx: &mut Context) {
1204 });
1203 });
1205
1204
1206 doc.apply(&transaction, view.id);
1205 doc.apply(&transaction, view.id);
1207− doc.append_changes_to_history(view.id);
1208 }
1206 }
1209 })
1207 })
1210}
1208}
@@ -1222,7 +1220,6 @@ where
1222 });
1220 });
1223
1221
1224 doc.apply(&transaction, view.id);
1222 doc.apply(&transaction, view.id);
1225− doc.append_changes_to_history(view.id);
1226}
1223}
1227
1224
1228fn switch_case(cx: &mut Context) {
1225fn switch_case(cx: &mut Context) {
@@ -1862,7 +1859,6 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
1862
1859
1863 match op {
1860 match op {
1864 Operation::Delete => {
1861 Operation::Delete => {
1865− doc.append_changes_to_history(view.id);
1866 // exit select mode, if currently in select mode
1862 // exit select mode, if currently in select mode
1867 exit_select_mode(cx);
1863 exit_select_mode(cx);
1868 }
1864 }
@@ -3861,7 +3857,6 @@ fn normal_mode(cx: &mut Context) {
3861 doc.mode = Mode::Normal;
3857 doc.mode = Mode::Normal;
3862
3858
3863 try_restore_indent(doc, view.id);
3859 try_restore_indent(doc, view.id);
3864− doc.append_changes_to_history(view.id);
3865
3860
3866 // if leaving append mode, move cursor back by 1
3861 // if leaving append mode, move cursor back by 1
3867 if doc.restore_cursor {
3862 if doc.restore_cursor {
@@ -4383,7 +4378,6 @@ fn signature_help(cx: &mut Context) {
4383 );
4378 );
4384}
4379}
4385
4380
4386−// NOTE: Transactions in this module get appended to history when we switch back to normal mode.
4387pub mod insert {
4381pub mod insert {
4388 use super::*;
4382 use super::*;
4389 pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;
4383 pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;
@@ -4998,7 +4992,6 @@ fn replace_with_yanked(cx: &mut Context) {
4998 });
4992 });
4999
4993
5000 doc.apply(&transaction, view.id);
4994 doc.apply(&transaction, view.id);
5001− doc.append_changes_to_history(view.id);
5002 }
4995 }
5003 }
4996 }
5004}
4997}
@@ -5048,7 +5041,6 @@ fn paste_after(cx: &mut Context) {
5048 .and_then(|values| paste_impl(values, doc, view, Paste::After, count))
5041 .and_then(|values| paste_impl(values, doc, view, Paste::After, count))
5049 {
5042 {
5050 doc.apply(&transaction, view.id);
5043 doc.apply(&transaction, view.id);
5051− doc.append_changes_to_history(view.id);
5052 }
5044 }
5053}
5045}
5054
5046
@@ -5063,7 +5055,6 @@ fn paste_before(cx: &mut Context) {
5063 .and_then(|values| paste_impl(values, doc, view, Paste::Before, count))
5055 .and_then(|values| paste_impl(values, doc, view, Paste::Before, count))
5064 {
5056 {
5065 doc.apply(&transaction, view.id);
5057 doc.apply(&transaction, view.id);
5066− doc.append_changes_to_history(view.id);
5067 }
5058 }
5068}
5059}
5069
5060
@@ -5099,7 +5090,6 @@ fn indent(cx: &mut Context) {
5099 }),
5090 }),
5100 );
5091 );
5101 doc.apply(&transaction, view.id);
5092 doc.apply(&transaction, view.id);
5102− doc.append_changes_to_history(view.id);
5103}
5093}
5104
5094
5105fn unindent(cx: &mut Context) {
5095fn unindent(cx: &mut Context) {
@@ -5139,7 +5129,6 @@ fn unindent(cx: &mut Context) {
5139 let transaction = Transaction::change(doc.text(), changes.into_iter());
5129 let transaction = Transaction::change(doc.text(), changes.into_iter());
5140
5130
5141 doc.apply(&transaction, view.id);
5131 doc.apply(&transaction, view.id);
5142− doc.append_changes_to_history(view.id);
5143}
5132}
5144
5133
5145fn format_selections(cx: &mut Context) {
5134fn format_selections(cx: &mut Context) {
@@ -5186,8 +5175,6 @@ fn format_selections(cx: &mut Context) {
5186
5175
5187 // doc.apply(&transaction, view.id);
5176 // doc.apply(&transaction, view.id);
5188 }
5177 }
5189−
5190− doc.append_changes_to_history(view.id);
5191}
5178}
5192
5179
5193fn join_selections(cx: &mut Context) {
5180fn join_selections(cx: &mut Context) {
@@ -5230,7 +5217,6 @@ fn join_selections(cx: &mut Context) {
5230 // .with_selection(selection);
5217 // .with_selection(selection);
5231
5218
5232 doc.apply(&transaction, view.id);
5219 doc.apply(&transaction, view.id);
5233− doc.append_changes_to_history(view.id);
5234}
5220}
5235
5221
5236fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
5222fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
@@ -5478,7 +5464,6 @@ fn toggle_comments(cx: &mut Context) {
5478 let transaction = comment::toggle_line_comments(doc.text(), doc.selection(view.id), token);
5464 let transaction = comment::toggle_line_comments(doc.text(), doc.selection(view.id), token);
5479
5465
5480 doc.apply(&transaction, view.id);
5466 doc.apply(&transaction, view.id);
5481− doc.append_changes_to_history(view.id);
5482 exit_select_mode(cx);
5467 exit_select_mode(cx);
5483}
5468}
5484
5469
@@ -5535,7 +5520,6 @@ fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
5535 );
5520 );
5536
5521
5537 doc.apply(&transaction, view.id);
5522 doc.apply(&transaction, view.id);
5538− doc.append_changes_to_history(view.id);
5539}
5523}
5540
5524
5541fn rotate_selection_contents_forward(cx: &mut Context) {
5525fn rotate_selection_contents_forward(cx: &mut Context) {
@@ -5875,7 +5859,6 @@ fn surround_add(cx: &mut Context) {
5875
5859
5876 let transaction = Transaction::change(doc.text(), changes.into_iter());
5860 let transaction = Transaction::change(doc.text(), changes.into_iter());
5877 doc.apply(&transaction, view.id);
5861 doc.apply(&transaction, view.id);
5878− doc.append_changes_to_history(view.id);
5879 }
5862 }
5880 })
5863 })
5881}
5864}
@@ -5908,7 +5891,6 @@ fn surround_replace(cx: &mut Context) {
5908 }),
5891 }),
5909 );
5892 );
5910 doc.apply(&transaction, view.id);
5893 doc.apply(&transaction, view.id);
5911− doc.append_changes_to_history(view.id);
5912 }
5894 }
5913 });
5895 });
5914 }
5896 }
@@ -5931,7 +5913,6 @@ fn surround_delete(cx: &mut Context) {
5931 let transaction =
5913 let transaction =
5932 Transaction::change(doc.text(), change_pos.into_iter().map(|p| (p, p + 1, None)));
5914 Transaction::change(doc.text(), change_pos.into_iter().map(|p| (p, p + 1, None)));
5933 doc.apply(&transaction, view.id);
5915 doc.apply(&transaction, view.id);
5934− doc.append_changes_to_history(view.id);
5935 }
5916 }
5936 })
5917 })
5937}
5918}
@@ -6102,7 +6083,6 @@ fn shell(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) {
6102 if behavior != ShellBehavior::Ignore {
6083 if behavior != ShellBehavior::Ignore {
6103 let transaction = Transaction::change(doc.text(), changes.into_iter());
6084 let transaction = Transaction::change(doc.text(), changes.into_iter());
6104 doc.apply(&transaction, view.id);
6085 doc.apply(&transaction, view.id);
6105− doc.append_changes_to_history(view.id);
6106 }
6086 }
6107
6087
6108 // after replace cursor may be out of bounds, do this to
6088 // after replace cursor may be out of bounds, do this to
@@ -6150,7 +6130,6 @@ fn add_newline_impl(cx: &mut Context, open: Open) {
6150
6130
6151 let transaction = Transaction::change(text, changes);
6131 let transaction = Transaction::change(text, changes);
6152 doc.apply(&transaction, view.id);
6132 doc.apply(&transaction, view.id);
6153− doc.append_changes_to_history(view.id);
6154}
6133}
6155
6134
6156fn rename_symbol(cx: &mut Context) {
6135fn rename_symbol(cx: &mut Context) {
@@ -6250,7 +6229,6 @@ fn increment_impl(cx: &mut Context, amount: i64) {
6250 let transaction = transaction.with_selection(selection.clone());
6229 let transaction = transaction.with_selection(selection.clone());
6251
6230
6252 doc.apply(&transaction, view.id);
6231 doc.apply(&transaction, view.id);
6253− doc.append_changes_to_history(view.id);
6254 }
6232 }
6255}
6233}
6256
6234
helix-term/src/ui/editor.rs+6
@@ -1035,6 +1035,12 @@ impl Component for EditorView {
1035 let (view, doc) = current!(cx.editor);
1035 let (view, doc) = current!(cx.editor);
1036 view.ensure_cursor_in_view(doc, cx.editor.config.scrolloff);
1036 view.ensure_cursor_in_view(doc, cx.editor.config.scrolloff);
1037
1037
1038+ // Store a history state if not in insert mode. This also takes care of
1039+ // commiting changes when leaving insert mode.
1040+ if doc.mode() != Mode::Insert {
1041+ doc.append_changes_to_history(view.id);
1042+ }
1043+
1038 // mode transitions
1044 // mode transitions
1039 match (mode, doc.mode()) {
1045 match (mode, doc.mode()) {
1040 (Mode::Normal, Mode::Insert) => {
1046 (Mode::Normal, Mode::Insert) => {