-
Notifications
You must be signed in to change notification settings - Fork 159
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
autocomplete: assume selection when there's only one candidate #277
Open
adtac
wants to merge
5
commits into
kamiyaa:main
Choose a base branch
from
adtac:autocomplete_improv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
613cbd1
textfield: allow closing with ctrl+c
adtac 002bc71
autocomplete: assume selection when there's only one candidate
adtac c98fe66
autocomplete: cycle back to first candidate
adtac 876c5a4
impl_from_str.rs: remove stray print
adtac b952351
docs/image_previews.md: fix typo in kitty guide
adtac 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 |
---|---|---|
|
@@ -248,7 +248,6 @@ impl std::str::FromStr for Command { | |
} else if command == CMD_DELETE_FILES { | ||
let (mut permanently, mut background) = (false, false); | ||
for arg in arg.split_whitespace() { | ||
eprintln!("arg: {:?}", arg); | ||
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. Oops, thanks for catching this! |
||
match arg { | ||
"--background=true" => background = true, | ||
"--background=false" => background = false, | ||
|
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 |
---|---|---|
|
@@ -215,6 +215,10 @@ impl<'a> TuiTextField<'a> { | |
let _ = terminal.hide_cursor(); | ||
return None; | ||
} | ||
Key::Ctrl('c') => { | ||
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. Good idea! |
||
let _ = terminal.hide_cursor(); | ||
return None; | ||
} | ||
Key::Char('\t') => autocomplete( | ||
&mut line_buffer, | ||
&mut completion_tracker, | ||
|
@@ -313,24 +317,27 @@ fn autocomplete( | |
if let Some(ref mut ct) = completion_tracker { | ||
ct.index = if reversed { | ||
ct.index.checked_sub(1).unwrap_or(ct.candidates.len() - 1) | ||
} else if ct.index + 1 < ct.candidates.len() { | ||
ct.index + 1 | ||
} else { | ||
ct.index | ||
(ct.index + 1) % ct.candidates.len() | ||
}; | ||
|
||
let candidate = &ct.candidates[ct.index]; | ||
completer.update(line_buffer, ct.pos, candidate.display()); | ||
completer.update(line_buffer, ct.pos, candidate.replacement()); | ||
} else if let Some((pos, mut candidates)) = get_candidates(completer, line_buffer) { | ||
if !candidates.is_empty() { | ||
if candidates.len() == 1 && candidates[0].replacement().ends_with('/') { | ||
completer.update(line_buffer, pos, &candidates[0].replacement()); | ||
return false; | ||
} | ||
|
||
candidates.sort_by(|x, y| { | ||
x.display() | ||
.partial_cmp(y.display()) | ||
.unwrap_or(std::cmp::Ordering::Less) | ||
}); | ||
|
||
let first_idx = if reversed { candidates.len() - 1 } else { 0 }; | ||
let first = candidates[first_idx].display().to_string(); | ||
let first = candidates[first_idx].replacement().to_string(); | ||
|
||
let mut ct = | ||
CompletionTracker::new(pos, candidates, String::from(line_buffer.as_str())); | ||
|
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.
Is there any reason for this change?
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.
Both references to this script above ("Configuring Hook Scripts" and "The Hook Scripts") don't have the .sh. I blindly copy-pasted those instructions, but with the kitty modifications, but it took me a couple minutes to identify the typo.