Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Jan 13, 2023
1 parent 0f94105 commit cdf81c1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
1 change: 0 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4078,7 +4078,6 @@ pub fn completion(cx: &mut Context) {

// Delete the signature help popup if they intersect.
if ui.set_completion(
// compositor,
signature_help_area,
editor,
items,
Expand Down
66 changes: 36 additions & 30 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,9 @@ impl EditorView {
}
}

#[allow(clippy::too_many_arguments)]
pub fn set_completion(
&mut self,
// compositor: &mut crate::compositor::Compositor,
signature_help_area: Option<Rect>,
editor: &mut Editor,
items: Vec<helix_lsp::lsp::CompletionItem>,
Expand Down Expand Up @@ -1307,7 +1307,7 @@ impl Component for EditorView {
event: &Event,
context: &mut crate::compositor::Context,
) -> EventResult {
let mut cx = commands::Context {
let mut cxt = commands::Context {
editor: context.editor,
count: None,
register: None,
Expand All @@ -1318,13 +1318,13 @@ impl Component for EditorView {

match event {
Event::Paste(contents) => {
cx.count = cx.editor.count;
commands::paste_bracketed_value(&mut cx, contents.clone());
cx.editor.count = None;
cxt.count = cxt.editor.count;
commands::paste_bracketed_value(&mut cxt, contents.clone());
cxt.editor.count = None;

let config = cx.editor.config();
let mode = cx.editor.mode();
let (view, doc) = current!(cx.editor);
let config = cxt.editor.config();
let mode = cxt.editor.mode();
let (view, doc) = current!(cxt.editor);
view.ensure_cursor_in_view(doc, config.scrolloff);

// Store a history state if not in insert mode. Otherwise wait till we exit insert
Expand All @@ -1341,19 +1341,19 @@ impl Component for EditorView {
EventResult::Consumed(None)
}
Event::Key(mut key) => {
cx.editor.reset_idle_timer();
cxt.editor.reset_idle_timer();
canonicalize_key(&mut key);

// clear status
cx.editor.status_msg = None;
cxt.editor.status_msg = None;

let mode = cx.editor.mode();
let (view, _) = current!(cx.editor);
let mode = cxt.editor.mode();
let (view, _) = current!(cxt.editor);
let focus = view.id;

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 cx, key);
on_next_key(&mut cxt, key);
} else {
match mode {
Mode::Insert => {
Expand All @@ -1362,8 +1362,8 @@ impl Component for EditorView {
if let Some(completion) = &mut self.completion {
// use a fake context here
let mut cx = Context {
editor: cx.editor,
jobs: cx.jobs,
editor: cxt.editor,
jobs: cxt.jobs,
scroll: None,
};
let res = completion.handle_event(event, &mut cx);
Expand All @@ -1374,55 +1374,61 @@ impl Component for EditorView {
if callback.is_some() {
// assume close_fn
self.clear_completion(cx.editor);

// In case the popup was deleted beacuse of an intersection w/ the auto-complete menu.
commands::signature_help_impl(
&mut cxt,
commands::SignatureHelpInvoked::Automatic,
);
}
}
}

// if completion didn't take the event, we pass it onto commands
if !consumed {
if let Some(compl) = cx.editor.last_completion.take() {
if let Some(compl) = cxt.editor.last_completion.take() {
self.last_insert.1.push(InsertEvent::CompletionApply(compl));
}

self.insert_mode(&mut cx, key);
self.insert_mode(&mut cxt, key);

// record last_insert key
self.last_insert.1.push(InsertEvent::Key(key));

// lastly we recalculate completion
if let Some(completion) = &mut self.completion {
completion.update(&mut cx);
completion.update(&mut cxt);
if completion.is_empty() {
self.clear_completion(cx.editor);
self.clear_completion(cxt.editor);
}
}
}
}
mode => self.command_mode(mode, &mut cx, key),
mode => self.command_mode(mode, &mut cxt, key),
}
}

self.on_next_key = cx.on_next_key_callback.take();
self.on_next_key = cxt.on_next_key_callback.take();
match self.on_next_key {
Some(_) => self.pseudo_pending.push(key),
None => self.pseudo_pending.clear(),
}

// appease borrowck
let callback = cx.callback.take();
let callback = cxt.callback.take();

// if the command consumed the last view, skip the render.
// on the next loop cycle the Application will then terminate.
if cx.editor.should_close() {
if cxt.editor.should_close() {
return EventResult::Ignored(None);
}

// if the focused view still exists and wasn't closed
if cx.editor.tree.contains(focus) {
let config = cx.editor.config();
let mode = cx.editor.mode();
let view = view_mut!(cx.editor, focus);
let doc = doc_mut!(cx.editor, &view.doc);
if cxt.editor.tree.contains(focus) {
let config = cxt.editor.config();
let mode = cxt.editor.mode();
let view = view_mut!(cxt.editor, focus);
let doc = doc_mut!(cxt.editor, &view.doc);

view.ensure_cursor_in_view(doc, config.scrolloff);

Expand All @@ -1436,8 +1442,8 @@ impl Component for EditorView {
EventResult::Consumed(callback)
}

Event::Mouse(event) => self.handle_mouse_event(event, &mut cx),
Event::IdleTimeout => self.handle_idle_timeout(&mut cx),
Event::Mouse(event) => self.handle_mouse_event(event, &mut cxt),
Event::IdleTimeout => self.handle_idle_timeout(&mut cxt),
Event::FocusGained => EventResult::Ignored(None),
Event::FocusLost => {
if context.editor.config().auto_save {
Expand Down

0 comments on commit cdf81c1

Please sign in to comment.