@@ -4,10 +4,7 @@ use crate::job::Job;
4
4
5
5
use super :: * ;
6
6
7
- use helix_view:: {
8
- apply_transaction,
9
- editor:: { Action , CloseError , ConfigEvent } ,
10
- } ;
7
+ use helix_view:: editor:: { Action , CloseError , ConfigEvent } ;
11
8
use ui:: completers:: { self , Completer } ;
12
9
13
10
#[ derive( Clone ) ]
@@ -445,8 +442,8 @@ fn set_line_ending(
445
442
arg if arg. starts_with ( "nel" ) => Nel ,
446
443
_ => bail ! ( "invalid line ending" ) ,
447
444
} ;
448
- let ( view , doc ) = current ! ( cx. editor) ;
449
- doc. line_ending = line_ending ;
445
+ doc_mut ! ( cx. editor) . line_ending = line_ending ;
446
+ let ( view , doc) = current_ref ! ( cx . editor ) ;
450
447
451
448
let mut pos = 0 ;
452
449
let transaction = Transaction :: change (
@@ -463,7 +460,8 @@ fn set_line_ending(
463
460
}
464
461
} ) ,
465
462
) ;
466
- apply_transaction ( & transaction, doc, view) ;
463
+ cx. editor . apply_transaction ( & transaction, doc. id ( ) , view. id ) ;
464
+ let ( view, doc) = current ! ( cx. editor) ;
467
465
doc. append_changes_to_history ( view. id ) ;
468
466
469
467
Ok ( ( ) )
@@ -480,9 +478,8 @@ fn earlier(
480
478
481
479
let uk = args. join ( " " ) . parse :: < UndoKind > ( ) . map_err ( |s| anyhow ! ( s) ) ?;
482
480
483
- let ( view, doc) = current ! ( cx. editor) ;
484
- let success = doc. earlier ( view, uk) ;
485
- if !success {
481
+ let ( view_id, doc_id) = current_ids ! ( cx. editor) ;
482
+ if !cx. editor . earlier ( doc_id, view_id, uk) {
486
483
cx. editor . set_status ( "Already at oldest change" ) ;
487
484
}
488
485
@@ -499,9 +496,9 @@ fn later(
499
496
}
500
497
501
498
let uk = args. join ( " " ) . parse :: < UndoKind > ( ) . map_err ( |s| anyhow ! ( s) ) ?;
502
- let ( view , doc ) = current ! ( cx . editor ) ;
503
- let success = doc . later ( view , uk ) ;
504
- if !success {
499
+
500
+ let ( view_id , doc_id ) = current_ids ! ( cx . editor ) ;
501
+ if !cx . editor . later ( doc_id , view_id , uk ) {
505
502
cx. editor . set_status ( "Already at newest change" ) ;
506
503
}
507
504
@@ -899,7 +896,7 @@ fn replace_selections_with_clipboard_impl(
899
896
cx : & mut compositor:: Context ,
900
897
clipboard_type : ClipboardType ,
901
898
) -> anyhow:: Result < ( ) > {
902
- let ( view, doc) = current ! ( cx. editor) ;
899
+ let ( view, doc) = current_ref ! ( cx. editor) ;
903
900
904
901
match cx. editor . clipboard_provider . get_contents ( clipboard_type) {
905
902
Ok ( contents) => {
@@ -908,7 +905,8 @@ fn replace_selections_with_clipboard_impl(
908
905
( range. from ( ) , range. to ( ) , Some ( contents. as_str ( ) . into ( ) ) )
909
906
} ) ;
910
907
911
- apply_transaction ( & transaction, doc, view) ;
908
+ cx. editor . apply_transaction ( & transaction, doc. id ( ) , view. id ) ;
909
+ let ( view, doc) = current ! ( cx. editor) ;
912
910
doc. append_changes_to_history ( view. id ) ;
913
911
Ok ( ( ) )
914
912
}
@@ -1027,11 +1025,8 @@ fn reload(
1027
1025
return Ok ( ( ) ) ;
1028
1026
}
1029
1027
1030
- let scrolloff = cx. editor . config ( ) . scrolloff ;
1031
- let ( view, doc) = current ! ( cx. editor) ;
1032
- doc. reload ( view) . map ( |_| {
1033
- view. ensure_cursor_in_view ( doc, scrolloff) ;
1034
- } )
1028
+ let ( view_id, doc_id) = current_ids ! ( cx. editor) ;
1029
+ cx. editor . reload ( doc_id, view_id)
1035
1030
}
1036
1031
1037
1032
fn reload_all (
@@ -1062,11 +1057,10 @@ fn reload_all(
1062
1057
. collect ( ) ;
1063
1058
1064
1059
for ( doc_id, view_ids) in docs_view_ids {
1065
- let doc = doc_mut ! ( cx. editor, & doc_id) ;
1066
-
1067
1060
// Every doc is guaranteed to have at least 1 view at this point.
1068
- let view = view_mut ! ( cx. editor, view_ids[ 0 ] ) ;
1069
- doc. reload ( view) ?;
1061
+ cx. editor . reload ( doc_id, view_ids[ 0 ] ) ?;
1062
+
1063
+ let doc = doc ! ( cx. editor, & doc_id) ;
1070
1064
1071
1065
for view_id in view_ids {
1072
1066
let view = view_mut ! ( cx. editor, view_id) ;
@@ -1088,8 +1082,7 @@ fn update(
1088
1082
return Ok ( ( ) ) ;
1089
1083
}
1090
1084
1091
- let ( _view, doc) = current ! ( cx. editor) ;
1092
- if doc. is_modified ( ) {
1085
+ if doc ! ( cx. editor) . is_modified ( ) {
1093
1086
write ( cx, args, event)
1094
1087
} else {
1095
1088
Ok ( ( ) )
@@ -1105,9 +1098,7 @@ fn lsp_workspace_command(
1105
1098
return Ok ( ( ) ) ;
1106
1099
}
1107
1100
1108
- let ( _, doc) = current ! ( cx. editor) ;
1109
-
1110
- let language_server = match doc. language_server ( ) {
1101
+ let language_server = match doc ! ( cx. editor) . language_server ( ) {
1111
1102
Some ( language_server) => language_server,
1112
1103
None => {
1113
1104
cx. editor
@@ -1176,7 +1167,8 @@ fn lsp_restart(
1176
1167
return Ok ( ( ) ) ;
1177
1168
}
1178
1169
1179
- let ( _view, doc) = current ! ( cx. editor) ;
1170
+ let doc = doc ! ( cx. editor) ;
1171
+
1180
1172
let config = doc
1181
1173
. language_config ( )
1182
1174
. context ( "LSP not defined for the current document" ) ?;
@@ -1210,7 +1202,7 @@ fn tree_sitter_scopes(
1210
1202
return Ok ( ( ) ) ;
1211
1203
}
1212
1204
1213
- let ( view, doc) = current ! ( cx. editor) ;
1205
+ let ( view, doc) = current_ref ! ( cx. editor) ;
1214
1206
let text = doc. text ( ) . slice ( ..) ;
1215
1207
1216
1208
let pos = doc. selection ( view. id ) . primary ( ) . cursor ( text) ;
@@ -1243,10 +1235,10 @@ fn vsplit(
1243
1235
return Ok ( ( ) ) ;
1244
1236
}
1245
1237
1246
- let id = view ! ( cx. editor) . doc ;
1238
+ let ( _ , doc_id ) = current_ids ! ( cx. editor) ;
1247
1239
1248
1240
if args. is_empty ( ) {
1249
- cx. editor . switch ( id , Action :: VerticalSplit ) ;
1241
+ cx. editor . switch ( doc_id , Action :: VerticalSplit ) ;
1250
1242
} else {
1251
1243
for arg in args {
1252
1244
cx. editor
@@ -1266,10 +1258,10 @@ fn hsplit(
1266
1258
return Ok ( ( ) ) ;
1267
1259
}
1268
1260
1269
- let id = view ! ( cx. editor) . doc ;
1261
+ let ( _ , doc_id ) = current_ids ! ( cx. editor) ;
1270
1262
1271
1263
if args. is_empty ( ) {
1272
- cx. editor . switch ( id , Action :: HorizontalSplit ) ;
1264
+ cx. editor . switch ( doc_id , Action :: HorizontalSplit ) ;
1273
1265
} else {
1274
1266
for arg in args {
1275
1267
cx. editor
@@ -1548,7 +1540,7 @@ fn sort_impl(
1548
1540
_args : & [ Cow < str > ] ,
1549
1541
reverse : bool ,
1550
1542
) -> anyhow:: Result < ( ) > {
1551
- let ( view, doc) = current ! ( cx. editor) ;
1543
+ let ( view, doc) = current_ref ! ( cx. editor) ;
1552
1544
let text = doc. text ( ) . slice ( ..) ;
1553
1545
1554
1546
let selection = doc. selection ( view. id ) ;
@@ -1571,7 +1563,8 @@ fn sort_impl(
1571
1563
. map ( |( s, fragment) | ( s. from ( ) , s. to ( ) , Some ( fragment) ) ) ,
1572
1564
) ;
1573
1565
1574
- apply_transaction ( & transaction, doc, view) ;
1566
+ cx. editor . apply_transaction ( & transaction, doc. id ( ) , view. id ) ;
1567
+ let ( view, doc) = current ! ( cx. editor) ;
1575
1568
doc. append_changes_to_history ( view. id ) ;
1576
1569
1577
1570
Ok ( ( ) )
@@ -1587,7 +1580,7 @@ fn reflow(
1587
1580
}
1588
1581
1589
1582
let scrolloff = cx. editor . config ( ) . scrolloff ;
1590
- let ( view, doc) = current ! ( cx. editor) ;
1583
+ let ( view, doc) = current_ref ! ( cx. editor) ;
1591
1584
1592
1585
const DEFAULT_MAX_LEN : usize = 79 ;
1593
1586
@@ -1615,7 +1608,8 @@ fn reflow(
1615
1608
( range. from ( ) , range. to ( ) , Some ( reflowed_text) )
1616
1609
} ) ;
1617
1610
1618
- apply_transaction ( & transaction, doc, view) ;
1611
+ cx. editor . apply_transaction ( & transaction, doc. id ( ) , view. id ) ;
1612
+ let ( view, doc) = current ! ( cx. editor) ;
1619
1613
doc. append_changes_to_history ( view. id ) ;
1620
1614
view. ensure_cursor_in_view ( doc, scrolloff) ;
1621
1615
@@ -1631,7 +1625,7 @@ fn tree_sitter_subtree(
1631
1625
return Ok ( ( ) ) ;
1632
1626
}
1633
1627
1634
- let ( view, doc) = current ! ( cx. editor) ;
1628
+ let ( view, doc) = current_ref ! ( cx. editor) ;
1635
1629
1636
1630
if let Some ( syntax) = doc. syntax ( ) {
1637
1631
let primary_selection = doc. selection ( view. id ) . primary ( ) ;
0 commit comments