@@ -27,6 +27,7 @@ use helix_core::{
27
27
SmallVec , Tendril , Transaction ,
28
28
} ;
29
29
use helix_view:: {
30
+ apply_transaction,
30
31
clipboard:: ClipboardType ,
31
32
document:: { FormatterError , Mode , SCRATCH_BUFFER_NAME } ,
32
33
editor:: { Action , Motion } ,
@@ -859,8 +860,7 @@ fn align_selections(cx: &mut Context) {
859
860
changes. sort_unstable_by_key ( |( from, _, _) | * from) ;
860
861
861
862
let transaction = Transaction :: change ( doc. text ( ) , changes. into_iter ( ) ) ;
862
- doc. apply ( & transaction, view. id ) ;
863
- view. apply ( & transaction, doc) ;
863
+ apply_transaction ( & transaction, doc, view) ;
864
864
}
865
865
866
866
fn goto_window ( cx : & mut Context , align : Align ) {
@@ -1290,8 +1290,7 @@ fn replace(cx: &mut Context) {
1290
1290
}
1291
1291
} ) ;
1292
1292
1293
- doc. apply ( & transaction, view. id ) ;
1294
- view. apply ( & transaction, doc) ;
1293
+ apply_transaction ( & transaction, doc, view) ;
1295
1294
}
1296
1295
} )
1297
1296
}
@@ -1308,8 +1307,7 @@ where
1308
1307
( range. from ( ) , range. to ( ) , Some ( text) )
1309
1308
} ) ;
1310
1309
1311
- doc. apply ( & transaction, view. id ) ;
1312
- view. apply ( & transaction, doc) ;
1310
+ apply_transaction ( & transaction, doc, view) ;
1313
1311
}
1314
1312
1315
1313
fn switch_case ( cx : & mut Context ) {
@@ -2115,8 +2113,7 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
2115
2113
let transaction = Transaction :: change_by_selection ( doc. text ( ) , selection, |range| {
2116
2114
( range. from ( ) , range. to ( ) , None )
2117
2115
} ) ;
2118
- doc. apply ( & transaction, view. id ) ;
2119
- view. apply ( & transaction, doc) ;
2116
+ apply_transaction ( & transaction, doc, view) ;
2120
2117
2121
2118
match op {
2122
2119
Operation :: Delete => {
@@ -2131,14 +2128,10 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
2131
2128
2132
2129
#[ inline]
2133
2130
fn delete_selection_insert_mode ( doc : & mut Document , view : & mut View , selection : & Selection ) {
2134
- let view_id = view. id ;
2135
-
2136
- // then delete
2137
2131
let transaction = Transaction :: change_by_selection ( doc. text ( ) , selection, |range| {
2138
2132
( range. from ( ) , range. to ( ) , None )
2139
2133
} ) ;
2140
- doc. apply ( & transaction, view_id) ;
2141
- view. apply ( & transaction, doc) ;
2134
+ apply_transaction ( & transaction, doc, view) ;
2142
2135
}
2143
2136
2144
2137
fn delete_selection ( cx : & mut Context ) {
@@ -2234,8 +2227,7 @@ fn append_mode(cx: &mut Context) {
2234
2227
doc. text ( ) ,
2235
2228
[ ( end, end, Some ( doc. line_ending . as_str ( ) . into ( ) ) ) ] . into_iter ( ) ,
2236
2229
) ;
2237
- doc. apply ( & transaction, view. id ) ;
2238
- view. apply ( & transaction, doc) ;
2230
+ apply_transaction ( & transaction, doc, view) ;
2239
2231
}
2240
2232
2241
2233
let selection = doc. selection ( view. id ) . clone ( ) . transform ( |range| {
@@ -2535,8 +2527,7 @@ async fn make_format_callback(
2535
2527
let doc = doc_mut ! ( editor, & doc_id) ;
2536
2528
let view = view_mut ! ( editor) ;
2537
2529
if doc. version ( ) == doc_version {
2538
- doc. apply ( & format, view. id ) ;
2539
- view. apply ( & format, doc) ;
2530
+ apply_transaction ( & format, doc, view) ;
2540
2531
doc. append_changes_to_history ( view. id ) ;
2541
2532
doc. detect_indent_and_line_ending ( ) ;
2542
2533
view. ensure_cursor_in_view ( doc, scrolloff) ;
@@ -2623,8 +2614,7 @@ fn open(cx: &mut Context, open: Open) {
2623
2614
2624
2615
transaction = transaction. with_selection ( Selection :: new ( ranges, selection. primary_index ( ) ) ) ;
2625
2616
2626
- doc. apply ( & transaction, view. id ) ;
2627
- view. apply ( & transaction, doc) ;
2617
+ apply_transaction ( & transaction, doc, view) ;
2628
2618
}
2629
2619
2630
2620
// o inserts a new line after each line with a selection
@@ -2692,8 +2682,7 @@ fn try_restore_indent(doc: &mut Document, view: &mut View) {
2692
2682
let line_start_pos = text. line_to_char ( range. cursor_line ( text) ) ;
2693
2683
( line_start_pos, pos, None )
2694
2684
} ) ;
2695
- doc. apply ( & transaction, view. id ) ;
2696
- view. apply ( & transaction, doc) ;
2685
+ apply_transaction ( & transaction, doc, view) ;
2697
2686
}
2698
2687
}
2699
2688
@@ -3007,8 +2996,7 @@ pub mod insert {
3007
2996
3008
2997
let ( view, doc) = current ! ( cx. editor) ;
3009
2998
if let Some ( t) = transaction {
3010
- doc. apply ( & t, view. id ) ;
3011
- view. apply ( & t, doc) ;
2999
+ apply_transaction ( & t, doc, view) ;
3012
3000
}
3013
3001
3014
3002
// TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
@@ -3030,8 +3018,7 @@ pub mod insert {
3030
3018
& doc. selection ( view. id ) . clone ( ) . cursors ( doc. text ( ) . slice ( ..) ) ,
3031
3019
indent,
3032
3020
) ;
3033
- doc. apply ( & transaction, view. id ) ;
3034
- view. apply ( & transaction, doc) ;
3021
+ apply_transaction ( & transaction, doc, view) ;
3035
3022
}
3036
3023
3037
3024
pub fn insert_newline ( cx : & mut Context ) {
@@ -3118,8 +3105,7 @@ pub mod insert {
3118
3105
transaction = transaction. with_selection ( Selection :: new ( ranges, selection. primary_index ( ) ) ) ;
3119
3106
3120
3107
let ( view, doc) = current ! ( cx. editor) ;
3121
- doc. apply ( & transaction, view. id ) ;
3122
- view. apply ( & transaction, doc) ;
3108
+ apply_transaction ( & transaction, doc, view) ;
3123
3109
}
3124
3110
3125
3111
pub fn delete_char_backward ( cx : & mut Context ) {
@@ -3213,8 +3199,7 @@ pub mod insert {
3213
3199
}
3214
3200
} ) ;
3215
3201
let ( view, doc) = current ! ( cx. editor) ;
3216
- doc. apply ( & transaction, view. id ) ;
3217
- view. apply ( & transaction, doc) ;
3202
+ apply_transaction ( & transaction, doc, view) ;
3218
3203
3219
3204
lsp:: signature_help_impl ( cx, SignatureHelpInvoked :: Automatic ) ;
3220
3205
}
@@ -3232,8 +3217,7 @@ pub mod insert {
3232
3217
None ,
3233
3218
)
3234
3219
} ) ;
3235
- doc. apply ( & transaction, view. id ) ;
3236
- view. apply ( & transaction, doc) ;
3220
+ apply_transaction ( & transaction, doc, view) ;
3237
3221
3238
3222
lsp:: signature_help_impl ( cx, SignatureHelpInvoked :: Automatic ) ;
3239
3223
}
@@ -3470,8 +3454,7 @@ fn paste_impl(values: &[String], doc: &mut Document, view: &mut View, action: Pa
3470
3454
} ;
3471
3455
( pos, pos, values. next ( ) )
3472
3456
} ) ;
3473
- doc. apply ( & transaction, view. id ) ;
3474
- view. apply ( & transaction, doc) ;
3457
+ apply_transaction ( & transaction, doc, view) ;
3475
3458
}
3476
3459
3477
3460
pub ( crate ) fn paste_bracketed_value ( cx : & mut Context , contents : String ) {
@@ -3563,8 +3546,7 @@ fn replace_with_yanked(cx: &mut Context) {
3563
3546
}
3564
3547
} ) ;
3565
3548
3566
- doc. apply ( & transaction, view. id ) ;
3567
- view. apply ( & transaction, doc) ;
3549
+ apply_transaction ( & transaction, doc, view) ;
3568
3550
}
3569
3551
}
3570
3552
}
@@ -3587,8 +3569,7 @@ fn replace_selections_with_clipboard_impl(
3587
3569
)
3588
3570
} ) ;
3589
3571
3590
- doc. apply ( & transaction, view. id ) ;
3591
- view. apply ( & transaction, doc) ;
3572
+ apply_transaction ( & transaction, doc, view) ;
3592
3573
doc. append_changes_to_history ( view. id ) ;
3593
3574
Ok ( ( ) )
3594
3575
}
@@ -3658,8 +3639,7 @@ fn indent(cx: &mut Context) {
3658
3639
Some ( ( pos, pos, Some ( indent. clone ( ) ) ) )
3659
3640
} ) ,
3660
3641
) ;
3661
- doc. apply ( & transaction, view. id ) ;
3662
- view. apply ( & transaction, doc) ;
3642
+ apply_transaction ( & transaction, doc, view) ;
3663
3643
}
3664
3644
3665
3645
fn unindent ( cx : & mut Context ) {
@@ -3698,8 +3678,7 @@ fn unindent(cx: &mut Context) {
3698
3678
3699
3679
let transaction = Transaction :: change ( doc. text ( ) , changes. into_iter ( ) ) ;
3700
3680
3701
- doc. apply ( & transaction, view. id ) ;
3702
- view. apply ( & transaction, doc) ;
3681
+ apply_transaction ( & transaction, doc, view) ;
3703
3682
}
3704
3683
3705
3684
fn format_selections ( cx : & mut Context ) {
@@ -3746,8 +3725,7 @@ fn format_selections(cx: &mut Context) {
3746
3725
// language_server.offset_encoding(),
3747
3726
// );
3748
3727
3749
- // doc.apply(&transaction, view.id);
3750
- // view.apply(&transaction, doc);
3728
+ // apply_transaction(&transaction, doc, view);
3751
3729
}
3752
3730
}
3753
3731
@@ -3802,8 +3780,7 @@ fn join_selections_inner(cx: &mut Context, select_space: bool) {
3802
3780
Transaction :: change ( doc. text ( ) , changes. into_iter ( ) )
3803
3781
} ;
3804
3782
3805
- doc. apply ( & transaction, view. id ) ;
3806
- view. apply ( & transaction, doc) ;
3783
+ apply_transaction ( & transaction, doc, view) ;
3807
3784
}
3808
3785
3809
3786
fn keep_or_remove_selections_impl ( cx : & mut Context , remove : bool ) {
@@ -3956,8 +3933,7 @@ fn toggle_comments(cx: &mut Context) {
3956
3933
. map ( |tc| tc. as_ref ( ) ) ;
3957
3934
let transaction = comment:: toggle_line_comments ( doc. text ( ) , doc. selection ( view. id ) , token) ;
3958
3935
3959
- doc. apply ( & transaction, view. id ) ;
3960
- view. apply ( & transaction, doc) ;
3936
+ apply_transaction ( & transaction, doc, view) ;
3961
3937
exit_select_mode ( cx) ;
3962
3938
}
3963
3939
@@ -4013,8 +3989,7 @@ fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
4013
3989
. map ( |( range, fragment) | ( range. from ( ) , range. to ( ) , Some ( fragment) ) ) ,
4014
3990
) ;
4015
3991
4016
- doc. apply ( & transaction, view. id ) ;
4017
- view. apply ( & transaction, doc) ;
3992
+ apply_transaction ( & transaction, doc, view) ;
4018
3993
}
4019
3994
4020
3995
fn rotate_selection_contents_forward ( cx : & mut Context ) {
@@ -4510,8 +4485,7 @@ fn surround_add(cx: &mut Context) {
4510
4485
}
4511
4486
4512
4487
let transaction = Transaction :: change ( doc. text ( ) , changes. into_iter ( ) ) ;
4513
- doc. apply ( & transaction, view. id ) ;
4514
- view. apply ( & transaction, doc) ;
4488
+ apply_transaction ( & transaction, doc, view) ;
4515
4489
} )
4516
4490
}
4517
4491
@@ -4550,8 +4524,7 @@ fn surround_replace(cx: &mut Context) {
4550
4524
( pos, pos + 1 , Some ( t) )
4551
4525
} ) ,
4552
4526
) ;
4553
- doc. apply ( & transaction, view. id ) ;
4554
- view. apply ( & transaction, doc) ;
4527
+ apply_transaction ( & transaction, doc, view) ;
4555
4528
} ) ;
4556
4529
} )
4557
4530
}
@@ -4578,8 +4551,7 @@ fn surround_delete(cx: &mut Context) {
4578
4551
4579
4552
let transaction =
4580
4553
Transaction :: change ( doc. text ( ) , change_pos. into_iter ( ) . map ( |p| ( p, p + 1 , None ) ) ) ;
4581
- doc. apply ( & transaction, view. id ) ;
4582
- view. apply ( & transaction, doc) ;
4554
+ apply_transaction ( & transaction, doc, view) ;
4583
4555
} )
4584
4556
}
4585
4557
@@ -4754,8 +4726,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
4754
4726
4755
4727
if behavior != & ShellBehavior :: Ignore {
4756
4728
let transaction = Transaction :: change ( doc. text ( ) , changes. into_iter ( ) ) ;
4757
- doc. apply ( & transaction, view. id ) ;
4758
- view. apply ( & transaction, doc) ;
4729
+ apply_transaction ( & transaction, doc, view) ;
4759
4730
doc. append_changes_to_history ( view. id ) ;
4760
4731
}
4761
4732
@@ -4818,8 +4789,7 @@ fn add_newline_impl(cx: &mut Context, open: Open) {
4818
4789
} ) ;
4819
4790
4820
4791
let transaction = Transaction :: change ( text, changes) ;
4821
- doc. apply ( & transaction, view. id ) ;
4822
- view. apply ( & transaction, doc) ;
4792
+ apply_transaction ( & transaction, doc, view) ;
4823
4793
}
4824
4794
4825
4795
/// Increment object under cursor by count.
@@ -4912,8 +4882,7 @@ fn increment_impl(cx: &mut Context, amount: i64) {
4912
4882
let transaction = Transaction :: change ( doc. text ( ) , changes) ;
4913
4883
let transaction = transaction. with_selection ( selection. clone ( ) ) ;
4914
4884
4915
- doc. apply ( & transaction, view. id ) ;
4916
- view. apply ( & transaction, doc) ;
4885
+ apply_transaction ( & transaction, doc, view) ;
4917
4886
}
4918
4887
}
4919
4888
0 commit comments