How to use the text-buffer.Range 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-editor-component.js View on Github external
const {target, button, ctrlKey, shiftKey, metaKey} = event

    // Only handle mousedown events for left mouse button
    if (button !== 0) return

    const clickedScreenRow = this.screenPositionForMouseEvent(event).row
    const startBufferRow = model.bufferPositionForScreenPosition([clickedScreenRow, 0]).row

    if (target && target.matches('.foldable .icon-right')) {
      model.toggleFoldAtBufferRow(startBufferRow)
      return
    }

    const addOrRemoveSelection = metaKey || (ctrlKey && this.getPlatform() !== 'darwin')
    const endBufferRow = model.bufferPositionForScreenPosition([clickedScreenRow, Infinity]).row
    const clickedLineBufferRange = Range(Point(startBufferRow, 0), Point(endBufferRow + 1, 0))

    let initialBufferRange
    if (shiftKey) {
      const lastSelection = model.getLastSelection()
      initialBufferRange = lastSelection.getBufferRange()
      lastSelection.setBufferRange(initialBufferRange.union(clickedLineBufferRange), {
        reversed: clickedScreenRow < lastSelection.getScreenRange().start.row,
        autoscroll: false,
        preserveFolds: true,
        suppressSelectionMerge: true
      })
    } else {
      initialBufferRange = clickedLineBufferRange
      if (addOrRemoveSelection) {
        model.addSelectionForBufferRange(clickedLineBufferRange, {autoscroll: false, preserveFolds: true})
      } else {
github atom / atom / src / text-mate-language-mode.js View on Github external
getFoldableRangesAtIndentLevel(indentLevel, tabLength) {
    const result = [];
    let row = 0;
    const lineCount = this.buffer.getLineCount();
    while (row < lineCount) {
      if (
        this.indentLevelForLine(this.buffer.lineForRow(row), tabLength) ===
        indentLevel
      ) {
        const endRow = this.endRowForFoldAtRow(row, tabLength);
        if (endRow != null) {
          result.push(Range(Point(row, Infinity), Point(endRow, Infinity)));
          row = endRow + 1;
          continue;
        }
      }
      row++;
    }
    return result;
  }
github atom / atom / src / text-editor-component.js View on Github external
didDrag: (event) => {
        this.autoscrollOnMouseDrag(event, true)
        const dragRow = this.screenPositionForMouseEvent(event).row
        const draggedLineScreenRange = Range(Point(dragRow, 0), Point(dragRow + 1, 0))
        model.getLastSelection().setScreenRange(draggedLineScreenRange.union(initialScreenRange), {
          reversed: dragRow < initialScreenRange.start.row,
          autoscroll: false,
          preserveFolds: true
        })
        this.updateSync()
      },
      didStopDragging: () => {
github atom / atom / src / text-mate-language-mode.js View on Github external
tag = tags[endTokenIndex];
      if (tag < 0) {
        if (tag % 2 === -1) {
          endScopes.push(this.grammar.scopeForId(tag));
        } else {
          endScopes.pop();
        }
      } else {
        if (!selectorMatchesAnyScope(selector, endScopes)) {
          break;
        }
        endColumn += tag;
      }
    }

    return new Range(
      new Point(position.row, startColumn),
      new Point(position.row, endColumn)
    );
  }
github atom / atom / src / cursor.js View on Github external
getPreviousWordBoundaryBufferPosition(options = {}) {
    const currentBufferPosition = this.getBufferPosition();
    const previousNonBlankRow = this.editor.buffer.previousNonBlankRow(
      currentBufferPosition.row
    );
    const scanRange = Range(
      Point(previousNonBlankRow || 0, 0),
      currentBufferPosition
    );

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

    const range = ranges[ranges.length - 1];
    if (range) {
      if (
        range.start.row < currentBufferPosition.row &&
        currentBufferPosition.column > 0
      ) {
        return Point(currentBufferPosition.row, 0);
github atom / atom / src / text-mate-language-mode.js View on Github external
getFoldableRangeContainingPoint(point, tabLength) {
    if (point.column >= this.buffer.lineLengthForRow(point.row)) {
      const endRow = this.endRowForFoldAtRow(point.row, tabLength);
      if (endRow != null) {
        return Range(Point(point.row, Infinity), Point(endRow, Infinity));
      }
    }

    for (let row = point.row - 1; row >= 0; row--) {
      const endRow = this.endRowForFoldAtRow(row, tabLength);
      if (endRow != null && endRow >= point.row) {
        return Range(Point(row, Infinity), Point(endRow, Infinity));
      }
    }
    return null;
  }
github suchipi / run-on-server / packages / babel-plugin / src / getSourceForNode.js View on Github external
export default function getSourceForNode(node, state) {
  const { start, end } = node.loc;
  const range = new TextBuffer.Range(
    [start.line - 1, start.column],
    [end.line - 1, end.column]
  );
  const source = state.file.code;
  return new TextBuffer(source).getTextInRange(range);
}
github atom / atom / src / cursor.js View on Github external
getBeginningOfCurrentWordBufferPosition(options = {}) {
    const allowPrevious = options.allowPrevious !== false;
    const position = this.getBufferPosition();

    const scanRange = allowPrevious
      ? new Range(new Point(position.row - 1, 0), position)
      : new Range(new Point(position.row, 0), position);

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

    let result;
    for (let range of ranges) {
      if (position.isLessThanOrEqual(range.start)) break;
      if (allowPrevious || position.isLessThanOrEqual(range.end))
        result = Point.fromObject(range.start);
    }

    return result || (allowPrevious ? new Point(0, 0) : position);
  }
github suchipi / run-on-server / packages / transform / src / macro.js View on Github external
function getSourceForNode(node) {
    const { start, end } = node.loc;
    const range = new TextBuffer.Range(
      [start.line - 1, start.column],
      [end.line - 1, end.column]
    );
    const source = state.file.code;
    return new TextBuffer(source).getTextInRange(range);
  }

text-buffer

A container for large mutable strings with annotated regions

MIT
Latest version published 4 years ago

Package Health Score

45 / 100
Full package analysis

Similar packages