Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix(gql): better handling of trailing val in list
Browse files Browse the repository at this point in the history
1.
files.access in [open, controlled]
move cursor into controlled:
files.access in [open, con|trolled]
select controlled from autosuggest:
files.access in [open, controlled
closing bracket gone
2.
files.access in [open, controlled]
move cursor into open:
files.access in [op|en, controlled]
select open from autosuggest:
files.access in [open
rest of list gone

- Closes #940
  • Loading branch information
Shane Wilson committed Jun 11, 2015
1 parent 19505be commit b2d93bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/scripts/components/gql/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ module ngApp.components.gql {

getComplexParts(s: string, n: number): IParts {
var parts = this.getParts(s.substring(0, n));

parts.needle = this.getNeedleFromList(s.substring(n));
console.log('here', parts);
return parts;
}

Expand Down Expand Up @@ -284,11 +282,14 @@ module ngApp.components.gql {
}

rhsRewriteList(right: string): string {
var rFirstBracket = right.indexOf(this.GqlTokens.RBRACKET);
var rFirstComma = right.indexOf(this.GqlTokens.COMMA);
var rFirstToken = rFirstComma < rFirstBracket ? rFirstComma : rFirstBracket;
rFirstToken = rFirstToken === -1 ? right.length : rFirstToken;
return right.substring(rFirstToken);
var bracket = right.indexOf(this.GqlTokens.RBRACKET);
var comma = right.indexOf(this.GqlTokens.COMMA);
// is there a comma before the ] - if yes use that
var pos = comma >= 0 && comma < bracket ? comma : bracket;
// other wise is there a ] at all - then use that
// else end of line
pos = pos === -1 ? right.length : pos;
return right.substring(pos);
}
}

Expand Down Expand Up @@ -472,7 +473,7 @@ module ngApp.components.gql {

var left = $scope.left;
var right = $scope.right;
console.log('her?E?RE');

if ([Mode.Field, Mode.Op, Mode.Unquoted].indexOf($scope.mode) !== -1) {
var newLeft = GqlService.lhsRewrite(left, needleLength);
var newRight = GqlService.rhsRewrite(right);
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/components/gql/tests/gql.service.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ describe("GQL Parser", function() {
it("[OICR-928] return empty string when just unquoted value", inject(function (GqlService) {
expect(GqlService.rhsRewriteList("otected")).to.eq("");
}));
it("[OICR-940] not remove trailing list items", inject(function (GqlService) {
expect(GqlService.rhsRewriteList("trolled]")).to.eq("]");
expect(GqlService.rhsRewriteList("en, controlled]")).to.eq(", controlled]");
}));
});
});
});

0 comments on commit b2d93bc

Please sign in to comment.