caretOperations.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 { EditorAction, registerEditorAction } from '../../browser/editorExtensions.js';
  6. import { EditorContextKeys } from '../../common/editorContextKeys.js';
  7. import { MoveCaretCommand } from './moveCaretCommand.js';
  8. import * as nls from '../../../nls.js';
  9. class MoveCaretAction extends EditorAction {
  10. constructor(left, opts) {
  11. super(opts);
  12. this.left = left;
  13. }
  14. run(accessor, editor) {
  15. if (!editor.hasModel()) {
  16. return;
  17. }
  18. let commands = [];
  19. let selections = editor.getSelections();
  20. for (const selection of selections) {
  21. commands.push(new MoveCaretCommand(selection, this.left));
  22. }
  23. editor.pushUndoStop();
  24. editor.executeCommands(this.id, commands);
  25. editor.pushUndoStop();
  26. }
  27. }
  28. class MoveCaretLeftAction extends MoveCaretAction {
  29. constructor() {
  30. super(true, {
  31. id: 'editor.action.moveCarretLeftAction',
  32. label: nls.localize('caret.moveLeft', "Move Selected Text Left"),
  33. alias: 'Move Selected Text Left',
  34. precondition: EditorContextKeys.writable
  35. });
  36. }
  37. }
  38. class MoveCaretRightAction extends MoveCaretAction {
  39. constructor() {
  40. super(false, {
  41. id: 'editor.action.moveCarretRightAction',
  42. label: nls.localize('caret.moveRight', "Move Selected Text Right"),
  43. alias: 'Move Selected Text Right',
  44. precondition: EditorContextKeys.writable
  45. });
  46. }
  47. }
  48. registerEditorAction(MoveCaretLeftAction);
  49. registerEditorAction(MoveCaretRightAction);