diff --git a/src/tools.ts b/src/tools.ts index 3119288..12fa8f3 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -1,7 +1,7 @@ import * as monaco from 'monaco-editor' import { DisposableStore } from 'vscode/monaco' import { IIdentifiedSingleEditOperation, ValidAnnotatedEditOperation } from 'vscode/vscode/vs/editor/common/model' -import { getRangesFromDecorations, minusRanges } from './tools/utils/rangeUtils' +import { getRangesFromDecorations, excludeRanges } from './tools/utils/rangeUtils' import { LockedCodeError, tryIgnoreLockedCode } from './tools/utils/editorOperationUtils' /** @@ -266,9 +266,9 @@ export function hideCodeWithoutDecoration (editor: monaco.editor.ICodeEditor, de }, []) const { - firstRanges: hiddenAreas, - secondRanges: visibleRanges - } = minusRanges(model, model.getFullModelRange(), ranges) + filteredRanges: hiddenAreas, + removedRanges: visibleRanges + } = excludeRanges(model, model.getFullModelRange(), ranges) editor.setHiddenAreas(hiddenAreas, hideId) diff --git a/src/tools/utils/editorOperationUtils.ts b/src/tools/utils/editorOperationUtils.ts index 3e40dc9..3383067 100644 --- a/src/tools/utils/editorOperationUtils.ts +++ b/src/tools/utils/editorOperationUtils.ts @@ -1,6 +1,6 @@ import * as monaco from 'monaco-editor' import { ValidAnnotatedEditOperation } from 'vscode/vscode/vs/editor/common/model' -import { getLockedRanges, minusRanges } from './rangeUtils' +import { getLockedRanges, excludeRanges } from './rangeUtils' export class LockedCodeError extends Error { constructor (message: string) { @@ -98,9 +98,9 @@ export function tryIgnoreLockedCodeForOperations ( let newOperations: ValidAnnotatedEditOperation[] = [] for (const operation of operations) { const { - firstRanges: operationEditableRanges, - secondRanges: operationUneditableRanges - } = minusRanges(model, operation.range, uneditableRanges) + filteredRanges: operationEditableRanges, + removedRanges: operationUneditableRanges + } = excludeRanges(model, operation.range, uneditableRanges) const splitText = tryIgnoreLockedCodeTextForOperation(model, operationUneditableRanges, operation.text) newOperations = [ ...newOperations, diff --git a/src/tools/utils/rangeUtils.ts b/src/tools/utils/rangeUtils.ts index 6d44bc6..498c381 100644 --- a/src/tools/utils/rangeUtils.ts +++ b/src/tools/utils/rangeUtils.ts @@ -10,16 +10,16 @@ export function getRangesFromDecorations ( .map((decoration) => decoration.range) } -export function minusRanges ( +export function excludeRanges ( model: monaco.editor.ITextModel, uniqueRange: monaco.Range, ranges: monaco.Range[] ): { - firstRanges: monaco.Range[] - secondRanges: monaco.Range[] + filteredRanges: monaco.Range[] + removedRanges: monaco.Range[] } { - const firstRanges: monaco.Range[] = [] - const secondRanges: monaco.Range[] = [] + const filteredRanges: monaco.Range[] = [] + const removedRanges: monaco.Range[] = [] let lastEndPosition = uniqueRange.getStartPosition() const uniqueRangeEndPosition = uniqueRange.getEndPosition() const intersectingRanges = ranges.filter(range => monaco.Range.areIntersectingOrTouching(range, uniqueRange)) @@ -32,7 +32,7 @@ export function minusRanges ( const firstRangeStart = lastEndPosition.equals(uniqueRange.getStartPosition()) ? lastEndPosition : model.modifyPosition(lastEndPosition, 1) - firstRanges.push(monaco.Range.fromPositions( + filteredRanges.push(monaco.Range.fromPositions( firstRangeStart, (model.modifyPosition(rangeStart, -1)) )) @@ -40,7 +40,7 @@ export function minusRanges ( const secondRangeStart = lastEndPosition.isBefore(rangeStart) ? rangeStart : lastEndPosition const secondRangeEnd = uniqueRangeEndPosition.isBefore(rangeEnd) ? uniqueRangeEndPosition : rangeEnd - secondRanges.push(monaco.Range.fromPositions(secondRangeStart, secondRangeEnd)) + removedRanges.push(monaco.Range.fromPositions(secondRangeStart, secondRangeEnd)) lastEndPosition = rangeEnd } @@ -49,10 +49,10 @@ export function minusRanges ( const firstRangeStart = lastEndPosition.equals(uniqueRange.getStartPosition()) ? lastEndPosition : model.modifyPosition(lastEndPosition, 1) - firstRanges.push(monaco.Range.fromPositions(firstRangeStart, uniqueRangeEndPosition)) + filteredRanges.push(monaco.Range.fromPositions(firstRangeStart, uniqueRangeEndPosition)) } - return { firstRanges, secondRanges } + return { filteredRanges, removedRanges } } export function getLockedRanges ( @@ -62,6 +62,6 @@ export function getLockedRanges ( ): monaco.Range[] { const fullModelRange = model.getFullModelRange() const ranges = getRangesFromDecorations(model, decorationFilter) - const { firstRanges, secondRanges } = minusRanges(model, fullModelRange, ranges) + const { filteredRanges: firstRanges, removedRanges: secondRanges } = excludeRanges(model, fullModelRange, ranges) return withDecoration ? secondRanges : firstRanges }