-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow a custom delay before a command popup shows up #2715
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a0ea172
Allow a custom delay before a command popup shows up (#1475)
lenstr b54b727
fix comment position
lenstr 6a4ad80
sort imports
lenstr b818b76
Update configuration.md
lenstr 53432ec
if autoinfo popup already opened, replace it without any delay
lenstr 28078dd
display sticky node without any delay
lenstr e5e2e03
rename schedule_autoinfo => handle_pending_node
lenstr 9de8974
Merge branch 'master' into feature/auto-info-delay
the-mikedavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ use crate::{ | |
commands, | ||
compositor::{Component, Context, Event, EventResult}, | ||
job, key, | ||
keymap::{KeymapResult, Keymaps}, | ||
keymap::{KeyTrieNode, KeymapResult, Keymaps}, | ||
ui::{Completion, ProgressSpinners}, | ||
}; | ||
|
||
|
@@ -20,6 +20,7 @@ use helix_view::{ | |
document::{Mode, SCRATCH_BUFFER_NAME}, | ||
editor::{CompleteAction, CursorShapeConfig}, | ||
graphics::{Color, CursorKind, Modifier, Rect, Style}, | ||
info::Delay, | ||
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind}, | ||
keyboard::{KeyCode, KeyModifiers}, | ||
Document, Editor, Theme, View, | ||
|
@@ -921,7 +922,11 @@ impl EditorView { | |
let mut last_mode = mode; | ||
self.pseudo_pending.extend(self.keymaps.pending()); | ||
let key_result = self.keymaps.get(mode, event); | ||
cxt.editor.autoinfo = self.keymaps.sticky().map(|node| node.infobox()); | ||
let is_pending = matches!(key_result, KeymapResult::Pending(_)); | ||
if !is_pending { | ||
// if there is no pending popup, reset autoinfo immediately | ||
cxt.editor.autoinfo = self.keymaps.sticky().map(|node| node.infobox()); | ||
} | ||
|
||
let mut execute_command = |command: &commands::MappableCommand| { | ||
command.execute(cxt); | ||
|
@@ -959,7 +964,7 @@ impl EditorView { | |
KeymapResult::Matched(command) => { | ||
execute_command(command); | ||
} | ||
KeymapResult::Pending(node) => cxt.editor.autoinfo = Some(node.infobox()), | ||
KeymapResult::Pending(node) => self.handle_pending_node(cxt, node), | ||
KeymapResult::MatchedSequence(commands) => { | ||
for command in commands { | ||
execute_command(command); | ||
|
@@ -1057,6 +1062,50 @@ impl EditorView { | |
} | ||
} | ||
|
||
fn handle_pending_node(&mut self, cxt: &mut commands::Context, node: &KeyTrieNode) { | ||
let infobox = node.infobox(); | ||
|
||
let auto_info_delay = cxt.editor.config().auto_info_delay; | ||
if auto_info_delay.is_zero() || node.is_sticky { | ||
cxt.editor.autoinfo = Some(infobox); | ||
return; | ||
} | ||
|
||
// if autoinfo popup already opened | ||
if cxt | ||
.editor | ||
.autoinfo | ||
.as_ref() | ||
.map(|info| !info.is_delayed()) | ||
.unwrap_or(false) | ||
{ | ||
// replace it without any delay | ||
cxt.editor.autoinfo = Some(infobox); | ||
return; | ||
} | ||
|
||
let (cancel_tx, cancel_rx) = tokio::sync::oneshot::channel::<()>(); | ||
|
||
let infobox_delayed = infobox.with_delay(Delay { cancel_tx }); | ||
cxt.editor.autoinfo = Some(infobox_delayed); | ||
|
||
let callback = async move { | ||
let call: job::Callback = tokio::select! { | ||
// delay timed out | ||
_ = tokio::time::sleep(auto_info_delay) => Box::new(move |editor, _compositor| { | ||
if let Some(autoinfo) = &mut editor.autoinfo { | ||
autoinfo.delay = None | ||
} | ||
}), | ||
// delay cancelled | ||
_ = cancel_rx => Box::new(move |_editor, _compositor| {}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah this is clever - this doesn't need to be triggered explicitly because it's marked as completed in the Drop implementation for Sender, eh? It's probably worth a comment here on how this triggers since it's kinda hidden in the implementation details |
||
}; | ||
Ok(call) | ||
}; | ||
|
||
cxt.jobs.callback(callback); | ||
} | ||
|
||
pub fn set_completion( | ||
&mut self, | ||
editor: &mut Editor, | ||
|
@@ -1461,7 +1510,9 @@ impl Component for EditorView { | |
|
||
if config.auto_info { | ||
if let Some(mut info) = cx.editor.autoinfo.take() { | ||
info.render(area, surface, cx); | ||
if !info.is_delayed() { | ||
info.render(area, surface, cx); | ||
} | ||
cx.editor.autoinfo = Some(info) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it would be too unreadable to have the
matches!
in theif
expression here. I don't feel strongly about it though and I think you did this for readability so it's up to you if you want to keep it as-is