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