|
|
@ -586,7 +586,7 @@ fn goto_line_end(cx: &mut Context) {
|
|
|
|
goto_line_end_impl(
|
|
|
|
goto_line_end_impl(
|
|
|
|
view,
|
|
|
|
view,
|
|
|
|
doc,
|
|
|
|
doc,
|
|
|
|
if doc.mode == Mode::Select {
|
|
|
|
if cx.editor.mode == Mode::Select {
|
|
|
|
Movement::Extend
|
|
|
|
Movement::Extend
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Movement::Move
|
|
|
|
Movement::Move
|
|
|
@ -616,7 +616,7 @@ fn goto_line_end_newline(cx: &mut Context) {
|
|
|
|
goto_line_end_newline_impl(
|
|
|
|
goto_line_end_newline_impl(
|
|
|
|
view,
|
|
|
|
view,
|
|
|
|
doc,
|
|
|
|
doc,
|
|
|
|
if doc.mode == Mode::Select {
|
|
|
|
if cx.editor.mode == Mode::Select {
|
|
|
|
Movement::Extend
|
|
|
|
Movement::Extend
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Movement::Move
|
|
|
|
Movement::Move
|
|
|
@ -647,7 +647,7 @@ fn goto_line_start(cx: &mut Context) {
|
|
|
|
goto_line_start_impl(
|
|
|
|
goto_line_start_impl(
|
|
|
|
view,
|
|
|
|
view,
|
|
|
|
doc,
|
|
|
|
doc,
|
|
|
|
if doc.mode == Mode::Select {
|
|
|
|
if cx.editor.mode == Mode::Select {
|
|
|
|
Movement::Extend
|
|
|
|
Movement::Extend
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Movement::Move
|
|
|
|
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)) {
|
|
|
|
if let Some(pos) = find_first_non_whitespace_char(text.line(line)) {
|
|
|
|
let pos = pos + text.line_to_char(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 {
|
|
|
|
} else {
|
|
|
|
range
|
|
|
|
range
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -952,7 +952,7 @@ where
|
|
|
|
let motion = move |editor: &mut Editor| {
|
|
|
|
let motion = move |editor: &mut Editor| {
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let behavior = if doc.mode == Mode::Select {
|
|
|
|
let behavior = if editor.mode == Mode::Select {
|
|
|
|
Movement::Extend
|
|
|
|
Movement::Extend
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Movement::Move
|
|
|
|
Movement::Move
|
|
|
@ -985,7 +985,7 @@ fn goto_file_start(cx: &mut Context) {
|
|
|
|
let selection = doc
|
|
|
|
let selection = doc
|
|
|
|
.selection(view.id)
|
|
|
|
.selection(view.id)
|
|
|
|
.clone()
|
|
|
|
.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);
|
|
|
|
push_jump(view, doc);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -998,7 +998,7 @@ fn goto_file_end(cx: &mut Context) {
|
|
|
|
let selection = doc
|
|
|
|
let selection = doc
|
|
|
|
.selection(view.id)
|
|
|
|
.selection(view.id)
|
|
|
|
.clone()
|
|
|
|
.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);
|
|
|
|
push_jump(view, doc);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1375,7 +1375,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
|
|
|
|
if line != cursor.row {
|
|
|
|
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 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
|
|
|
|
range.anchor
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
head
|
|
|
|
head
|
|
|
@ -2098,7 +2098,7 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
|
|
|
|
exit_select_mode(cx);
|
|
|
|
exit_select_mode(cx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Operation::Change => {
|
|
|
|
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);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn enter_insert_mode(doc: &mut Document) {
|
|
|
|
fn enter_insert_mode(cx: &mut Context) {
|
|
|
|
doc.mode = Mode::Insert;
|
|
|
|
cx.editor.mode = Mode::Insert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// inserts at the start of each selection
|
|
|
|
// inserts at the start of each selection
|
|
|
|
fn insert_mode(cx: &mut Context) {
|
|
|
|
fn insert_mode(cx: &mut Context) {
|
|
|
|
|
|
|
|
enter_insert_mode(cx);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log::trace!(
|
|
|
|
log::trace!(
|
|
|
|
"entering insert mode with sel: {:?}, text: {:?}",
|
|
|
|
"entering insert mode with sel: {:?}, text: {:?}",
|
|
|
@ -2192,8 +2192,8 @@ fn insert_mode(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
// inserts at the end of each selection
|
|
|
|
// inserts at the end of each selection
|
|
|
|
fn append_mode(cx: &mut Context) {
|
|
|
|
fn append_mode(cx: &mut Context) {
|
|
|
|
|
|
|
|
enter_insert_mode(cx);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
|
|
|
|
doc.restore_cursor = true;
|
|
|
|
doc.restore_cursor = true;
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
|
|
|
|
|
|
|
@ -2421,9 +2421,9 @@ impl ui::menu::Item for MappableCommand {
|
|
|
|
pub fn command_palette(cx: &mut Context) {
|
|
|
|
pub fn command_palette(cx: &mut Context) {
|
|
|
|
cx.callback = Some(Box::new(
|
|
|
|
cx.callback = Some(Box::new(
|
|
|
|
move |compositor: &mut Compositor, cx: &mut compositor::Context| {
|
|
|
|
move |compositor: &mut Compositor, cx: &mut compositor::Context| {
|
|
|
|
let doc = doc_mut!(cx.editor);
|
|
|
|
let keymap = compositor.find::<ui::EditorView>().unwrap().keymaps.map()
|
|
|
|
let keymap =
|
|
|
|
[&cx.editor.mode]
|
|
|
|
compositor.find::<ui::EditorView>().unwrap().keymaps.map()[&doc.mode].reverse_map();
|
|
|
|
.reverse_map();
|
|
|
|
|
|
|
|
|
|
|
|
let mut commands: Vec<MappableCommand> = MappableCommand::STATIC_COMMAND_LIST.into();
|
|
|
|
let mut commands: Vec<MappableCommand> = MappableCommand::STATIC_COMMAND_LIST.into();
|
|
|
|
commands.extend(typed::TYPABLE_COMMAND_LIST.iter().map(|cmd| {
|
|
|
|
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
|
|
|
|
// I inserts at the first nonwhitespace character of each line with a selection
|
|
|
|
fn prepend_to_line(cx: &mut Context) {
|
|
|
|
fn prepend_to_line(cx: &mut Context) {
|
|
|
|
goto_first_nonwhitespace(cx);
|
|
|
|
goto_first_nonwhitespace(cx);
|
|
|
|
let doc = doc_mut!(cx.editor);
|
|
|
|
enter_insert_mode(cx);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// A inserts at the end of each line with a selection
|
|
|
|
// A inserts at the end of each line with a selection
|
|
|
|
fn append_to_line(cx: &mut Context) {
|
|
|
|
fn append_to_line(cx: &mut Context) {
|
|
|
|
|
|
|
|
enter_insert_mode(cx);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let selection = doc.selection(view.id).clone().transform(|range| {
|
|
|
|
let selection = doc.selection(view.id).clone().transform(|range| {
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
@ -2527,8 +2526,8 @@ pub enum Open {
|
|
|
|
|
|
|
|
|
|
|
|
fn open(cx: &mut Context, open: Open) {
|
|
|
|
fn open(cx: &mut Context, open: Open) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
|
|
|
|
enter_insert_mode(cx);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
enter_insert_mode(doc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let contents = doc.text();
|
|
|
|
let contents = doc.text();
|
|
|
@ -2606,13 +2605,12 @@ fn open_above(cx: &mut Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn normal_mode(cx: &mut Context) {
|
|
|
|
fn normal_mode(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
if cx.editor.mode == Mode::Normal {
|
|
|
|
|
|
|
|
|
|
|
|
if doc.mode == Mode::Normal {
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
doc.mode = Mode::Normal;
|
|
|
|
cx.editor.mode = Mode::Normal;
|
|
|
|
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
try_restore_indent(doc, view.id);
|
|
|
|
try_restore_indent(doc, view.id);
|
|
|
|
|
|
|
|
|
|
|
@ -2690,7 +2688,7 @@ fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
|
|
|
|
let selection = doc
|
|
|
|
let selection = doc
|
|
|
|
.selection(view.id)
|
|
|
|
.selection(view.id)
|
|
|
|
.clone()
|
|
|
|
.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);
|
|
|
|
push_jump(view, doc);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
@ -2710,7 +2708,7 @@ fn goto_last_line(cx: &mut Context) {
|
|
|
|
let selection = doc
|
|
|
|
let selection = doc
|
|
|
|
.selection(view.id)
|
|
|
|
.selection(view.id)
|
|
|
|
.clone()
|
|
|
|
.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);
|
|
|
|
push_jump(view, doc);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
@ -2733,7 +2731,7 @@ fn goto_last_modification(cx: &mut Context) {
|
|
|
|
let selection = doc
|
|
|
|
let selection = doc
|
|
|
|
.selection(view.id)
|
|
|
|
.selection(view.id)
|
|
|
|
.clone()
|
|
|
|
.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);
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -2770,13 +2768,12 @@ fn select_mode(cx: &mut Context) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
doc.set_selection(view.id, selection);
|
|
|
|
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) {
|
|
|
|
fn exit_select_mode(cx: &mut Context) {
|
|
|
|
let doc = doc_mut!(cx.editor);
|
|
|
|
if cx.editor.mode == Mode::Select {
|
|
|
|
if doc.mode == Mode::Select {
|
|
|
|
cx.editor.mode = Mode::Normal;
|
|
|
|
doc.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) {
|
|
|
|
pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
|
|
|
|
let count = cx.count();
|
|
|
|
let count = cx.count();
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let paste = match cx.editor.mode {
|
|
|
|
let paste = match doc.mode {
|
|
|
|
|
|
|
|
Mode::Insert | Mode::Select => Paste::Cursor,
|
|
|
|
Mode::Insert | Mode::Select => Paste::Cursor,
|
|
|
|
Mode::Normal => Paste::Before,
|
|
|
|
Mode::Normal => Paste::Before,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
paste_impl(&[contents], doc, view, paste, count);
|
|
|
|
paste_impl(&[contents], doc, view, paste, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -3838,8 +3835,7 @@ pub fn completion(cx: &mut Context) {
|
|
|
|
cx.callback(
|
|
|
|
cx.callback(
|
|
|
|
future,
|
|
|
|
future,
|
|
|
|
move |editor, compositor, response: Option<lsp::CompletionResponse>| {
|
|
|
|
move |editor, compositor, response: Option<lsp::CompletionResponse>| {
|
|
|
|
let doc = doc!(editor);
|
|
|
|
if editor.mode != Mode::Insert {
|
|
|
|
if doc.mode() != Mode::Insert {
|
|
|
|
|
|
|
|
// we're not in insert mode anymore
|
|
|
|
// we're not in insert mode anymore
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -4046,7 +4042,7 @@ fn match_brackets(cx: &mut Context) {
|
|
|
|
if let Some(pos) =
|
|
|
|
if let Some(pos) =
|
|
|
|
match_brackets::find_matching_bracket_fuzzy(syntax, doc.text(), range.cursor(text))
|
|
|
|
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 {
|
|
|
|
} else {
|
|
|
|
range
|
|
|
|
range
|
|
|
|
}
|
|
|
|
}
|
|
|
|