mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-05 21:37:55 +00:00
fix issue with optional branches having wrong flag insert positions
This commit is contained in:
parent
e2b354aae1
commit
c5ce6fb6c0
3 changed files with 28 additions and 6 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use ordermap::OrderMap;
|
||||
|
||||
use crate::{command::Command, token::Token};
|
||||
|
|
@ -27,10 +29,20 @@ impl TreeBranch {
|
|||
if matches!(token, Token::Parameter(ref param) if param.is_optional())
|
||||
&& index < command.tokens.len() - 1
|
||||
{
|
||||
current_branch.register_command(Command {
|
||||
tokens: command.tokens[index + 1..].to_vec(),
|
||||
..command.clone()
|
||||
});
|
||||
let mut new_command = command.clone();
|
||||
new_command.tokens = command.tokens[index + 1..].to_vec();
|
||||
new_command.original = command
|
||||
.original
|
||||
.clone()
|
||||
.or_else(|| Some(Arc::new(command.clone())));
|
||||
|
||||
// if the optional parameter we're skipping is *before* the flag insertion point,
|
||||
// we need to shift the index left by 1 to account for the removed token
|
||||
if new_command.parse_flags_before > index {
|
||||
new_command.parse_flags_before -= 1;
|
||||
}
|
||||
|
||||
current_branch.register_command(new_command);
|
||||
}
|
||||
// recursively get or create a sub-branch for each token
|
||||
current_branch = current_branch
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue