How to use the text-buffer.Point.fromObject function in text-buffer

To help you get started, we’ve selected a few text-buffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atom / atom / src / text-mate-language-mode.js View on Github external
scopeDescriptorForPosition(position) {
    let scopes;
    const { row, column } = this.buffer.clipPosition(
      Point.fromObject(position)
    );

    const iterator = this.tokenizedLineForRow(row).getTokenIterator();
    while (iterator.next()) {
      if (iterator.getBufferEnd() > column) {
        scopes = iterator.getScopes();
        break;
      }
    }

    // rebuild scope of last token if we iterated off the end
    if (!scopes) {
      scopes = iterator.getScopes();
      scopes.push(...iterator.getScopeEnds().reverse());
    }
github manaflair / mylittledom / sources / core / misc / TextFormatter.js View on Github external
moveDown(position, { copy = false, amount = 1 } = {}) {

        if (this.lineInfo.length === 0)
            return new Point();

        position = Point.fromObject(position, copy);

        // if jumping would bring us below the very last line, we just go to the end of this line
        if (position.row + amount >= this.lineInfo.length) {
            position.row = this.lineInfo.length - 1;
            position.column = this.lineInfo[position.row].outputLineLength;

        } else {
            position.row += amount;

            // if we land on the left edge, short-circuit the rest of the procedure
            if (position.column === 0) {
                return position;

            // if we land on the right edge or beyond, we can short-circuit the rest of the procedure too
            } else if (position.column >= this.lineInfo[position.row].outputLineLength) {
                position.column = this.lineInfo[position.row].outputLineLength;
github manaflair / mylittledom / sources / core / misc / TextFormatter.js View on Github external
moveLeft(position, { copy = false } = {}) {

        if (this.lineInfo.length === 0)
            return new Point();

        position = Point.fromObject(position, copy);

        let tokenLocator = this.tokenLocatorForPosition(position);

        if (!tokenLocator)
            return null;

        let [ row, tokenIndex, line, token ] = tokenLocator;

        // if we're inside the token, or on its right edge
        if (position.column > token.outputOffset) {

            // if we're a static token, we can just move inside the token
            if (token.type === STATIC_TOKEN) {
                position.column -= 1;

            // otherwise, we need to teleport to the beginning of the token
github manaflair / mylittledom / sources / core / misc / TextFormatter.js View on Github external
moveUp(position, { copy = false, amount = 1 } = {}) {

        if (this.lineInfo.length === 0)
            return new Point();

        position = Point.fromObject(position, copy);

        // if jumping would bring us above the very first line, we just go to the beginning of this line
        if (position.row - amount < 0) {
            position.row = 0;
            position.column = 0;

        } else {
            position.row -= amount;

            // if we land on the left edge, short-circuit the rest of the procedure
            if (position.column === 0) {
                return position;

            // if we land on the right edge or beyond, we can short-circuit the rest of the procedure too
            } else if (position.column >= this.lineInfo[position.row].outputLineLength) {
                position.column = this.lineInfo[position.row].outputLineLength;
github manaflair / mylittledom / sources / core / misc / TextFormatter.js View on Github external
moveTo(position, { copy = false } = {}) {

        if (this.lineInfo.length === 0)
            return new Point();

        position = Point.fromObject(position, copy);

        position.row = Math.max(0, Math.min(position.row, this.lineInfo.length - 1));
        position.column = Math.max(0, Math.min(position.column, this.lineInfo[position.row].outputLineLength));

        if (position.column === 0 || position.column === this.lineInfo[position.row].outputLineLength)
            return position;

        let tokenLocator = this.tokenLocatorForPosition(position);
        let [ row, tokenIndex, line, token ] = tokenLocator;

        if (token.type === DYNAMIC_TOKEN) {

            // if we're closer to the right side, we jump to it
            if (position.column >= token.outputOffset + token.outputLength / 2) {
                position.column = token.outputOffset + token.outputLength;
github atom / atom / src / cursor.js View on Github external
getEndOfCurrentWordBufferPosition(options = {}) {
    const allowNext = options.allowNext !== false;
    const position = this.getBufferPosition();

    const scanRange = allowNext
      ? new Range(position, new Point(position.row + 2, 0))
      : new Range(position, new Point(position.row, Infinity));

    const ranges = this.editor.buffer.findAllInRangeSync(
      options.wordRegex || this.wordRegExp(options),
      scanRange
    );

    for (let range of ranges) {
      if (position.isLessThan(range.start) && !allowNext) break;
      if (position.isLessThan(range.end)) return Point.fromObject(range.end);
    }

    return allowNext ? this.editor.getEofBufferPosition() : position;
  }
github atom / atom / src / cursor.js View on Github external
currentBufferPosition,
      this.editor.getEofBufferPosition()
    );

    const range = this.editor.buffer.findInRangeSync(
      options.wordRegex || this.wordRegExp(),
      scanRange
    );

    if (range) {
      if (range.start.row > currentBufferPosition.row) {
        return Point(range.start.row, 0);
      } else if (currentBufferPosition.isLessThan(range.start)) {
        return Point.fromObject(range.start);
      } else {
        return Point.fromObject(range.end);
      }
    } else {
      return currentBufferPosition;
    }
  }
github manaflair / mylittledom / sources / core / misc / TextFormatter.js View on Github external
tokenLocatorForPosition(position) {

        position = Point.fromObject(position);

        if (this.lineInfo.length === 0)
            return null;

        let row = Math.max(0, Math.min(position.row, this.lineInfo.length - 1));

        let line = this.lineInfo[row];
        let tokens = line.tokens;

        let col = Math.max(0, Math.min(position.column, line.outputLineLength));

        let l = 0;
        let r = tokens.length - 1;

        while (l <= r) {
github atom / atom / src / selection.js View on Github external
selectToScreenPosition(position, options) {
    position = Point.fromObject(position);

    this.modifySelection(() => {
      if (this.initialScreenRange) {
        if (position.isLessThan(this.initialScreenRange.start)) {
          this.marker.setScreenRange([position, this.initialScreenRange.end], {
            reversed: true
          });
        } else {
          this.marker.setScreenRange(
            [this.initialScreenRange.start, position],
            { reversed: false }
          );
        }
      } else {
        this.cursor.setScreenPosition(position, options);
      }

text-buffer

A container for large mutable strings with annotated regions

MIT
Latest version published 5 years ago

Package Health Score

47 / 100
Full package analysis

Similar packages