summaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs68
1 files changed, 32 insertions, 36 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index cd92c42d..906f201a 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -586,7 +586,7 @@ fn goto_line_end(cx: &mut Context) {
goto_line_end_impl(
view,
doc,
- if doc.mode == Mode::Select {
+ if cx.editor.mode == Mode::Select {
Movement::Extend
} else {
Movement::Move
@@ -616,7 +616,7 @@ fn goto_line_end_newline(cx: &mut Context) {
goto_line_end_newline_impl(
view,
doc,
- if doc.mode == Mode::Select {
+ if cx.editor.mode == Mode::Select {
Movement::Extend
} else {
Movement::Move
@@ -647,7 +647,7 @@ fn goto_line_start(cx: &mut Context) {
goto_line_start_impl(
view,
doc,
- if doc.mode == Mode::Select {
+ if cx.editor.mode == Mode::Select {
Movement::Extend
} else {
Movement::Move
@@ -752,7 +752,7 @@ fn goto_first_nonwhitespace(cx: &mut Context) {
if let Some(pos) = find_first_non_whitespace_char(text.line(line)) {
let pos = pos + text.line_to_char(line);
- range.put_cursor(text, pos, doc.mode == Mode::Select)
+ range.put_cursor(text, pos, cx.editor.mode == Mode::Select)
} else {
range
}
@@ -952,7 +952,7 @@ where
let motion = move |editor: &mut Editor| {
let (view, doc) = current!(editor);
let text = doc.text().slice(..);
- let behavior = if doc.mode == Mode::Select {
+ let behavior = if editor.mode == Mode::Select {
Movement::Extend
} else {
Movement::Move
@@ -985,7 +985,7 @@ fn goto_file_start(cx: &mut Context) {
let selection = doc
.selection(view.id)
.clone()
- .transform(|range| range.put_cursor(text, 0, doc.mode == Mode::Select));
+ .transform(|range| range.put_cursor(text, 0, cx.editor.mode == Mode::Select));
push_jump(view, doc);
doc.set_selection(view.id, selection);
}
@@ -998,7 +998,7 @@ fn goto_file_end(cx: &mut Context) {
let selection = doc
.selection(view.id)
.clone()
- .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
+ .transform(|range| range.put_cursor(text, pos, cx.editor.mode == Mode::Select));
push_jump(view, doc);
doc.set_selection(view.id, selection);
}
@@ -1375,7 +1375,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
if line != cursor.row {
let head = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
- let anchor = if doc.mode == Mode::Select {
+ let anchor = if cx.editor.mode == Mode::Select {
range.anchor
} else {
head
@@ -2098,7 +2098,7 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
exit_select_mode(cx);
}
Operation::Change => {
- enter_insert_mode(doc);
+ enter_insert_mode(cx);
}
}
}
@@ -2167,14 +2167,14 @@ fn ensure_selections_forward(cx: &mut Context) {
doc.set_selection(view.id, selection);
}
-fn enter_insert_mode(doc: &mut Document) {
- doc.mode = Mode::Insert;
+fn enter_insert_mode(cx: &mut Context) {
+ cx.editor.mode = Mode::Insert;
}
// inserts at the start of each selection
fn insert_mode(cx: &mut Context) {
+ enter_insert_mode(cx);
let (view, doc) = current!(cx.editor);
- enter_insert_mode(doc);
log::trace!(
"entering insert mode with sel: {:?}, text: {:?}",
@@ -2192,8 +2192,8 @@ fn insert_mode(cx: &mut Context) {
// inserts at the end of each selection
fn append_mode(cx: &mut Context) {
+ enter_insert_mode(cx);
let (view, doc) = current!(cx.editor);
- enter_insert_mode(doc);
doc.restore_cursor = true;
let text = doc.text().slice(..);
@@ -2421,9 +2421,9 @@ impl ui::menu::Item for MappableCommand {
pub fn command_palette(cx: &mut Context) {
cx.callback = Some(Box::new(
move |compositor: &mut Compositor, cx: &mut compositor::Context| {
- let doc = doc_mut!(cx.editor);
- let keymap =
- compositor.find::<ui::EditorView>().unwrap().keymaps.map()[&doc.mode].reverse_map();
+ let keymap = compositor.find::<ui::EditorView>().unwrap().keymaps.map()
+ [&cx.editor.mode]
+ .reverse_map();
let mut commands: Vec<MappableCommand> = MappableCommand::STATIC_COMMAND_LIST.into();
commands.extend(typed::TYPABLE_COMMAND_LIST.iter().map(|cmd| {
@@ -2464,14 +2464,13 @@ fn last_picker(cx: &mut Context) {
// I inserts at the first nonwhitespace character of each line with a selection
fn prepend_to_line(cx: &mut Context) {
goto_first_nonwhitespace(cx);
- let doc = doc_mut!(cx.editor);
- enter_insert_mode(doc);
+ enter_insert_mode(cx);
}
// A inserts at the end of each line with a selection
fn append_to_line(cx: &mut Context) {
+ enter_insert_mode(cx);
let (view, doc) = current!(cx.editor);
- enter_insert_mode(doc);
let selection = doc.selection(view.id).clone().transform(|range| {
let text = doc.text().slice(..);
@@ -2527,8 +2526,8 @@ pub enum Open {
fn open(cx: &mut Context, open: Open) {
let count = cx.count();
+ enter_insert_mode(cx);
let (view, doc) = current!(cx.editor);
- enter_insert_mode(doc);
let text = doc.text().slice(..);
let contents = doc.text();
@@ -2606,13 +2605,12 @@ fn open_above(cx: &mut Context) {
}
fn normal_mode(cx: &mut Context) {
- let (view, doc) = current!(cx.editor);
-
- if doc.mode == Mode::Normal {
+ if cx.editor.mode == Mode::Normal {
return;
}
- doc.mode = Mode::Normal;
+ cx.editor.mode = Mode::Normal;
+ let (view, doc) = current!(cx.editor);
try_restore_indent(doc, view.id);
@@ -2690,7 +2688,7 @@ fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
let selection = doc
.selection(view.id)
.clone()
- .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
+ .transform(|range| range.put_cursor(text, pos, editor.mode == Mode::Select));
push_jump(view, doc);
doc.set_selection(view.id, selection);
@@ -2710,7 +2708,7 @@ fn goto_last_line(cx: &mut Context) {
let selection = doc
.selection(view.id)
.clone()
- .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
+ .transform(|range| range.put_cursor(text, pos, cx.editor.mode == Mode::Select));
push_jump(view, doc);
doc.set_selection(view.id, selection);
@@ -2733,7 +2731,7 @@ fn goto_last_modification(cx: &mut Context) {
let selection = doc
.selection(view.id)
.clone()
- .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
+ .transform(|range| range.put_cursor(text, pos, cx.editor.mode == Mode::Select));
doc.set_selection(view.id, selection);
}
}
@@ -2770,13 +2768,12 @@ fn select_mode(cx: &mut Context) {
});
doc.set_selection(view.id, selection);
- doc_mut!(cx.editor).mode = Mode::Select;
+ cx.editor.mode = Mode::Select;
}
fn exit_select_mode(cx: &mut Context) {
- let doc = doc_mut!(cx.editor);
- if doc.mode == Mode::Select {
- doc.mode = Mode::Normal;
+ if cx.editor.mode == Mode::Select {
+ cx.editor.mode = Mode::Normal;
}
}
@@ -3439,11 +3436,11 @@ fn paste_impl(values: &[String], doc: &mut Document, view: &View, action: Paste,
pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
let count = cx.count();
- let (view, doc) = current!(cx.editor);
- let paste = match doc.mode {
+ let paste = match cx.editor.mode {
Mode::Insert | Mode::Select => Paste::Cursor,
Mode::Normal => Paste::Before,
};
+ let (view, doc) = current!(cx.editor);
paste_impl(&[contents], doc, view, paste, count);
}
@@ -3838,8 +3835,7 @@ pub fn completion(cx: &mut Context) {
cx.callback(
future,
move |editor, compositor, response: Option<lsp::CompletionResponse>| {
- let doc = doc!(editor);
- if doc.mode() != Mode::Insert {
+ if editor.mode != Mode::Insert {
// we're not in insert mode anymore
return;
}
@@ -4046,7 +4042,7 @@ fn match_brackets(cx: &mut Context) {
if let Some(pos) =
match_brackets::find_matching_bracket_fuzzy(syntax, doc.text(), range.cursor(text))
{
- range.put_cursor(text, pos, doc.mode == Mode::Select)
+ range.put_cursor(text, pos, cx.editor.mode == Mode::Select)
} else {
range
}