switch redundant current! usage to doc! (#1416)

pull/1409/head^2
Kirawi 3 years ago committed by GitHub
parent aaa42e1a69
commit 93a948d889
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1545,7 +1545,7 @@ fn searcher(cx: &mut Context, direction: Direction) {
let reg = cx.register.unwrap_or('/');
let scrolloff = cx.editor.config.scrolloff;
let (_, doc) = current!(cx.editor);
let doc = doc!(cx.editor);
// TODO: could probably share with select_on_matches?
@ -2046,7 +2046,7 @@ pub mod cmd {
fn write_impl(cx: &mut compositor::Context, path: Option<&Cow<str>>) -> anyhow::Result<()> {
let jobs = &mut cx.jobs;
let (_, doc) = current!(cx.editor);
let doc = doc_mut!(cx.editor);
if let Some(ref path) = path {
doc.set_path(Some(path.as_ref().as_ref()))
@ -2099,8 +2099,7 @@ pub mod cmd {
_args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
let (_, doc) = current!(cx.editor);
let doc = doc!(cx.editor);
if let Some(format) = doc.format() {
let callback =
make_format_callback(doc.id(), doc.version(), Modified::LeaveModified, format);
@ -2409,7 +2408,7 @@ pub mod cmd {
args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
let (_, doc) = current!(cx.editor);
let doc = doc!(cx.editor);
let default_sep = Cow::Borrowed(doc.line_ending.as_str());
let separator = args.first().unwrap_or(&default_sep);
yank_joined_to_clipboard_impl(cx.editor, separator, ClipboardType::Clipboard)
@ -2428,7 +2427,7 @@ pub mod cmd {
args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
let (_, doc) = current!(cx.editor);
let doc = doc!(cx.editor);
let default_sep = Cow::Borrowed(doc.line_ending.as_str());
let separator = args.first().unwrap_or(&default_sep);
yank_joined_to_clipboard_impl(cx.editor, separator, ClipboardType::Selection)
@ -2555,7 +2554,7 @@ pub mod cmd {
args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
let (_, doc) = current!(cx.editor);
let doc = doc_mut!(cx.editor);
if let Some(label) = args.first() {
doc.set_encoding(label)
} else {
@ -3247,7 +3246,7 @@ fn symbol_picker(cx: &mut Context) {
nested_to_flat(list, file, child);
}
}
let (_, doc) = current!(cx.editor);
let doc = doc!(cx.editor);
let language_server = match doc.language_server() {
Some(language_server) => language_server,
@ -3268,7 +3267,7 @@ fn symbol_picker(cx: &mut Context) {
let symbols = match symbols {
lsp::DocumentSymbolResponse::Flat(symbols) => symbols,
lsp::DocumentSymbolResponse::Nested(symbols) => {
let (_view, doc) = current!(editor);
let doc = doc!(editor);
let mut flat_symbols = Vec::new();
for symbol in symbols {
nested_to_flat(&mut flat_symbols, &doc.identifier(), symbol)
@ -3310,17 +3309,15 @@ fn symbol_picker(cx: &mut Context) {
}
fn workspace_symbol_picker(cx: &mut Context) {
let (_, doc) = current!(cx.editor);
let doc = doc!(cx.editor);
let current_path = doc.path().cloned();
let language_server = match doc.language_server() {
Some(language_server) => language_server,
None => return,
};
let offset_encoding = language_server.offset_encoding();
let future = language_server.workspace_symbols("".to_string());
let current_path = doc_mut!(cx.editor).path().cloned();
cx.callback(
future,
move |_editor: &mut Editor,
@ -3430,8 +3427,7 @@ pub fn code_action(cx: &mut Context) {
}
pub fn execute_lsp_command(editor: &mut Editor, cmd: lsp::Command) {
let (_view, doc) = current!(editor);
let doc = doc!(editor);
let language_server = match doc.language_server() {
Some(language_server) => language_server,
None => return,
@ -4185,27 +4181,21 @@ fn goto_pos(editor: &mut Editor, pos: usize) {
}
fn goto_first_diag(cx: &mut Context) {
let editor = &mut cx.editor;
let (_, doc) = current!(editor);
let doc = doc!(cx.editor);
let pos = match doc.diagnostics().first() {
Some(diag) => diag.range.start,
None => return,
};
goto_pos(editor, pos);
goto_pos(cx.editor, pos);
}
fn goto_last_diag(cx: &mut Context) {
let editor = &mut cx.editor;
let (_, doc) = current!(editor);
let doc = doc!(cx.editor);
let pos = match doc.diagnostics().last() {
Some(diag) => diag.range.start,
None => return,
};
goto_pos(editor, pos);
goto_pos(cx.editor, pos);
}
fn goto_next_diag(cx: &mut Context) {
@ -5270,7 +5260,7 @@ pub fn completion(cx: &mut Context) {
move |editor: &mut Editor,
compositor: &mut Compositor,
response: Option<lsp::CompletionResponse>| {
let (_, doc) = current!(editor);
let doc = doc!(editor);
if doc.mode() != Mode::Insert {
// we're not in insert mode anymore
return;

@ -781,8 +781,9 @@ impl EditorView {
pub fn clear_completion(&mut self, editor: &mut Editor) {
self.completion = None;
// Clear any savepoints
let (_, doc) = current!(editor);
let doc = doc_mut!(editor);
doc.savepoint = None;
editor.clear_idle_timer(); // don't retrigger
}
@ -940,14 +941,18 @@ impl EditorView {
}
impl Component for EditorView {
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
let mut cxt = commands::Context {
editor: cx.editor,
fn handle_event(
&mut self,
event: Event,
context: &mut crate::compositor::Context,
) -> EventResult {
let mut cx = commands::Context {
editor: context.editor,
count: None,
register: None,
callback: None,
on_next_key_callback: None,
jobs: cx.jobs,
jobs: context.jobs,
};
match event {
@ -957,18 +962,19 @@ impl Component for EditorView {
EventResult::Consumed(None)
}
Event::Key(key) => {
cxt.editor.reset_idle_timer();
cx.editor.reset_idle_timer();
let mut key = KeyEvent::from(key);
canonicalize_key(&mut key);
// clear status
cxt.editor.status_msg = None;
cx.editor.status_msg = None;
let (_, doc) = current!(cxt.editor);
let doc = doc!(cx.editor);
let mode = doc.mode();
if let Some(on_next_key) = self.on_next_key.take() {
// if there's a command waiting input, do that first
on_next_key(&mut cxt, key);
on_next_key(&mut cx, key);
} else {
match mode {
Mode::Insert => {
@ -980,8 +986,8 @@ impl Component for EditorView {
if let Some(completion) = &mut self.completion {
// use a fake context here
let mut cx = Context {
editor: cxt.editor,
jobs: cxt.jobs,
editor: cx.editor,
jobs: cx.jobs,
scroll: None,
};
let res = completion.handle_event(event, &mut cx);
@ -991,40 +997,40 @@ impl Component for EditorView {
if callback.is_some() {
// assume close_fn
self.clear_completion(cxt.editor);
self.clear_completion(cx.editor);
}
}
}
// if completion didn't take the event, we pass it onto commands
if !consumed {
self.insert_mode(&mut cxt, key);
self.insert_mode(&mut cx, key);
// lastly we recalculate completion
if let Some(completion) = &mut self.completion {
completion.update(&mut cxt);
completion.update(&mut cx);
if completion.is_empty() {
self.clear_completion(cxt.editor);
self.clear_completion(cx.editor);
}
}
}
}
mode => self.command_mode(mode, &mut cxt, key),
mode => self.command_mode(mode, &mut cx, key),
}
}
self.on_next_key = cxt.on_next_key_callback.take();
self.on_next_key = cx.on_next_key_callback.take();
// appease borrowck
let callback = cxt.callback.take();
let callback = cx.callback.take();
// if the command consumed the last view, skip the render.
// on the next loop cycle the Application will then terminate.
if cxt.editor.should_close() {
if cx.editor.should_close() {
return EventResult::Ignored;
}
let (view, doc) = current!(cxt.editor);
view.ensure_cursor_in_view(doc, cxt.editor.config.scrolloff);
let (view, doc) = current!(cx.editor);
view.ensure_cursor_in_view(doc, cx.editor.config.scrolloff);
// mode transitions
match (mode, doc.mode()) {
@ -1053,7 +1059,7 @@ impl Component for EditorView {
EventResult::Consumed(callback)
}
Event::Mouse(event) => self.handle_mouse_event(event, &mut cxt),
Event::Mouse(event) => self.handle_mouse_event(event, &mut cx),
}
}

Loading…
Cancel
Save