Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export class MembraneEditorMetricsContribution extends Disposable implements IWo
this._currentEditorDisposables.add(activeControl.onDidLayoutChange(sendMetrics));
this._currentEditorDisposables.add(activeControl.onDidChangeHiddenAreas(sendMetrics));
this._currentEditorDisposables.add(activeControl.onDidChangeConfiguration(sendMetrics));
this._currentEditorDisposables.add(activeControl.onDidChangeCursorSelection(sendMetrics));
this._currentEditorDisposables.add(activeControl.onDidChangeModelContent(sendMetrics));
}

private _gatherMetrics(editor: ICodeEditor) {
Expand All @@ -67,6 +69,7 @@ export class MembraneEditorMetricsContribution extends Disposable implements IWo
const lineCount = model.getLineCount();
const startLine = Math.max(1, firstVisibleLine - 20);
const endLine = Math.min(lineCount, lastVisibleLine + 20);
const selection = editor.getSelection();

const isLineVisible = (line: number): boolean => {
return visibleRanges.some(range =>
Expand All @@ -85,6 +88,58 @@ export class MembraneEditorMetricsContribution extends Disposable implements IWo
}
}

const hasSelection = selection && (
selection.selectionStartLineNumber !== selection.positionLineNumber ||
selection.selectionStartColumn !== selection.positionColumn
);

let selectionData = undefined;
if (hasSelection) {
const startLineNum = Math.min(selection.selectionStartLineNumber, selection.positionLineNumber);
const endLineNum = Math.max(selection.selectionStartLineNumber, selection.positionLineNumber);

let minLeft = Infinity;
let maxRight = 0;
for (let line = startLineNum; line <= endLineNum; line++) {
let lineStartCol: number;
let lineEndCol: number;

if (line === selection.selectionStartLineNumber && line === selection.positionLineNumber) {
lineStartCol = Math.min(selection.selectionStartColumn, selection.positionColumn);
lineEndCol = Math.max(selection.selectionStartColumn, selection.positionColumn);
} else if (line === startLineNum) {
const startCol = line === selection.selectionStartLineNumber ? selection.selectionStartColumn : selection.positionColumn;
lineStartCol = startCol;
lineEndCol = model.getLineMaxColumn(line);
} else if (line === endLineNum) {
const endCol = line === selection.positionLineNumber ? selection.positionColumn : selection.selectionStartColumn;
lineStartCol = 1;
lineEndCol = endCol;
} else {
lineStartCol = 1;
lineEndCol = model.getLineMaxColumn(line);
}

const leftOffset = editor.getOffsetForColumn(line, lineStartCol);
const rightOffset = editor.getOffsetForColumn(line, lineEndCol);
if (leftOffset !== -1) {
minLeft = Math.min(minLeft, leftOffset);
}
if (rightOffset !== -1) {
maxRight = Math.max(maxRight, rightOffset);
}
}

selectionData = {
selectionStartLineNumber: selection.selectionStartLineNumber,
selectionStartColumn: selection.selectionStartColumn,
positionLineNumber: selection.positionLineNumber,
positionColumn: selection.positionColumn,
visualLeft: minLeft !== Infinity ? minLeft : undefined,
visualRight: maxRight > 0 ? maxRight : undefined,
};
}

return {
uri: model.uri.toString(),
scrollTop: editor.getScrollTop(),
Expand All @@ -94,7 +149,9 @@ export class MembraneEditorMetricsContribution extends Disposable implements IWo
lastVisibleLine,
contentLeft: layoutInfo.contentLeft,
contentWidth: layoutInfo.contentWidth,
lineCount,
linePositions,
...(selectionData && { selection: selectionData }),
};
}
}
Expand Down
Loading