97c600da5bd5d7fe92b0aa89a86191623b95f996f28b397c3451d422545d6b54d9b148d6c0ccf827c7e4652d71afce667223fef962cb1ba59fd29ca206c149 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 { registerEditorCommand } from '../../../browser/editorExtensions.js';
  6. import { WordPartOperations } from '../../../common/cursor/cursorWordOperations.js';
  7. import { Range } from '../../../common/core/range.js';
  8. import { EditorContextKeys } from '../../../common/editorContextKeys.js';
  9. import { DeleteWordCommand, MoveWordCommand } from '../../wordOperations/browser/wordOperations.js';
  10. import { CommandsRegistry } from '../../../../platform/commands/common/commands.js';
  11. export class DeleteWordPartLeft extends DeleteWordCommand {
  12. constructor() {
  13. super({
  14. whitespaceHeuristics: true,
  15. wordNavigationType: 0 /* WordNavigationType.WordStart */,
  16. id: 'deleteWordPartLeft',
  17. precondition: EditorContextKeys.writable,
  18. kbOpts: {
  19. kbExpr: EditorContextKeys.textInputFocus,
  20. primary: 0,
  21. mac: { primary: 256 /* KeyMod.WinCtrl */ | 512 /* KeyMod.Alt */ | 1 /* KeyCode.Backspace */ },
  22. weight: 100 /* KeybindingWeight.EditorContrib */
  23. }
  24. });
  25. }
  26. _delete(ctx, wordNavigationType) {
  27. const r = WordPartOperations.deleteWordPartLeft(ctx);
  28. if (r) {
  29. return r;
  30. }
  31. return new Range(1, 1, 1, 1);
  32. }
  33. }
  34. export class DeleteWordPartRight extends DeleteWordCommand {
  35. constructor() {
  36. super({
  37. whitespaceHeuristics: true,
  38. wordNavigationType: 2 /* WordNavigationType.WordEnd */,
  39. id: 'deleteWordPartRight',
  40. precondition: EditorContextKeys.writable,
  41. kbOpts: {
  42. kbExpr: EditorContextKeys.textInputFocus,
  43. primary: 0,
  44. mac: { primary: 256 /* KeyMod.WinCtrl */ | 512 /* KeyMod.Alt */ | 20 /* KeyCode.Delete */ },
  45. weight: 100 /* KeybindingWeight.EditorContrib */
  46. }
  47. });
  48. }
  49. _delete(ctx, wordNavigationType) {
  50. const r = WordPartOperations.deleteWordPartRight(ctx);
  51. if (r) {
  52. return r;
  53. }
  54. const lineCount = ctx.model.getLineCount();
  55. const maxColumn = ctx.model.getLineMaxColumn(lineCount);
  56. return new Range(lineCount, maxColumn, lineCount, maxColumn);
  57. }
  58. }
  59. export class WordPartLeftCommand extends MoveWordCommand {
  60. _move(wordSeparators, model, position, wordNavigationType) {
  61. return WordPartOperations.moveWordPartLeft(wordSeparators, model, position);
  62. }
  63. }
  64. export class CursorWordPartLeft extends WordPartLeftCommand {
  65. constructor() {
  66. super({
  67. inSelectionMode: false,
  68. wordNavigationType: 0 /* WordNavigationType.WordStart */,
  69. id: 'cursorWordPartLeft',
  70. precondition: undefined,
  71. kbOpts: {
  72. kbExpr: EditorContextKeys.textInputFocus,
  73. primary: 0,
  74. mac: { primary: 256 /* KeyMod.WinCtrl */ | 512 /* KeyMod.Alt */ | 15 /* KeyCode.LeftArrow */ },
  75. weight: 100 /* KeybindingWeight.EditorContrib */
  76. }
  77. });
  78. }
  79. }
  80. // Register previous id for compatibility purposes
  81. CommandsRegistry.registerCommandAlias('cursorWordPartStartLeft', 'cursorWordPartLeft');
  82. export class CursorWordPartLeftSelect extends WordPartLeftCommand {
  83. constructor() {
  84. super({
  85. inSelectionMode: true,
  86. wordNavigationType: 0 /* WordNavigationType.WordStart */,
  87. id: 'cursorWordPartLeftSelect',
  88. precondition: undefined,
  89. kbOpts: {
  90. kbExpr: EditorContextKeys.textInputFocus,
  91. primary: 0,
  92. mac: { primary: 256 /* KeyMod.WinCtrl */ | 512 /* KeyMod.Alt */ | 1024 /* KeyMod.Shift */ | 15 /* KeyCode.LeftArrow */ },
  93. weight: 100 /* KeybindingWeight.EditorContrib */
  94. }
  95. });
  96. }
  97. }
  98. // Register previous id for compatibility purposes
  99. CommandsRegistry.registerCommandAlias('cursorWordPartStartLeftSelect', 'cursorWordPartLeftSelect');
  100. export class WordPartRightCommand extends MoveWordCommand {
  101. _move(wordSeparators, model, position, wordNavigationType) {
  102. return WordPartOperations.moveWordPartRight(wordSeparators, model, position);
  103. }
  104. }
  105. export class CursorWordPartRight extends WordPartRightCommand {
  106. constructor() {
  107. super({
  108. inSelectionMode: false,
  109. wordNavigationType: 2 /* WordNavigationType.WordEnd */,
  110. id: 'cursorWordPartRight',
  111. precondition: undefined,
  112. kbOpts: {
  113. kbExpr: EditorContextKeys.textInputFocus,
  114. primary: 0,
  115. mac: { primary: 256 /* KeyMod.WinCtrl */ | 512 /* KeyMod.Alt */ | 17 /* KeyCode.RightArrow */ },
  116. weight: 100 /* KeybindingWeight.EditorContrib */
  117. }
  118. });
  119. }
  120. }
  121. export class CursorWordPartRightSelect extends WordPartRightCommand {
  122. constructor() {
  123. super({
  124. inSelectionMode: true,
  125. wordNavigationType: 2 /* WordNavigationType.WordEnd */,
  126. id: 'cursorWordPartRightSelect',
  127. precondition: undefined,
  128. kbOpts: {
  129. kbExpr: EditorContextKeys.textInputFocus,
  130. primary: 0,
  131. mac: { primary: 256 /* KeyMod.WinCtrl */ | 512 /* KeyMod.Alt */ | 1024 /* KeyMod.Shift */ | 17 /* KeyCode.RightArrow */ },
  132. weight: 100 /* KeybindingWeight.EditorContrib */
  133. }
  134. });
  135. }
  136. }
  137. registerEditorCommand(new DeleteWordPartLeft());
  138. registerEditorCommand(new DeleteWordPartRight());
  139. registerEditorCommand(new CursorWordPartLeft());
  140. registerEditorCommand(new CursorWordPartLeftSelect());
  141. registerEditorCommand(new CursorWordPartRight());
  142. registerEditorCommand(new CursorWordPartRightSelect());