surroundSelectionCommand.js 1.5 KB

1234567891011121314151617181920212223
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { Range } from '../core/range.js';
  6. import { Selection } from '../core/selection.js';
  7. export class SurroundSelectionCommand {
  8. constructor(range, charBeforeSelection, charAfterSelection) {
  9. this._range = range;
  10. this._charBeforeSelection = charBeforeSelection;
  11. this._charAfterSelection = charAfterSelection;
  12. }
  13. getEditOperations(model, builder) {
  14. builder.addTrackedEditOperation(new Range(this._range.startLineNumber, this._range.startColumn, this._range.startLineNumber, this._range.startColumn), this._charBeforeSelection);
  15. builder.addTrackedEditOperation(new Range(this._range.endLineNumber, this._range.endColumn, this._range.endLineNumber, this._range.endColumn), this._charAfterSelection);
  16. }
  17. computeCursorState(model, helper) {
  18. let inverseEditOperations = helper.getInverseEditOperations();
  19. let firstOperationRange = inverseEditOperations[0].range;
  20. let secondOperationRange = inverseEditOperations[1].range;
  21. return new Selection(firstOperationRange.endLineNumber, firstOperationRange.endColumn, secondOperationRange.endLineNumber, secondOperationRange.endColumn - this._charAfterSelection.length);
  22. }
  23. }