@@ -586,7 +586,7 @@ fn goto_line_end(cx: &mut Context) {
586 goto_line_end_impl(
586 goto_line_end_impl(
589− if doc.mode == Mode::Select {
589+ if cx.editor.mode == Mode::Select {
590 Movement::Extend
590 Movement::Extend
592 Movement::Move
592 Movement::Move
@@ -616,7 +616,7 @@ fn goto_line_end_newline(cx: &mut Context) {
616 goto_line_end_newline_impl(
616 goto_line_end_newline_impl(
619− if doc.mode == Mode::Select {
619+ if cx.editor.mode == Mode::Select {
620 Movement::Extend
620 Movement::Extend
622 Movement::Move
622 Movement::Move
@@ -647,7 +647,7 @@ fn goto_line_start(cx: &mut Context) {
647 goto_line_start_impl(
647 goto_line_start_impl(
650− if doc.mode == Mode::Select {
650+ if cx.editor.mode == Mode::Select {
651 Movement::Extend
651 Movement::Extend
653 Movement::Move
653 Movement::Move
@@ -752,7 +752,7 @@ fn goto_first_nonwhitespace(cx: &mut Context) {
753 if let Some(pos) = find_first_non_whitespace_char(text.line(line)) {
753 if let Some(pos) = find_first_non_whitespace_char(text.line(line)) {
754 let pos = pos + text.line_to_char(line);
754 let pos = pos + text.line_to_char(line);
755− range.put_cursor(text, pos, doc.mode == Mode::Select)
755+ range.put_cursor(text, pos, cx.editor.mode == Mode::Select)
@@ -952,7 +952,7 @@ where
952 let motion = move |editor: &mut Editor| {
952 let motion = move |editor: &mut Editor| {
953 let (view, doc) = current!(editor);
953 let (view, doc) = current!(editor);
954 let text = doc.text().slice(..);
954 let text = doc.text().slice(..);
955− let behavior = if doc.mode == Mode::Select {
955+ let behavior = if editor.mode == Mode::Select {
956 Movement::Extend
956 Movement::Extend
958 Movement::Move
958 Movement::Move
@@ -985,7 +985,7 @@ fn goto_file_start(cx: &mut Context) {
985 let selection = doc
985 let selection = doc
986 .selection(view.id)
986 .selection(view.id)
988− .transform(|range| range.put_cursor(text, 0, doc.mode == Mode::Select));
988+ .transform(|range| range.put_cursor(text, 0, cx.editor.mode == Mode::Select));
989 push_jump(view, doc);
989 push_jump(view, doc);
990 doc.set_selection(view.id, selection);
990 doc.set_selection(view.id, selection);
@@ -998,7 +998,7 @@ fn goto_file_end(cx: &mut Context) {
998 let selection = doc
998 let selection = doc
999 .selection(view.id)
999 .selection(view.id)
1000 .clone()
1000 .clone()
1001− .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
1001+ .transform(|range| range.put_cursor(text, pos, cx.editor.mode == Mode::Select));
1002 push_jump(view, doc);
1002 push_jump(view, doc);
1003 doc.set_selection(view.id, selection);
1003 doc.set_selection(view.id, selection);
@@ -1375,7 +1375,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
1375 if line != cursor.row {
1375 if line != cursor.row {
1376 let head = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
1376 let head = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
1378− let anchor = if doc.mode == Mode::Select {
1378+ let anchor = if cx.editor.mode == Mode::Select {
1379 range.anchor
1379 range.anchor
1380 } else {
1380 } else {
@@ -2098,7 +2098,7 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
2098 exit_select_mode(cx);
2098 exit_select_mode(cx);
2100 Operation::Change => {
2100 Operation::Change => {
2101− enter_insert_mode(doc);
2101+ enter_insert_mode(cx);
@@ -2167,14 +2167,14 @@ fn ensure_selections_forward(cx: &mut Context) {
2167 doc.set_selection(view.id, selection);
2167 doc.set_selection(view.id, selection);
2170−fn enter_insert_mode(doc: &mut Document) {
2170+fn enter_insert_mode(cx: &mut Context) {
2171− doc.mode = Mode::Insert;
2171+ cx.editor.mode = Mode::Insert;
2174// inserts at the start of each selection
2174// inserts at the start of each selection
2175fn insert_mode(cx: &mut Context) {
2175fn insert_mode(cx: &mut Context) {
2176+ enter_insert_mode(cx);
2176 let (view, doc) = current!(cx.editor);
2177 let (view, doc) = current!(cx.editor);
2177− enter_insert_mode(doc);
2179 log::trace!(
2179 log::trace!(
2180 "entering insert mode with sel: {:?}, text: {:?}",
2180 "entering insert mode with sel: {:?}, text: {:?}",
@@ -2192,8 +2192,8 @@ fn insert_mode(cx: &mut Context) {
2193// inserts at the end of each selection
2193// inserts at the end of each selection
2194fn append_mode(cx: &mut Context) {
2194fn append_mode(cx: &mut Context) {
2195+ enter_insert_mode(cx);
2195 let (view, doc) = current!(cx.editor);
2196 let (view, doc) = current!(cx.editor);
2196− enter_insert_mode(doc);
2197 doc.restore_cursor = true;
2197 doc.restore_cursor = true;
2198 let text = doc.text().slice(..);
2198 let text = doc.text().slice(..);
@@ -2421,9 +2421,9 @@ impl ui::menu::Item for MappableCommand {
2421pub fn command_palette(cx: &mut Context) {
2421pub fn command_palette(cx: &mut Context) {
2422 cx.callback = Some(Box::new(
2422 cx.callback = Some(Box::new(
2423 move |compositor: &mut Compositor, cx: &mut compositor::Context| {
2423 move |compositor: &mut Compositor, cx: &mut compositor::Context| {
2424− let doc = doc_mut!(cx.editor);
2426− compositor.find::<ui::EditorView>().unwrap().keymaps.map()[&doc.mode].reverse_map();
2424+ let keymap = compositor.find::<ui::EditorView>().unwrap().keymaps.map()
2428 let mut commands: Vec<MappableCommand> = MappableCommand::STATIC_COMMAND_LIST.into();
2428 let mut commands: Vec<MappableCommand> = MappableCommand::STATIC_COMMAND_LIST.into();
2429 commands.extend(typed::TYPABLE_COMMAND_LIST.iter().map(|cmd| {
2429 commands.extend(typed::TYPABLE_COMMAND_LIST.iter().map(|cmd| {
@@ -2464,14 +2464,13 @@ fn last_picker(cx: &mut Context) {
2464// I inserts at the first nonwhitespace character of each line with a selection
2464// I inserts at the first nonwhitespace character of each line with a selection
2465fn prepend_to_line(cx: &mut Context) {
2465fn prepend_to_line(cx: &mut Context) {
2466 goto_first_nonwhitespace(cx);
2466 goto_first_nonwhitespace(cx);
2467− let doc = doc_mut!(cx.editor);
2468− enter_insert_mode(doc);
2467+ enter_insert_mode(cx);
2471// A inserts at the end of each line with a selection
2470// A inserts at the end of each line with a selection
2472fn append_to_line(cx: &mut Context) {
2471fn append_to_line(cx: &mut Context) {
2472+ enter_insert_mode(cx);
2473 let (view, doc) = current!(cx.editor);
2473 let (view, doc) = current!(cx.editor);
2474− enter_insert_mode(doc);
2476 let selection = doc.selection(view.id).clone().transform(|range| {
2475 let selection = doc.selection(view.id).clone().transform(|range| {
2477 let text = doc.text().slice(..);
2476 let text = doc.text().slice(..);
@@ -2527,8 +2526,8 @@ pub enum Open {
2528fn open(cx: &mut Context, open: Open) {
2527fn open(cx: &mut Context, open: Open) {
2529 let count = cx.count();
2528 let count = cx.count();
2529+ enter_insert_mode(cx);
2530 let (view, doc) = current!(cx.editor);
2530 let (view, doc) = current!(cx.editor);
2531− enter_insert_mode(doc);
2533 let text = doc.text().slice(..);
2532 let text = doc.text().slice(..);
2534 let contents = doc.text();
2533 let contents = doc.text();
@@ -2606,13 +2605,12 @@ fn open_above(cx: &mut Context) {
2608fn normal_mode(cx: &mut Context) {
2607fn normal_mode(cx: &mut Context) {
2609− let (view, doc) = current!(cx.editor);
2611− if doc.mode == Mode::Normal {
2608+ if cx.editor.mode == Mode::Normal {
2615− doc.mode = Mode::Normal;
2612+ cx.editor.mode = Mode::Normal;
2613+ let (view, doc) = current!(cx.editor);
2617 try_restore_indent(doc, view.id);
2615 try_restore_indent(doc, view.id);
@@ -2690,7 +2688,7 @@ fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
2690 let selection = doc
2688 let selection = doc
2691 .selection(view.id)
2689 .selection(view.id)
2692 .clone()
2690 .clone()
2693− .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
2691+ .transform(|range| range.put_cursor(text, pos, editor.mode == Mode::Select));
2695 push_jump(view, doc);
2693 push_jump(view, doc);
2696 doc.set_selection(view.id, selection);
2694 doc.set_selection(view.id, selection);
@@ -2710,7 +2708,7 @@ fn goto_last_line(cx: &mut Context) {
2710 let selection = doc
2708 let selection = doc
2711 .selection(view.id)
2709 .selection(view.id)
2712 .clone()
2710 .clone()
2713− .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
2711+ .transform(|range| range.put_cursor(text, pos, cx.editor.mode == Mode::Select));
2715 push_jump(view, doc);
2713 push_jump(view, doc);
2716 doc.set_selection(view.id, selection);
2714 doc.set_selection(view.id, selection);
@@ -2733,7 +2731,7 @@ fn goto_last_modification(cx: &mut Context) {
2733 let selection = doc
2731 let selection = doc
2734 .selection(view.id)
2732 .selection(view.id)
2735 .clone()
2733 .clone()
2736− .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
2734+ .transform(|range| range.put_cursor(text, pos, cx.editor.mode == Mode::Select));
2737 doc.set_selection(view.id, selection);
2735 doc.set_selection(view.id, selection);
@@ -2770,13 +2768,12 @@ fn select_mode(cx: &mut Context) {
2771 doc.set_selection(view.id, selection);
2769 doc.set_selection(view.id, selection);
2773− doc_mut!(cx.editor).mode = Mode::Select;
2771+ cx.editor.mode = Mode::Select;
2776fn exit_select_mode(cx: &mut Context) {
2774fn exit_select_mode(cx: &mut Context) {
2777− let doc = doc_mut!(cx.editor);
2778− if doc.mode == Mode::Select {
2775+ if cx.editor.mode == Mode::Select {
2779− doc.mode = Mode::Normal;
2776+ cx.editor.mode = Mode::Normal;
@@ -3439,11 +3436,11 @@ fn paste_impl(values: &[String], doc: &mut Document, view: &View, action: Paste,
3440pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
3437pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
3441 let count = cx.count();
3438 let count = cx.count();
3442− let (view, doc) = current!(cx.editor);
3443− let paste = match doc.mode {
3439+ let paste = match cx.editor.mode {
3444 Mode::Insert | Mode::Select => Paste::Cursor,
3440 Mode::Insert | Mode::Select => Paste::Cursor,
3445 Mode::Normal => Paste::Before,
3441 Mode::Normal => Paste::Before,
3443+ let (view, doc) = current!(cx.editor);
3447 paste_impl(&[contents], doc, view, paste, count);
3444 paste_impl(&[contents], doc, view, paste, count);
@@ -3838,8 +3835,7 @@ pub fn completion(cx: &mut Context) {
3838 cx.callback(
3835 cx.callback(
3840 move |editor, compositor, response: Option<lsp::CompletionResponse>| {
3837 move |editor, compositor, response: Option<lsp::CompletionResponse>| {
3841− let doc = doc!(editor);
3842− if doc.mode() != Mode::Insert {
3838+ if editor.mode != Mode::Insert {
3843 // we're not in insert mode anymore
3839 // we're not in insert mode anymore
@@ -4046,7 +4042,7 @@ fn match_brackets(cx: &mut Context) {
4046 if let Some(pos) =
4042 if let Some(pos) =
4047 match_brackets::find_matching_bracket_fuzzy(syntax, doc.text(), range.cursor(text))
4043 match_brackets::find_matching_bracket_fuzzy(syntax, doc.text(), range.cursor(text))
4049− range.put_cursor(text, pos, doc.mode == Mode::Select)
4045+ range.put_cursor(text, pos, cx.editor.mode == Mode::Select)
4050 } else {
4046 } else {