Third try for Add Em Dash PR (#5564)

This commit is contained in:
Daniel Espino García 2021-07-26 10:28:29 +02:00 committed by GitHub
parent 53890c8d32
commit ca4840a3eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -263,6 +263,15 @@ export class ParsedCommand {
this.i++;
break;
}
case '—': {
// Em dash, introduced when two '-' are set in iOS. Will be considered as such.
this.state = ParseState.Flag;
this.i++;
this.incomplete = '';
this.incompleteStart = this.i;
flagEqualsUsed = false;
break;
}
default: {
// Positional parameter.
this.position++;
@ -1093,10 +1102,14 @@ export class AppCommandParser {
}
// There have been 0 to 2 dashes in the command prior to this call, adjust.
const prevCharIndex = parsed.incompleteStart - 1;
let prefix = '--';
for (let i = parsed.incompleteStart - 1; i > 0 && i >= parsed.incompleteStart - 2 && parsed.command[i] === '-'; i--) {
for (let i = prevCharIndex; i > 0 && i >= parsed.incompleteStart - 2 && parsed.command[i] === '-'; i--) {
prefix = prefix.substring(1);
}
if (prevCharIndex > 0 && parsed.command[prevCharIndex] === '—') {
prefix = '';
}
const applicable = parsed.form.fields.filter((field) => field.label && field.label.toLowerCase().startsWith(parsed.incomplete.toLowerCase()) && !parsed.values[field.name]);
if (applicable) {