-
Notifications
You must be signed in to change notification settings - Fork 57
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
Added username completion in channels #93
Added username completion in channels #93
Conversation
src/widget/input/completion.rs
Outdated
pub fn process(&mut self, input: &str, users: Vec<User>) { | ||
self.with_users(users); | ||
let maybe_command = input.starts_with('/'); | ||
let Some((head, rest)) = Self::valid_completion_input(input, maybe_command) else { | ||
self.reset(); | ||
return; |
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.
Let's add some better separation between processing for a command vs user completion. If input starts with a slash, we can branch into a process_command
function, otherwise process_user
.
Then we only need to add the users info inside process_user
compared to us always adding it here
Awesome, thanks for the feedback, I'll have a look at these today |
d8a421e
to
c868590
Compare
b13f97e
to
c99c01d
Compare
@Tangdongle It's looking good! I've pushed a few commits to get it over the finish line, let me know what you think.
|
0c99d01
to
1820448
Compare
@tarkah Legendary! Thanks for cleaning that up, hope it wasn't too much of a hassle! Yeah, I see what you've done here, looks much cleaner. I've taken it for a spin and it looks good to me! |
Awesome! Not at all, you put it in a really nice spot so it all came together nicely 👌 I'm going to hold off on merging until @casperstorm can test. I'm not sure I love |
src/widget/input.rs
Outdated
@@ -51,6 +52,7 @@ pub enum Event { | |||
pub struct Input<'a, Message> { | |||
id: Id, | |||
buffer: Buffer, | |||
users: Vec<User>, |
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.
Could this borrow a slice to avoid the clone
in view
?
users: Vec<User>, | |
users: &'a [User], |
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.
Unfortunately not. We're currently depending on the IRC crate for managing the user list per channel and it doesn't expose a way to get a reference to this data.
Ideally we manage channels and users ourselves so we could make this optimization. It'd definitely benefit us in the long run as we have better control over our data.
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.
A middle ground solution would be to extract channel and user lists after receiving each batch of IRC messages which can be stored in Connection
. This will ensure they're in sync but give us this level of control.
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.
Yup, just took a look at the irc
crate. A bit unfortunate it relies heavily on interior mutation :/
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've created a tracking issue for this here:
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 think we need to rethink the UX slightly, it not that irc idiomatic. The core functionality however is spot on. Because of this, the most common practise is to be able to trigger at all times when pressing Tab (without any prefix). This also means that we save a few clicks. Currently in this PR if i want to highlight
My suggestion would be a system where when pressing Tab we try to match a nick, and pressing Tab again cycles, without displaying our completion list. Take the following scenario as an example: We have a irc channel with three users:
|
Ok, I got a little something going on, lemme know what you think. Seems to work well enough from my tests (i.e. "it works on my machine"). did notice that if you have text in the input buffer and then open a new channel, the text carries across to the newly opened channels buffer. Doesn't seem related to the change, so I'll raise a bug for it. |
@Tangdongle I ended up pushing a larger refactor since the previous implementation didn't really jive with the new requirements and we were introducing a lot of impossible states. The new implementation separates user / command completion logic and should be much simpler to follow. We also can get user completions while showing the command popup for the selected command! Great for /msg and the like :D Thanks so much for tackling this, it was a huge help! |
5b58711
to
d2ca1c5
Compare
Removed some heap allocations. Split up how we process command vs user completions
d2ca1c5
to
3a54355
Compare
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.
This is SUCH a great feature.
Thanks for the work @Tangdongle and @tarkah.
src/widget/input/completion.rs
Outdated
let nickname = user.nickname(); | ||
nickname |
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.
A tiny thing could be that we lower-cased both rest
and nickname
so we can tab-complete from t
to Tarkah
.
Not blocking but just an idea.
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.
Good idea! 09c9e78
} | ||
} | ||
|
||
static COMMAND_LIST: Lazy<Vec<Command>> = Lazy::new(|| { |
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 like this 👍🏻
Perhaps some macro magic in the future.
Co-authored-by: Casper Rogild Storm <casper+github@rogildstorm.com>
This adds nickname auto-completion for channels.
When we instantiate the text_input from the Channel's view with a list of users in that channel.
From there, we need to differentiate between a /command and a user completion, so we add a CompletionType to each Completion Entry. /commands only auto-complete from the start of the input text, whereas name completion can occur from any word.
Finally, we replace the current word being completed without sending, so the user can continue to type.