on master help sign in
commands: Simplify some code, only calling cx.doc() once.
7da6bd6Blaž Hrastnik
helix-term/src/commands.rs+140−177
@@ -36,6 +36,15 @@ impl<'a> Context<'a> {
36 pub fn doc(&mut self) -> &mut Document {
36 pub fn doc(&mut self) -> &mut Document {
37 &mut self.editor.view_mut().doc
37 &mut self.editor.view_mut().doc
38 }
38 }
39+
40+ /// Push a new component onto the compositor.
41+ pub fn push_layer(&mut self, component: Box<dyn crate::compositor::Component>) {
42+ self.callback = Some(Box::new(
43+ |compositor: &mut Compositor, editor: &mut Editor| {
44+ compositor.push(component);
45+ },
46+ ));
47+ }
39}
48}
40
49
41/// A command is a function that takes the current state and a count, and does a side-effect on the
50/// A command is a function that takes the current state and a count, and does a side-effect on the
@@ -44,42 +53,43 @@ pub type Command = fn(cx: &mut Context);
44
53
45pub fn move_char_left(cx: &mut Context) {
54pub fn move_char_left(cx: &mut Context) {
46 let count = cx.count;
55 let count = cx.count;
47− let selection =
48− cx.doc()
56+ let doc = cx.doc();
57+ let selection = doc
49− .state
58+ .state
50− .move_selection(Direction::Backward, Granularity::Character, count);
59+ .move_selection(Direction::Backward, Granularity::Character, count);
51− cx.doc().set_selection(selection);
60+ doc.set_selection(selection);
52}
61}
53
62
54pub fn move_char_right(cx: &mut Context) {
63pub fn move_char_right(cx: &mut Context) {
55 let count = cx.count;
64 let count = cx.count;
56− let selection =
57− cx.doc()
65+ let doc = cx.doc();
66+ let selection = doc
58− .state
67+ .state
59− .move_selection(Direction::Forward, Granularity::Character, count);
68+ .move_selection(Direction::Forward, Granularity::Character, count);
60− cx.doc().set_selection(selection);
69+ doc.set_selection(selection);
61}
70}
62
71
63pub fn move_line_up(cx: &mut Context) {
72pub fn move_line_up(cx: &mut Context) {
64 let count = cx.count;
73 let count = cx.count;
65− let selection = cx
66− .doc()
74+ let doc = cx.doc();
75+ let selection = doc
67 .state
76 .state
68 .move_selection(Direction::Backward, Granularity::Line, count);
77 .move_selection(Direction::Backward, Granularity::Line, count);
69− cx.doc().set_selection(selection);
78+ doc.set_selection(selection);
70}
79}
71
80
72pub fn move_line_down(cx: &mut Context) {
81pub fn move_line_down(cx: &mut Context) {
73 let count = cx.count;
82 let count = cx.count;
74− let selection = cx
75− .doc()
83+ let doc = cx.doc();
84+ let selection = doc
76 .state
85 .state
77 .move_selection(Direction::Forward, Granularity::Line, count);
86 .move_selection(Direction::Forward, Granularity::Line, count);
78− cx.doc().set_selection(selection);
87+ doc.set_selection(selection);
79}
88}
80
89
81pub fn move_line_end(cx: &mut Context) {
90pub fn move_line_end(cx: &mut Context) {
91+ let doc = cx.doc();
82− let lines = selection_lines(&cx.doc().state);
92+ let lines = selection_lines(&doc.state);
83
93
84 let positions = lines
94 let positions = lines
85 .into_iter()
95 .into_iter()
@@ -88,29 +98,30 @@ pub fn move_line_end(cx: &mut Context) {
88
98
89 // Line end is pos at the start of next line - 1
99 // Line end is pos at the start of next line - 1
90 // subtract another 1 because the line ends with \n
100 // subtract another 1 because the line ends with \n
91− cx.doc().text().line_to_char(index + 1).saturating_sub(2)
101+ doc.text().line_to_char(index + 1).saturating_sub(2)
92 })
102 })
93 .map(|pos| Range::new(pos, pos));
103 .map(|pos| Range::new(pos, pos));
94
104
95 let selection = Selection::new(positions.collect(), 0);
105 let selection = Selection::new(positions.collect(), 0);
96
106
97− cx.doc().set_selection(selection);
107+ doc.set_selection(selection);
98}
108}
99
109
100pub fn move_line_start(cx: &mut Context) {
110pub fn move_line_start(cx: &mut Context) {
111+ let doc = cx.doc();
101− let lines = selection_lines(&cx.doc().state);
112+ let lines = selection_lines(&doc.state);
102
113
103 let positions = lines
114 let positions = lines
104 .into_iter()
115 .into_iter()
105 .map(|index| {
116 .map(|index| {
106 // adjust all positions to the start of the line.
117 // adjust all positions to the start of the line.
107− cx.doc().text().line_to_char(index)
118+ doc.text().line_to_char(index)
108 })
119 })
109 .map(|pos| Range::new(pos, pos));
120 .map(|pos| Range::new(pos, pos));
110
121
111 let selection = Selection::new(positions.collect(), 0);
122 let selection = Selection::new(positions.collect(), 0);
112
123
113− cx.doc().set_selection(selection);
124+ doc.set_selection(selection);
114}
125}
115
126
116pub fn move_next_word_start(cx: &mut Context) {
127pub fn move_next_word_start(cx: &mut Context) {
@@ -139,17 +150,19 @@ pub fn move_next_word_end(cx: &mut Context) {
139}
150}
140
151
141pub fn move_file_start(cx: &mut Context) {
152pub fn move_file_start(cx: &mut Context) {
153+ let doc = cx.doc();
142− cx.doc().set_selection(Selection::point(0));
154+ doc.set_selection(Selection::point(0));
143
155
144− cx.doc().mode = Mode::Normal;
156+ doc.mode = Mode::Normal;
145}
157}
146
158
147pub fn move_file_end(cx: &mut Context) {
159pub fn move_file_end(cx: &mut Context) {
148− let text = &cx.doc().text();
160+ let doc = cx.doc();
161+ let text = doc.text();
149 let last_line = text.line_to_char(text.len_lines().saturating_sub(2));
162 let last_line = text.line_to_char(text.len_lines().saturating_sub(2));
150− cx.doc().set_selection(Selection::point(last_line));
163+ doc.set_selection(Selection::point(last_line));
151
164
152− cx.doc().mode = Mode::Normal;
165+ doc.mode = Mode::Normal;
153}
166}
154
167
155pub fn extend_next_word_start(cx: &mut Context) {
168pub fn extend_next_word_start(cx: &mut Context) {
@@ -161,7 +174,7 @@ pub fn extend_next_word_start(cx: &mut Context) {
161 range
174 range
162 }); // TODO: count
175 }); // TODO: count
163
176
164− cx.doc().set_selection(selection);
177+ doc.set_selection(selection);
165}
178}
166
179
167pub fn extend_prev_word_start(cx: &mut Context) {
180pub fn extend_prev_word_start(cx: &mut Context) {
@@ -172,7 +185,7 @@ pub fn extend_prev_word_start(cx: &mut Context) {
172 range.head = pos;
185 range.head = pos;
173 range
186 range
174 }); // TODO: count
187 }); // TODO: count
175− cx.doc().set_selection(selection);
188+ doc.set_selection(selection);
176}
189}
177
190
178pub fn extend_next_word_end(cx: &mut Context) {
191pub fn extend_next_word_end(cx: &mut Context) {
@@ -184,7 +197,7 @@ pub fn extend_next_word_end(cx: &mut Context) {
184 range
197 range
185 }); // TODO: count
198 }); // TODO: count
186
199
187− cx.doc().set_selection(selection);
200+ doc.set_selection(selection);
188}
201}
189
202
190pub fn check_cursor_in_view(view: &View) -> bool {
203pub fn check_cursor_in_view(view: &View) -> bool {
@@ -309,11 +322,8 @@ pub fn select_regex(cx: &mut Context) {
309 selection::select_on_matches(text, doc.selection(), &regex).expect("no matches");
322 selection::select_on_matches(text, doc.selection(), &regex).expect("no matches");
310 doc.set_selection(selection);
323 doc.set_selection(selection);
311 });
324 });
312− cx.callback = Some(Box::new(
325+
313− move |compositor: &mut Compositor, editor: &mut Editor| {
314− compositor.push(Box::new(prompt));
326+ cx.push_layer(Box::new(prompt));
315− },
316− ));
317}
327}
318
328
319pub fn split_selection(cx: &mut Context) {
329pub fn split_selection(cx: &mut Context) {
@@ -336,11 +346,7 @@ pub fn split_selection(cx: &mut Context) {
336 doc.set_selection(selection);
346 doc.set_selection(selection);
337 });
347 });
338
348
339− cx.callback = Some(Box::new(
340− move |compositor: &mut Compositor, editor: &mut Editor| {
341− compositor.push(Box::new(prompt));
349+ cx.push_layer(Box::new(prompt));
342− },
343− ));
344}
350}
345
351
346pub fn split_selection_on_newline(cx: &mut Context) {
352pub fn split_selection_on_newline(cx: &mut Context) {
@@ -393,11 +399,7 @@ pub fn search(cx: &mut Context) {
393 register::set('\\', vec![regex.as_str().to_string()]);
399 register::set('\\', vec![regex.as_str().to_string()]);
394 });
400 });
395
401
396− cx.callback = Some(Box::new(
397− move |compositor: &mut Compositor, editor: &mut Editor| {
398− compositor.push(Box::new(prompt));
402+ cx.push_layer(Box::new(prompt));
399− },
400− ));
401}
403}
402
404
403pub fn search_next(cx: &mut Context) {
405pub fn search_next(cx: &mut Context) {
@@ -418,74 +420,76 @@ pub fn search_next(cx: &mut Context) {
418
420
419pub fn select_line(cx: &mut Context) {
421pub fn select_line(cx: &mut Context) {
420 // TODO: count
422 // TODO: count
423+ let doc = cx.doc();
421− let pos = cx.doc().selection().primary();
424+ let pos = doc.selection().primary();
422− let text = cx.doc().text();
425+ let text = doc.text();
423 let line = text.char_to_line(pos.head);
426 let line = text.char_to_line(pos.head);
424 let start = text.line_to_char(line);
427 let start = text.line_to_char(line);
425 let end = text.line_to_char(line + 1).saturating_sub(1);
428 let end = text.line_to_char(line + 1).saturating_sub(1);
426
429
427− cx.doc().set_selection(Selection::single(start, end));
430+ doc.set_selection(Selection::single(start, end));
428}
431}
429
432
430// heuristic: append changes to history after each command, unless we're in insert mode
433// heuristic: append changes to history after each command, unless we're in insert mode
431
434
432−fn _delete_selection(cx: &mut Context) {
435+fn _delete_selection(doc: &mut Document) {
436+ let transaction =
433− let transaction = Transaction::change_by_selection(&cx.doc().state, |range| {
437+ Transaction::change_by_selection(&doc.state, |range| (range.from(), range.to() + 1, None));
434− (range.from(), range.to() + 1, None)
435− });
436− cx.doc().apply(&transaction);
438+ doc.apply(&transaction);
437}
439}
438
440
439pub fn delete_selection(cx: &mut Context) {
441pub fn delete_selection(cx: &mut Context) {
442+ let doc = cx.doc();
440− _delete_selection(cx);
443+ _delete_selection(doc);
441
444
442− append_changes_to_history(cx);
445+ append_changes_to_history(doc);
443}
446}
444
447
445pub fn change_selection(cx: &mut Context) {
448pub fn change_selection(cx: &mut Context) {
449+ let doc = cx.doc();
446− _delete_selection(cx);
450+ _delete_selection(doc);
447 insert_mode(cx);
451 insert_mode(cx);
448}
452}
449
453
450pub fn collapse_selection(cx: &mut Context) {
454pub fn collapse_selection(cx: &mut Context) {
451− let selection = cx
452− .doc()
455+ let doc = cx.doc();
456+ let selection = doc
453 .selection()
457 .selection()
454 .transform(|range| Range::new(range.head, range.head));
458 .transform(|range| Range::new(range.head, range.head));
455
459
456− cx.doc().set_selection(selection);
460+ doc.set_selection(selection);
457}
461}
458
462
459pub fn flip_selections(cx: &mut Context) {
463pub fn flip_selections(cx: &mut Context) {
460− let selection = cx
461− .doc()
464+ let doc = cx.doc();
465+ let selection = doc
462 .selection()
466 .selection()
463 .transform(|range| Range::new(range.head, range.anchor));
467 .transform(|range| Range::new(range.head, range.anchor));
464
468
465− cx.doc().set_selection(selection);
469+ doc.set_selection(selection);
466}
470}
467
471
468−fn enter_insert_mode(cx: &mut Context) {
472+fn enter_insert_mode(doc: &mut Document) {
469− cx.doc().mode = Mode::Insert;
473+ doc.mode = Mode::Insert;
470
474
471 // TODO: store selection for undo
475 // TODO: store selection for undo
472}
476}
473
477
474// inserts at the start of each selection
478// inserts at the start of each selection
475pub fn insert_mode(cx: &mut Context) {
479pub fn insert_mode(cx: &mut Context) {
480+ let doc = cx.doc();
476− enter_insert_mode(cx);
481+ enter_insert_mode(doc);
477
482
478− let selection = cx
483+ let selection = doc
479− .doc()
480 .selection()
484 .selection()
481 .transform(|range| Range::new(range.to(), range.from()));
485 .transform(|range| Range::new(range.to(), range.from()));
482− cx.doc().set_selection(selection);
486+ doc.set_selection(selection);
483}
487}
484
488
485// inserts at the end of each selection
489// inserts at the end of each selection
486pub fn append_mode(cx: &mut Context) {
490pub fn append_mode(cx: &mut Context) {
487− enter_insert_mode(cx);
488 let doc = cx.doc();
491 let doc = cx.doc();
492+ enter_insert_mode(doc);
489 doc.restore_cursor = true;
493 doc.restore_cursor = true;
490
494
491 // TODO: as transaction
495 // TODO: as transaction
@@ -503,98 +507,56 @@ pub fn append_mode(cx: &mut Context) {
503// TODO: I, A, o and O can share a lot of the primitives.
507// TODO: I, A, o and O can share a lot of the primitives.
504pub fn command_mode(cx: &mut Context) {
508pub fn command_mode(cx: &mut Context) {
505 let executor = cx.executor;
509 let executor = cx.executor;
506− cx.callback = Some(Box::new(
507− move |compositor: &mut Compositor, editor: &mut Editor| {
508− let prompt = Prompt::new(
510+ let prompt = Prompt::new(
509− ":".to_owned(),
511+ ":".to_owned(),
510− |_input: &str| {
512+ |_input: &str| {
511− // TODO: i need this duplicate list right now to avoid borrow checker issues
513+ // TODO: i need this duplicate list right now to avoid borrow checker issues
512− let command_list = vec![
514+ let command_list = vec![
513− "q".to_string(),
515+ "q".to_string(),
514− "o".to_string(),
516+ "o".to_string(),
515− "w".to_string(),
517+ "w".to_string(),
516− // String::from("q"),
518+ // String::from("q"),
517− // String::from("aaa"),
518− // String::from("bbb"),
519− // String::from("ccc"),
520− // String::from("ddd"),
521− // String::from("eee"),
522− // String::from("averylongcommandaverylongcommandaverylongcommandaverylongcommandaverylongcommand"),
523− // String::from("q"),
524− // String::from("aaa"),
525− // String::from("bbb"),
526− // String::from("ccc"),
527− // String::from("ddd"),
528− // String::from("eee"),
529− // String::from("q"),
530− // String::from("aaa"),
531− // String::from("bbb"),
532− // String::from("ccc"),
533− // String::from("ddd"),
534− // String::from("eee"),
535− // String::from("q"),
536− // String::from("aaa"),
537− // String::from("bbb"),
538− // String::from("ccc"),
539− // String::from("ddd"),
540− // String::from("eee"),
541− // String::from("q"),
542− // String::from("aaa"),
543− // String::from("bbb"),
544− // String::from("ccc"),
545− // String::from("ddd"),
546− // String::from("eee"),
547− ];
519+ ];
548− command_list
520+ command_list
549− .into_iter()
521+ .into_iter()
550− .filter(|command| command.contains(_input))
522+ .filter(|command| command.contains(_input))
551− .collect()
523+ .collect()
552− }, // completion
524+ }, // completion
553− move |editor: &mut Editor, input: &str, event: PromptEvent| {
525+ move |editor: &mut Editor, input: &str, event: PromptEvent| {
554− if event != PromptEvent::Validate {
526+ if event != PromptEvent::Validate {
555− return;
527+ return;
556− }
557−
558− let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
559−
560− match *parts.as_slice() {
561− ["q"] => {
562− editor.tree.remove(editor.view().id);
563− // editor.should_close = true,
564− }
565− ["o", path] => {
566− editor.open(path.into(), executor);
567− }
568− ["w"] => {
569− // TODO: non-blocking via save() command
570− smol::block_on(editor.view_mut().doc.save());
571− }
528+ }
572
529
573− _ => (),
530+ let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
574− }
531+
532+ match *parts.as_slice() {
533+ ["q"] => {
534+ editor.tree.remove(editor.view().id);
535+ // editor.should_close = true,
575− },
536+ }
576− );
537+ ["o", path] => {
577− compositor.push(Box::new(prompt));
538+ editor.open(path.into(), executor);
539+ }
540+ ["w"] => {
541+ // TODO: non-blocking via save() command
542+ smol::block_on(editor.view_mut().doc.save());
543+ }
544+
545+ _ => (),
546+ }
578 },
547 },
579− ));
548+ );
549+ cx.push_layer(Box::new(prompt));
580}
550}
581pub fn file_picker(cx: &mut Context) {
551pub fn file_picker(cx: &mut Context) {
582 let picker = ui::file_picker("./", cx.executor);
552 let picker = ui::file_picker("./", cx.executor);
583− cx.callback = Some(Box::new(
584− |compositor: &mut Compositor, editor: &mut Editor| {
585− compositor.push(Box::new(picker));
553+ cx.push_layer(Box::new(picker));
586− },
587− ));
588}
554}
589
555
590pub fn buffer_picker(cx: &mut Context) {
556pub fn buffer_picker(cx: &mut Context) {
591 unimplemented!()
557 unimplemented!()
592− // cx.callback = Some(Box::new(
593− // |compositor: &mut Compositor, editor: &mut Editor| {
594− // let picker = ui::buffer_picker(&editor.views, editor.focus);
558+ // let picker = ui::buffer_picker(&editor.views, editor.focus);
595− // compositor.push(Box::new(picker));
559+ // cx.push_layer(Box::new(picker));
596− // },
597− // ));
598}
560}
599
561
600// calculate line numbers for each selection range
562// calculate line numbers for each selection range
@@ -614,23 +576,24 @@ fn selection_lines(state: &State) -> Vec<usize> {
614
576
615// I inserts at the start of each line with a selection
577// I inserts at the start of each line with a selection
616pub fn prepend_to_line(cx: &mut Context) {
578pub fn prepend_to_line(cx: &mut Context) {
579+ let doc = cx.doc();
617− enter_insert_mode(cx);
580+ enter_insert_mode(doc);
618
581
619 move_line_start(cx);
582 move_line_start(cx);
620}
583}
621
584
622// A inserts at the end of each line with a selection
585// A inserts at the end of each line with a selection
623pub fn append_to_line(cx: &mut Context) {
586pub fn append_to_line(cx: &mut Context) {
587+ let doc = cx.doc();
624− enter_insert_mode(cx);
588+ enter_insert_mode(doc);
625
589
626 move_line_end(cx);
590 move_line_end(cx);
627}
591}
628
592
629// o inserts a new line after each line with a selection
593// o inserts a new line after each line with a selection
630pub fn open_below(cx: &mut Context) {
594pub fn open_below(cx: &mut Context) {
631− enter_insert_mode(cx);
632−
633 let doc = cx.doc();
595 let doc = cx.doc();
596+ enter_insert_mode(doc);
634
597
635 let lines = selection_lines(&doc.state);
598 let lines = selection_lines(&doc.state);
636
599
@@ -687,40 +650,40 @@ pub fn open_below(cx: &mut Context) {
687
650
688// O inserts a new line before each line with a selection
651// O inserts a new line before each line with a selection
689
652
690−fn append_changes_to_history(cx: &mut Context) {
653+fn append_changes_to_history(doc: &mut Document) {
691− if cx.doc().changes.is_empty() {
654+ if doc.changes.is_empty() {
692 return;
655 return;
693 }
656 }
694
657
695 // TODO: change -> change -> undo -> change -> change fails, probably old_state needs reset
658 // TODO: change -> change -> undo -> change -> change fails, probably old_state needs reset
696
659
697− let new_changeset = ChangeSet::new(cx.doc().text());
660+ let new_changeset = ChangeSet::new(doc.text());
698− let changes = std::mem::replace(&mut cx.doc().changes, new_changeset);
661+ let changes = std::mem::replace(&mut doc.changes, new_changeset);
699 // Instead of doing this messy merge we could always commit, and based on transaction
662 // Instead of doing this messy merge we could always commit, and based on transaction
700 // annotations either add a new layer or compose into the previous one.
663 // annotations either add a new layer or compose into the previous one.
701− let transaction = Transaction::from(changes).with_selection(cx.doc().selection().clone());
664+ let transaction = Transaction::from(changes).with_selection(doc.selection().clone());
702
665
703 // increment document version
666 // increment document version
704 // TODO: needs to happen on undo/redo too
667 // TODO: needs to happen on undo/redo too
705− cx.doc().version += 1;
668+ doc.version += 1;
706
669
707 // TODO: trigger lsp/documentDidChange with changes
670 // TODO: trigger lsp/documentDidChange with changes
708
671
709 // HAXX: we need to reconstruct the state as it was before the changes..
672 // HAXX: we need to reconstruct the state as it was before the changes..
710− let old_state = cx.doc().old_state.take().expect("no old_state available");
673+ let old_state = doc.old_state.take().expect("no old_state available");
711
674
712 // TODO: take transaction by value?
675 // TODO: take transaction by value?
713− cx.doc().history.commit_revision(&transaction, &old_state);
676+ doc.history.commit_revision(&transaction, &old_state);
714
677
715 // TODO: notify LSP of changes
678 // TODO: notify LSP of changes
716}
679}
717
680
718pub fn normal_mode(cx: &mut Context) {
681pub fn normal_mode(cx: &mut Context) {
719− cx.doc().mode = Mode::Normal;
682+ let doc = cx.doc();
720
683
721− append_changes_to_history(cx);
684+ doc.mode = Mode::Normal;
722
685
723− let doc = cx.doc();
686+ append_changes_to_history(doc);
724
687
725 // if leaving append mode, move cursor back by 1
688 // if leaving append mode, move cursor back by 1
726 if doc.restore_cursor {
689 if doc.restore_cursor {
@@ -746,10 +709,11 @@ pub mod insert {
746 use super::*;
709 use super::*;
747 // TODO: insert means add text just before cursor, on exit we should be on the last letter.
710 // TODO: insert means add text just before cursor, on exit we should be on the last letter.
748 pub fn insert_char(cx: &mut Context, c: char) {
711 pub fn insert_char(cx: &mut Context, c: char) {
712+ let doc = cx.doc();
749 let c = Tendril::from_char(c);
713 let c = Tendril::from_char(c);
750− let transaction = Transaction::insert(&cx.doc().state, c);
714+ let transaction = Transaction::insert(&doc.state, c);
751
715
752− cx.doc().apply(&transaction);
716+ doc.apply(&transaction);
753 }
717 }
754
718
755 pub fn insert_tab(cx: &mut Context) {
719 pub fn insert_tab(cx: &mut Context) {
@@ -884,7 +848,7 @@ pub fn paste(cx: &mut Context) {
884 };
848 };
885
849
886 doc.apply(&transaction);
850 doc.apply(&transaction);
887− append_changes_to_history(cx);
851+ append_changes_to_history(doc);
888 }
852 }
889}
853}
890
854
@@ -919,8 +883,8 @@ pub fn indent(cx: &mut Context) {
919 (pos, pos, Some(indent.clone()))
883 (pos, pos, Some(indent.clone()))
920 }),
884 }),
921 );
885 );
922− cx.doc().apply(&transaction);
886+ doc.apply(&transaction);
923− append_changes_to_history(cx);
887+ append_changes_to_history(doc);
924}
888}
925
889
926pub fn unindent(cx: &mut Context) {
890pub fn unindent(cx: &mut Context) {
@@ -953,7 +917,7 @@ pub fn unindent(cx: &mut Context) {
953 let transaction = Transaction::change(&doc.state, changes.into_iter());
917 let transaction = Transaction::change(&doc.state, changes.into_iter());
954
918
955 doc.apply(&transaction);
919 doc.apply(&transaction);
956− append_changes_to_history(cx);
920+ append_changes_to_history(doc);
957}
921}
958
922
959//
923//
@@ -979,12 +943,11 @@ pub fn completion(cx: &mut Context) {
979 let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
943 let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
980
944
981 // TODO: handle fails
945 // TODO: handle fails
982− let res =
983− smol::block_on(language_server.completion(cx.doc().identifier(), pos)).unwrap_or_default();
946+ let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap_or_default();
984
947
985 // TODO: if no completion, show some message or something
948 // TODO: if no completion, show some message or something
986 if !res.is_empty() {
949 if !res.is_empty() {
987− let snapshot = cx.doc().state.clone();
950+ let snapshot = doc.state.clone();
988 let mut menu = ui::Menu::new(
951 let mut menu = ui::Menu::new(
989 res,
952 res,
990 |item| {
953 |item| {
@@ -1047,7 +1010,7 @@ pub fn completion(cx: &mut Context) {
1047 let transaction =
1010 let transaction =
1048 util::generate_transaction_from_edits(&doc.state, vec![edit]);
1011 util::generate_transaction_from_edits(&doc.state, vec![edit]);
1049 doc.apply(&transaction);
1012 doc.apply(&transaction);
1050− // TODO: append_changes_to_history(cx); if not in insert mode?
1013+ // TODO: append_changes_to_history(doc); if not in insert mode?
1051 }
1014 }
1052 _ => (),
1015 _ => (),
1053 };
1016 };
helix-term/src/ui/editor.rs+1−1
@@ -436,7 +436,7 @@ impl Component for EditorView {
436 // mode => write!(stdout, "\x1B[2 q"),
436 // mode => write!(stdout, "\x1B[2 q"),
437 // };
437 // };
438 let view = editor.view();
438 let view = editor.view();
439− let cursor = view.doc.state.selection().cursor();
439+ let cursor = view.doc.selection().cursor();
440
440
441 let mut pos = view
441 let mut pos = view
442 .screen_coords_at_pos(view.doc.text().slice(..), cursor)
442 .screen_coords_at_pos(view.doc.text().slice(..), cursor)
helix-view/src/editor.rs+1−2
@@ -54,8 +54,7 @@ impl Editor {
54 }
54 }
55
55
56 let view = View::new(doc)?;
56 let view = View::new(doc)?;
57− let id = self.tree.insert(view);
57+ self.tree.insert(view);
58− self.tree.get_mut(id).id = id;
59 Ok(())
58 Ok(())
60 }
59 }
61
60
helix-view/src/tree.rs+1
@@ -99,6 +99,7 @@ impl Tree {
99 let mut node = Node::view(view);
99 let mut node = Node::view(view);
100 node.parent = parent;
100 node.parent = parent;
101 let node = self.nodes.insert(node);
101 let node = self.nodes.insert(node);
102+ self.get_mut(node).id = node;
102
103
103 let container = match &mut self.nodes[parent] {
104 let container = match &mut self.nodes[parent] {
104 Node {
105 Node {