Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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());
}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;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 tokenmoveUp(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;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;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;
}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;
}
}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) {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);
}