private findHitSubPath(hits: ReadonlyArray<{ subIdx: number }>) {
   const infos = hits.map(index => {
     const { subIdx } = index;
     return { subIdx, subPath: this.component.activePath.getSubPath(subIdx) };
   });
   const lastSplitIndex = _.findLastIndex(infos, info => info.subPath.isSplit());
   return infos[lastSplitIndex < 0 ? infos.length - 1 : lastSplitIndex];
 }
Example #2
0
  playDisc(column: number, color: string): boolean {
    let rowOfCellToChange: number = _.findLastIndex(this.cells[column], (cell: string) => this.cellIsEmpty(cell));
    if (!this.rowIsValid(rowOfCellToChange)) return false;

    let discPlayed: Disc = new Disc(new Location(column, rowOfCellToChange), color);
    this.setCell(discPlayed);
    this.lastDiscPlayed = discPlayed;
    return true;
  }
Example #3
0
    @memoizeAccessor
    get children(): ASTNode[] {
        const separatorOpIndex = _.findLastIndex(this.tokens, isEndOfCommand);

        if (separatorOpIndex !== -1) {
            return [
                new List(this.tokens.slice(0, separatorOpIndex)),
                new ShellSyntaxNode(this.tokens[separatorOpIndex]),
                new AndOr(this.tokens.slice(separatorOpIndex + 1)),
            ];
        } else {
            return [
                new AndOr(this.tokens),
            ];
        }
    }
Example #4
0
    @memoizeAccessor
    get children(): ASTNode[] {
        const separatorOpIndex = _.findLastIndex(this.tokens, token => token instanceof Scanner.Semicolon);

        if (separatorOpIndex !== -1) {
            return [
                new List(this.tokens.slice(0, separatorOpIndex)),
                new ShellSyntaxNode(this.tokens[separatorOpIndex]),
                new AndOr(this.tokens.slice(separatorOpIndex + 1)),
            ];
        } else {
            return [
                new AndOr(this.tokens),
            ];
        }
    }
Example #5
0
    @memoizeAccessor
    get children(): ASTNode[] {
        const andOrTokenIndex = _.findLastIndex(this.tokens, token => token instanceof Scanner.And || token instanceof Scanner.Or);

        if (andOrTokenIndex !== -1) {
            return [
                new AndOr(this.tokens.slice(0, andOrTokenIndex)),
                new ShellSyntaxNode(this.tokens[andOrTokenIndex]),
                new Pipeline(this.tokens.slice(andOrTokenIndex + 1)),
            ];
        } else {
            return [
                new Pipeline(this.tokens),
            ];
        }
    }
Example #6
0
    @memoizeAccessor
    get children(): ASTNode[] {
        const pipeIndex = _.findLastIndex(this.tokens, token => token instanceof Scanner.Pipe);

        if (pipeIndex !== -1) {
            return [
                new PipeSequence(this.tokens.slice(0, pipeIndex)),
                new ShellSyntaxNode(this.tokens[pipeIndex]),
                new Command(this.tokens.slice(pipeIndex + 1)),
            ];
        } else {
            return [
                new Command(this.tokens),
            ];
        }
    }
Example #7
0
function _addToPosition(
    obj: MenuItemOptions,
    target: MenuItemOptions[],
    position: string,
    relativeId: string | null
): string | null {
    let retVal: string | null = null;
    if (position === "first") {
        target.unshift(obj);
    } else if (position === "last") {
        target.push(obj);
    } else if (
        position === "before" || position === "after" || position === "firstInSection" || position === "lastInSection"
    ) {
        let idx = _.findIndex(target, {id: relativeId});
        let idxSection: number;
        if (idx === -1) {
            // NOTE: original behaviour - if relativeId wasn't found
            // menu should be put to the end of the list
            console.warn("menu item with id: " + relativeId + " was not found, adding entry to the end of the list");
            retVal = ERR_NOT_FOUND;
            idx = target.length;
        }
        if (position === "firstInSection") {
            idxSection = _.findLastIndex(target, (o: MenuItemOptions, i: number) => {
                return i < idx && o.type === "separator";
            });
            idx = idxSection + 1;
        }
        if (position === "lastInSection") {
            idxSection = _.findIndex(target, (o: MenuItemOptions, i: number) => {
                return i >= idx && o.type === "separator";
            });
            idx = idxSection === -1 ? target.length : idxSection;
        }
        if (position === "after") {
            idx++;
        }
        target.splice(idx, 0, obj);
    } else {
        throw new Error("position not implemented in _addToPosition: " + position);
    }
    return retVal;
}
Example #8
0
 /**
  * Calculates the sub path indices that will be removed after unsplitting subIdx.
  * targetCs is the command state object containing the split segment in question.
  */
 private calculateDeletedSubIdxs(subIdx: number, targetCs: CommandState) {
   const splitSegId = targetCs.getSplitSegmentId();
   const psps = this.findSplitSegmentParentNode(splitSegId);
   const pssps = psps.getSplitSubPaths();
   const splitSubPathIdx1 = _.findIndex(pssps, sps => {
     return sps.getCommandStates().some(cs => cs.getSplitSegmentId() === splitSegId);
   });
   const splitSubPathIdx2 = _.findLastIndex(pssps, sps => {
     return sps.getCommandStates().some(cs => cs.getSplitSegmentId() === splitSegId);
   });
   const pssp1 = pssps[splitSubPathIdx1];
   const pssp2 = pssps[splitSubPathIdx2];
   const deletedSps = [...flattenSubPathStates([pssp1]), ...flattenSubPathStates([pssp2])];
   const spss = flattenSubPathStates(this.subPathStateMap);
   return deletedSps
     .slice(1)
     .map(sps => this.subPathOrdering[spss.indexOf(sps)])
     .sort((a, b) => b - a);
 }
      .success(function(ret) {
        $scope.revisions = ret.revisions;
        $scope.latestOAIdx = findLastIndex(ret.revisions, {isOpenAccess: true});

        const latestOARevision = $scope.revisions[$scope.latestOAIdx];
        // Cut description down to 150 chars, cf.
        // <http://moz.com/learn/seo/meta-description>
        // TODO move linebreak removal to backend?
        const metaData = [
          {
            name: 'description',
            content: latestOARevision.title + ' by ' + latestOARevision.authors.join(', ') + '.'
          },
          {name: 'author', content: latestOARevision.authors.join(', ')},
          {name: 'keywords', content: latestOARevision.tags.join(', ')}
        ];

        $scope.addDocumentMetaData(metaData);

        metaService.set({
          title: latestOARevision.title + ' ยท PaperHive',
          meta: metaData
        });
      })
Example #10
0
  get(index) {

    if (index === undefined) {
      index = this.index;
    }

    if (this.validateIndex(index)) {

      if (index !== -1 && this.eventType) {
        let _index = _.findLastIndex(this.events.slice(0, index + 1), { type: this.eventType });
        if (_index === -1) {
          return null;
        } else {
          index = _index;
        }
      }

      let events = this.events.slice(0, index + 1);
      this.index = index;
      return reborn(this.ActorClass, this.lastSnap, events).json;
    } else {
      return null;
    }
  }