e435307462b1c38b59637cc83824023f4cb1284a4b689fb756882db2dc36216cfbafe295e56eb7f79f937d2c13c85a3115ae4328e935c90e99f97a1cb3f8e1 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  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 * as nls from '../../nls.js';
  6. import { isFirefox } from '../../base/browser/browser.js';
  7. import * as types from '../../base/common/types.js';
  8. import { status } from '../../base/browser/ui/aria/aria.js';
  9. import { Command, EditorCommand, registerEditorCommand, UndoCommand, RedoCommand, SelectAllCommand } from './editorExtensions.js';
  10. import { ICodeEditorService } from './services/codeEditorService.js';
  11. import { ColumnSelection } from '../common/cursor/cursorColumnSelection.js';
  12. import { CursorState } from '../common/cursorCommon.js';
  13. import { DeleteOperations } from '../common/cursor/cursorDeleteOperations.js';
  14. import { CursorMove as CursorMove_, CursorMoveCommands } from '../common/cursor/cursorMoveCommands.js';
  15. import { TypeOperations } from '../common/cursor/cursorTypeOperations.js';
  16. import { Position } from '../common/core/position.js';
  17. import { Range } from '../common/core/range.js';
  18. import { EditorContextKeys } from '../common/editorContextKeys.js';
  19. import { ContextKeyExpr } from '../../platform/contextkey/common/contextkey.js';
  20. import { KeybindingsRegistry } from '../../platform/keybinding/common/keybindingsRegistry.js';
  21. const CORE_WEIGHT = 0 /* KeybindingWeight.EditorCore */;
  22. export class CoreEditorCommand extends EditorCommand {
  23. runEditorCommand(accessor, editor, args) {
  24. const viewModel = editor._getViewModel();
  25. if (!viewModel) {
  26. // the editor has no view => has no cursors
  27. return;
  28. }
  29. this.runCoreEditorCommand(viewModel, args || {});
  30. }
  31. }
  32. export var EditorScroll_;
  33. (function (EditorScroll_) {
  34. const isEditorScrollArgs = function (arg) {
  35. if (!types.isObject(arg)) {
  36. return false;
  37. }
  38. const scrollArg = arg;
  39. if (!types.isString(scrollArg.to)) {
  40. return false;
  41. }
  42. if (!types.isUndefined(scrollArg.by) && !types.isString(scrollArg.by)) {
  43. return false;
  44. }
  45. if (!types.isUndefined(scrollArg.value) && !types.isNumber(scrollArg.value)) {
  46. return false;
  47. }
  48. if (!types.isUndefined(scrollArg.revealCursor) && !types.isBoolean(scrollArg.revealCursor)) {
  49. return false;
  50. }
  51. return true;
  52. };
  53. EditorScroll_.description = {
  54. description: 'Scroll editor in the given direction',
  55. args: [
  56. {
  57. name: 'Editor scroll argument object',
  58. description: `Property-value pairs that can be passed through this argument:
  59. * 'to': A mandatory direction value.
  60. \`\`\`
  61. 'up', 'down'
  62. \`\`\`
  63. * 'by': Unit to move. Default is computed based on 'to' value.
  64. \`\`\`
  65. 'line', 'wrappedLine', 'page', 'halfPage', 'editor'
  66. \`\`\`
  67. * 'value': Number of units to move. Default is '1'.
  68. * 'revealCursor': If 'true' reveals the cursor if it is outside view port.
  69. `,
  70. constraint: isEditorScrollArgs,
  71. schema: {
  72. 'type': 'object',
  73. 'required': ['to'],
  74. 'properties': {
  75. 'to': {
  76. 'type': 'string',
  77. 'enum': ['up', 'down']
  78. },
  79. 'by': {
  80. 'type': 'string',
  81. 'enum': ['line', 'wrappedLine', 'page', 'halfPage', 'editor']
  82. },
  83. 'value': {
  84. 'type': 'number',
  85. 'default': 1
  86. },
  87. 'revealCursor': {
  88. 'type': 'boolean',
  89. }
  90. }
  91. }
  92. }
  93. ]
  94. };
  95. /**
  96. * Directions in the view for editor scroll command.
  97. */
  98. EditorScroll_.RawDirection = {
  99. Up: 'up',
  100. Down: 'down',
  101. };
  102. /**
  103. * Units for editor scroll 'by' argument
  104. */
  105. EditorScroll_.RawUnit = {
  106. Line: 'line',
  107. WrappedLine: 'wrappedLine',
  108. Page: 'page',
  109. HalfPage: 'halfPage',
  110. Editor: 'editor'
  111. };
  112. function parse(args) {
  113. let direction;
  114. switch (args.to) {
  115. case EditorScroll_.RawDirection.Up:
  116. direction = 1 /* Direction.Up */;
  117. break;
  118. case EditorScroll_.RawDirection.Down:
  119. direction = 2 /* Direction.Down */;
  120. break;
  121. default:
  122. // Illegal arguments
  123. return null;
  124. }
  125. let unit;
  126. switch (args.by) {
  127. case EditorScroll_.RawUnit.Line:
  128. unit = 1 /* Unit.Line */;
  129. break;
  130. case EditorScroll_.RawUnit.WrappedLine:
  131. unit = 2 /* Unit.WrappedLine */;
  132. break;
  133. case EditorScroll_.RawUnit.Page:
  134. unit = 3 /* Unit.Page */;
  135. break;
  136. case EditorScroll_.RawUnit.HalfPage:
  137. unit = 4 /* Unit.HalfPage */;
  138. break;
  139. case EditorScroll_.RawUnit.Editor:
  140. unit = 5 /* Unit.Editor */;
  141. break;
  142. default:
  143. unit = 2 /* Unit.WrappedLine */;
  144. }
  145. const value = Math.floor(args.value || 1);
  146. const revealCursor = !!args.revealCursor;
  147. return {
  148. direction: direction,
  149. unit: unit,
  150. value: value,
  151. revealCursor: revealCursor,
  152. select: (!!args.select)
  153. };
  154. }
  155. EditorScroll_.parse = parse;
  156. })(EditorScroll_ || (EditorScroll_ = {}));
  157. export var RevealLine_;
  158. (function (RevealLine_) {
  159. const isRevealLineArgs = function (arg) {
  160. if (!types.isObject(arg)) {
  161. return false;
  162. }
  163. const reveaLineArg = arg;
  164. if (!types.isNumber(reveaLineArg.lineNumber) && !types.isString(reveaLineArg.lineNumber)) {
  165. return false;
  166. }
  167. if (!types.isUndefined(reveaLineArg.at) && !types.isString(reveaLineArg.at)) {
  168. return false;
  169. }
  170. return true;
  171. };
  172. RevealLine_.description = {
  173. description: 'Reveal the given line at the given logical position',
  174. args: [
  175. {
  176. name: 'Reveal line argument object',
  177. description: `Property-value pairs that can be passed through this argument:
  178. * 'lineNumber': A mandatory line number value.
  179. * 'at': Logical position at which line has to be revealed.
  180. \`\`\`
  181. 'top', 'center', 'bottom'
  182. \`\`\`
  183. `,
  184. constraint: isRevealLineArgs,
  185. schema: {
  186. 'type': 'object',
  187. 'required': ['lineNumber'],
  188. 'properties': {
  189. 'lineNumber': {
  190. 'type': ['number', 'string'],
  191. },
  192. 'at': {
  193. 'type': 'string',
  194. 'enum': ['top', 'center', 'bottom']
  195. }
  196. }
  197. }
  198. }
  199. ]
  200. };
  201. /**
  202. * Values for reveal line 'at' argument
  203. */
  204. RevealLine_.RawAtArgument = {
  205. Top: 'top',
  206. Center: 'center',
  207. Bottom: 'bottom'
  208. };
  209. })(RevealLine_ || (RevealLine_ = {}));
  210. class EditorOrNativeTextInputCommand {
  211. constructor(target) {
  212. // 1. handle case when focus is in editor.
  213. target.addImplementation(10000, 'code-editor', (accessor, args) => {
  214. // Only if editor text focus (i.e. not if editor has widget focus).
  215. const focusedEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
  216. if (focusedEditor && focusedEditor.hasTextFocus()) {
  217. return this._runEditorCommand(accessor, focusedEditor, args);
  218. }
  219. return false;
  220. });
  221. // 2. handle case when focus is in some other `input` / `textarea`.
  222. target.addImplementation(1000, 'generic-dom-input-textarea', (accessor, args) => {
  223. // Only if focused on an element that allows for entering text
  224. const activeElement = document.activeElement;
  225. if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) {
  226. this.runDOMCommand();
  227. return true;
  228. }
  229. return false;
  230. });
  231. // 3. (default) handle case when focus is somewhere else.
  232. target.addImplementation(0, 'generic-dom', (accessor, args) => {
  233. // Redirecting to active editor
  234. const activeEditor = accessor.get(ICodeEditorService).getActiveCodeEditor();
  235. if (activeEditor) {
  236. activeEditor.focus();
  237. return this._runEditorCommand(accessor, activeEditor, args);
  238. }
  239. return false;
  240. });
  241. }
  242. _runEditorCommand(accessor, editor, args) {
  243. const result = this.runEditorCommand(accessor, editor, args);
  244. if (result) {
  245. return result;
  246. }
  247. return true;
  248. }
  249. }
  250. export var CoreNavigationCommands;
  251. (function (CoreNavigationCommands) {
  252. class BaseMoveToCommand extends CoreEditorCommand {
  253. constructor(opts) {
  254. super(opts);
  255. this._minimalReveal = opts.minimalReveal;
  256. this._inSelectionMode = opts.inSelectionMode;
  257. }
  258. runCoreEditorCommand(viewModel, args) {
  259. viewModel.model.pushStackElement();
  260. const cursorStateChanged = viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, [
  261. CursorMoveCommands.moveTo(viewModel, viewModel.getPrimaryCursorState(), this._inSelectionMode, args.position, args.viewPosition)
  262. ]);
  263. if (cursorStateChanged) {
  264. viewModel.revealPrimaryCursor(args.source, true, this._minimalReveal);
  265. }
  266. }
  267. }
  268. CoreNavigationCommands.MoveTo = registerEditorCommand(new BaseMoveToCommand({
  269. id: '_moveTo',
  270. minimalReveal: true,
  271. inSelectionMode: false,
  272. precondition: undefined
  273. }));
  274. CoreNavigationCommands.MoveToSelect = registerEditorCommand(new BaseMoveToCommand({
  275. id: '_moveToSelect',
  276. minimalReveal: false,
  277. inSelectionMode: true,
  278. precondition: undefined
  279. }));
  280. class ColumnSelectCommand extends CoreEditorCommand {
  281. runCoreEditorCommand(viewModel, args) {
  282. viewModel.model.pushStackElement();
  283. const result = this._getColumnSelectResult(viewModel, viewModel.getPrimaryCursorState(), viewModel.getCursorColumnSelectData(), args);
  284. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, result.viewStates.map((viewState) => CursorState.fromViewState(viewState)));
  285. viewModel.setCursorColumnSelectData({
  286. isReal: true,
  287. fromViewLineNumber: result.fromLineNumber,
  288. fromViewVisualColumn: result.fromVisualColumn,
  289. toViewLineNumber: result.toLineNumber,
  290. toViewVisualColumn: result.toVisualColumn
  291. });
  292. if (result.reversed) {
  293. viewModel.revealTopMostCursor(args.source);
  294. }
  295. else {
  296. viewModel.revealBottomMostCursor(args.source);
  297. }
  298. }
  299. }
  300. CoreNavigationCommands.ColumnSelect = registerEditorCommand(new class extends ColumnSelectCommand {
  301. constructor() {
  302. super({
  303. id: 'columnSelect',
  304. precondition: undefined
  305. });
  306. }
  307. _getColumnSelectResult(viewModel, primary, prevColumnSelectData, args) {
  308. // validate `args`
  309. const validatedPosition = viewModel.model.validatePosition(args.position);
  310. const validatedViewPosition = viewModel.coordinatesConverter.validateViewPosition(new Position(args.viewPosition.lineNumber, args.viewPosition.column), validatedPosition);
  311. const fromViewLineNumber = args.doColumnSelect ? prevColumnSelectData.fromViewLineNumber : validatedViewPosition.lineNumber;
  312. const fromViewVisualColumn = args.doColumnSelect ? prevColumnSelectData.fromViewVisualColumn : args.mouseColumn - 1;
  313. return ColumnSelection.columnSelect(viewModel.cursorConfig, viewModel, fromViewLineNumber, fromViewVisualColumn, validatedViewPosition.lineNumber, args.mouseColumn - 1);
  314. }
  315. });
  316. CoreNavigationCommands.CursorColumnSelectLeft = registerEditorCommand(new class extends ColumnSelectCommand {
  317. constructor() {
  318. super({
  319. id: 'cursorColumnSelectLeft',
  320. precondition: undefined,
  321. kbOpts: {
  322. weight: CORE_WEIGHT,
  323. kbExpr: EditorContextKeys.textInputFocus,
  324. primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 512 /* KeyMod.Alt */ | 15 /* KeyCode.LeftArrow */,
  325. linux: { primary: 0 }
  326. }
  327. });
  328. }
  329. _getColumnSelectResult(viewModel, primary, prevColumnSelectData, args) {
  330. return ColumnSelection.columnSelectLeft(viewModel.cursorConfig, viewModel, prevColumnSelectData);
  331. }
  332. });
  333. CoreNavigationCommands.CursorColumnSelectRight = registerEditorCommand(new class extends ColumnSelectCommand {
  334. constructor() {
  335. super({
  336. id: 'cursorColumnSelectRight',
  337. precondition: undefined,
  338. kbOpts: {
  339. weight: CORE_WEIGHT,
  340. kbExpr: EditorContextKeys.textInputFocus,
  341. primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 512 /* KeyMod.Alt */ | 17 /* KeyCode.RightArrow */,
  342. linux: { primary: 0 }
  343. }
  344. });
  345. }
  346. _getColumnSelectResult(viewModel, primary, prevColumnSelectData, args) {
  347. return ColumnSelection.columnSelectRight(viewModel.cursorConfig, viewModel, prevColumnSelectData);
  348. }
  349. });
  350. class ColumnSelectUpCommand extends ColumnSelectCommand {
  351. constructor(opts) {
  352. super(opts);
  353. this._isPaged = opts.isPaged;
  354. }
  355. _getColumnSelectResult(viewModel, primary, prevColumnSelectData, args) {
  356. return ColumnSelection.columnSelectUp(viewModel.cursorConfig, viewModel, prevColumnSelectData, this._isPaged);
  357. }
  358. }
  359. CoreNavigationCommands.CursorColumnSelectUp = registerEditorCommand(new ColumnSelectUpCommand({
  360. isPaged: false,
  361. id: 'cursorColumnSelectUp',
  362. precondition: undefined,
  363. kbOpts: {
  364. weight: CORE_WEIGHT,
  365. kbExpr: EditorContextKeys.textInputFocus,
  366. primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 512 /* KeyMod.Alt */ | 16 /* KeyCode.UpArrow */,
  367. linux: { primary: 0 }
  368. }
  369. }));
  370. CoreNavigationCommands.CursorColumnSelectPageUp = registerEditorCommand(new ColumnSelectUpCommand({
  371. isPaged: true,
  372. id: 'cursorColumnSelectPageUp',
  373. precondition: undefined,
  374. kbOpts: {
  375. weight: CORE_WEIGHT,
  376. kbExpr: EditorContextKeys.textInputFocus,
  377. primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 512 /* KeyMod.Alt */ | 11 /* KeyCode.PageUp */,
  378. linux: { primary: 0 }
  379. }
  380. }));
  381. class ColumnSelectDownCommand extends ColumnSelectCommand {
  382. constructor(opts) {
  383. super(opts);
  384. this._isPaged = opts.isPaged;
  385. }
  386. _getColumnSelectResult(viewModel, primary, prevColumnSelectData, args) {
  387. return ColumnSelection.columnSelectDown(viewModel.cursorConfig, viewModel, prevColumnSelectData, this._isPaged);
  388. }
  389. }
  390. CoreNavigationCommands.CursorColumnSelectDown = registerEditorCommand(new ColumnSelectDownCommand({
  391. isPaged: false,
  392. id: 'cursorColumnSelectDown',
  393. precondition: undefined,
  394. kbOpts: {
  395. weight: CORE_WEIGHT,
  396. kbExpr: EditorContextKeys.textInputFocus,
  397. primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 512 /* KeyMod.Alt */ | 18 /* KeyCode.DownArrow */,
  398. linux: { primary: 0 }
  399. }
  400. }));
  401. CoreNavigationCommands.CursorColumnSelectPageDown = registerEditorCommand(new ColumnSelectDownCommand({
  402. isPaged: true,
  403. id: 'cursorColumnSelectPageDown',
  404. precondition: undefined,
  405. kbOpts: {
  406. weight: CORE_WEIGHT,
  407. kbExpr: EditorContextKeys.textInputFocus,
  408. primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 512 /* KeyMod.Alt */ | 12 /* KeyCode.PageDown */,
  409. linux: { primary: 0 }
  410. }
  411. }));
  412. class CursorMoveImpl extends CoreEditorCommand {
  413. constructor() {
  414. super({
  415. id: 'cursorMove',
  416. precondition: undefined,
  417. description: CursorMove_.description
  418. });
  419. }
  420. runCoreEditorCommand(viewModel, args) {
  421. const parsed = CursorMove_.parse(args);
  422. if (!parsed) {
  423. // illegal arguments
  424. return;
  425. }
  426. this._runCursorMove(viewModel, args.source, parsed);
  427. }
  428. _runCursorMove(viewModel, source, args) {
  429. viewModel.model.pushStackElement();
  430. viewModel.setCursorStates(source, 3 /* CursorChangeReason.Explicit */, CursorMoveImpl._move(viewModel, viewModel.getCursorStates(), args));
  431. viewModel.revealPrimaryCursor(source, true);
  432. }
  433. static _move(viewModel, cursors, args) {
  434. const inSelectionMode = args.select;
  435. const value = args.value;
  436. switch (args.direction) {
  437. case 0 /* CursorMove_.Direction.Left */:
  438. case 1 /* CursorMove_.Direction.Right */:
  439. case 2 /* CursorMove_.Direction.Up */:
  440. case 3 /* CursorMove_.Direction.Down */:
  441. case 4 /* CursorMove_.Direction.PrevBlankLine */:
  442. case 5 /* CursorMove_.Direction.NextBlankLine */:
  443. case 6 /* CursorMove_.Direction.WrappedLineStart */:
  444. case 7 /* CursorMove_.Direction.WrappedLineFirstNonWhitespaceCharacter */:
  445. case 8 /* CursorMove_.Direction.WrappedLineColumnCenter */:
  446. case 9 /* CursorMove_.Direction.WrappedLineEnd */:
  447. case 10 /* CursorMove_.Direction.WrappedLineLastNonWhitespaceCharacter */:
  448. return CursorMoveCommands.simpleMove(viewModel, cursors, args.direction, inSelectionMode, value, args.unit);
  449. case 11 /* CursorMove_.Direction.ViewPortTop */:
  450. case 13 /* CursorMove_.Direction.ViewPortBottom */:
  451. case 12 /* CursorMove_.Direction.ViewPortCenter */:
  452. case 14 /* CursorMove_.Direction.ViewPortIfOutside */:
  453. return CursorMoveCommands.viewportMove(viewModel, cursors, args.direction, inSelectionMode, value);
  454. default:
  455. return null;
  456. }
  457. }
  458. }
  459. CoreNavigationCommands.CursorMoveImpl = CursorMoveImpl;
  460. CoreNavigationCommands.CursorMove = registerEditorCommand(new CursorMoveImpl());
  461. class CursorMoveBasedCommand extends CoreEditorCommand {
  462. constructor(opts) {
  463. super(opts);
  464. this._staticArgs = opts.args;
  465. }
  466. runCoreEditorCommand(viewModel, dynamicArgs) {
  467. let args = this._staticArgs;
  468. if (this._staticArgs.value === -1 /* Constants.PAGE_SIZE_MARKER */) {
  469. // -1 is a marker for page size
  470. args = {
  471. direction: this._staticArgs.direction,
  472. unit: this._staticArgs.unit,
  473. select: this._staticArgs.select,
  474. value: dynamicArgs.pageSize || viewModel.cursorConfig.pageSize
  475. };
  476. }
  477. viewModel.model.pushStackElement();
  478. viewModel.setCursorStates(dynamicArgs.source, 3 /* CursorChangeReason.Explicit */, CursorMoveCommands.simpleMove(viewModel, viewModel.getCursorStates(), args.direction, args.select, args.value, args.unit));
  479. viewModel.revealPrimaryCursor(dynamicArgs.source, true);
  480. }
  481. }
  482. CoreNavigationCommands.CursorLeft = registerEditorCommand(new CursorMoveBasedCommand({
  483. args: {
  484. direction: 0 /* CursorMove_.Direction.Left */,
  485. unit: 0 /* CursorMove_.Unit.None */,
  486. select: false,
  487. value: 1
  488. },
  489. id: 'cursorLeft',
  490. precondition: undefined,
  491. kbOpts: {
  492. weight: CORE_WEIGHT,
  493. kbExpr: EditorContextKeys.textInputFocus,
  494. primary: 15 /* KeyCode.LeftArrow */,
  495. mac: { primary: 15 /* KeyCode.LeftArrow */, secondary: [256 /* KeyMod.WinCtrl */ | 32 /* KeyCode.KeyB */] }
  496. }
  497. }));
  498. CoreNavigationCommands.CursorLeftSelect = registerEditorCommand(new CursorMoveBasedCommand({
  499. args: {
  500. direction: 0 /* CursorMove_.Direction.Left */,
  501. unit: 0 /* CursorMove_.Unit.None */,
  502. select: true,
  503. value: 1
  504. },
  505. id: 'cursorLeftSelect',
  506. precondition: undefined,
  507. kbOpts: {
  508. weight: CORE_WEIGHT,
  509. kbExpr: EditorContextKeys.textInputFocus,
  510. primary: 1024 /* KeyMod.Shift */ | 15 /* KeyCode.LeftArrow */
  511. }
  512. }));
  513. CoreNavigationCommands.CursorRight = registerEditorCommand(new CursorMoveBasedCommand({
  514. args: {
  515. direction: 1 /* CursorMove_.Direction.Right */,
  516. unit: 0 /* CursorMove_.Unit.None */,
  517. select: false,
  518. value: 1
  519. },
  520. id: 'cursorRight',
  521. precondition: undefined,
  522. kbOpts: {
  523. weight: CORE_WEIGHT,
  524. kbExpr: EditorContextKeys.textInputFocus,
  525. primary: 17 /* KeyCode.RightArrow */,
  526. mac: { primary: 17 /* KeyCode.RightArrow */, secondary: [256 /* KeyMod.WinCtrl */ | 36 /* KeyCode.KeyF */] }
  527. }
  528. }));
  529. CoreNavigationCommands.CursorRightSelect = registerEditorCommand(new CursorMoveBasedCommand({
  530. args: {
  531. direction: 1 /* CursorMove_.Direction.Right */,
  532. unit: 0 /* CursorMove_.Unit.None */,
  533. select: true,
  534. value: 1
  535. },
  536. id: 'cursorRightSelect',
  537. precondition: undefined,
  538. kbOpts: {
  539. weight: CORE_WEIGHT,
  540. kbExpr: EditorContextKeys.textInputFocus,
  541. primary: 1024 /* KeyMod.Shift */ | 17 /* KeyCode.RightArrow */
  542. }
  543. }));
  544. CoreNavigationCommands.CursorUp = registerEditorCommand(new CursorMoveBasedCommand({
  545. args: {
  546. direction: 2 /* CursorMove_.Direction.Up */,
  547. unit: 2 /* CursorMove_.Unit.WrappedLine */,
  548. select: false,
  549. value: 1
  550. },
  551. id: 'cursorUp',
  552. precondition: undefined,
  553. kbOpts: {
  554. weight: CORE_WEIGHT,
  555. kbExpr: EditorContextKeys.textInputFocus,
  556. primary: 16 /* KeyCode.UpArrow */,
  557. mac: { primary: 16 /* KeyCode.UpArrow */, secondary: [256 /* KeyMod.WinCtrl */ | 46 /* KeyCode.KeyP */] }
  558. }
  559. }));
  560. CoreNavigationCommands.CursorUpSelect = registerEditorCommand(new CursorMoveBasedCommand({
  561. args: {
  562. direction: 2 /* CursorMove_.Direction.Up */,
  563. unit: 2 /* CursorMove_.Unit.WrappedLine */,
  564. select: true,
  565. value: 1
  566. },
  567. id: 'cursorUpSelect',
  568. precondition: undefined,
  569. kbOpts: {
  570. weight: CORE_WEIGHT,
  571. kbExpr: EditorContextKeys.textInputFocus,
  572. primary: 1024 /* KeyMod.Shift */ | 16 /* KeyCode.UpArrow */,
  573. secondary: [2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 16 /* KeyCode.UpArrow */],
  574. mac: { primary: 1024 /* KeyMod.Shift */ | 16 /* KeyCode.UpArrow */ },
  575. linux: { primary: 1024 /* KeyMod.Shift */ | 16 /* KeyCode.UpArrow */ }
  576. }
  577. }));
  578. CoreNavigationCommands.CursorPageUp = registerEditorCommand(new CursorMoveBasedCommand({
  579. args: {
  580. direction: 2 /* CursorMove_.Direction.Up */,
  581. unit: 2 /* CursorMove_.Unit.WrappedLine */,
  582. select: false,
  583. value: -1 /* Constants.PAGE_SIZE_MARKER */
  584. },
  585. id: 'cursorPageUp',
  586. precondition: undefined,
  587. kbOpts: {
  588. weight: CORE_WEIGHT,
  589. kbExpr: EditorContextKeys.textInputFocus,
  590. primary: 11 /* KeyCode.PageUp */
  591. }
  592. }));
  593. CoreNavigationCommands.CursorPageUpSelect = registerEditorCommand(new CursorMoveBasedCommand({
  594. args: {
  595. direction: 2 /* CursorMove_.Direction.Up */,
  596. unit: 2 /* CursorMove_.Unit.WrappedLine */,
  597. select: true,
  598. value: -1 /* Constants.PAGE_SIZE_MARKER */
  599. },
  600. id: 'cursorPageUpSelect',
  601. precondition: undefined,
  602. kbOpts: {
  603. weight: CORE_WEIGHT,
  604. kbExpr: EditorContextKeys.textInputFocus,
  605. primary: 1024 /* KeyMod.Shift */ | 11 /* KeyCode.PageUp */
  606. }
  607. }));
  608. CoreNavigationCommands.CursorDown = registerEditorCommand(new CursorMoveBasedCommand({
  609. args: {
  610. direction: 3 /* CursorMove_.Direction.Down */,
  611. unit: 2 /* CursorMove_.Unit.WrappedLine */,
  612. select: false,
  613. value: 1
  614. },
  615. id: 'cursorDown',
  616. precondition: undefined,
  617. kbOpts: {
  618. weight: CORE_WEIGHT,
  619. kbExpr: EditorContextKeys.textInputFocus,
  620. primary: 18 /* KeyCode.DownArrow */,
  621. mac: { primary: 18 /* KeyCode.DownArrow */, secondary: [256 /* KeyMod.WinCtrl */ | 44 /* KeyCode.KeyN */] }
  622. }
  623. }));
  624. CoreNavigationCommands.CursorDownSelect = registerEditorCommand(new CursorMoveBasedCommand({
  625. args: {
  626. direction: 3 /* CursorMove_.Direction.Down */,
  627. unit: 2 /* CursorMove_.Unit.WrappedLine */,
  628. select: true,
  629. value: 1
  630. },
  631. id: 'cursorDownSelect',
  632. precondition: undefined,
  633. kbOpts: {
  634. weight: CORE_WEIGHT,
  635. kbExpr: EditorContextKeys.textInputFocus,
  636. primary: 1024 /* KeyMod.Shift */ | 18 /* KeyCode.DownArrow */,
  637. secondary: [2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 18 /* KeyCode.DownArrow */],
  638. mac: { primary: 1024 /* KeyMod.Shift */ | 18 /* KeyCode.DownArrow */ },
  639. linux: { primary: 1024 /* KeyMod.Shift */ | 18 /* KeyCode.DownArrow */ }
  640. }
  641. }));
  642. CoreNavigationCommands.CursorPageDown = registerEditorCommand(new CursorMoveBasedCommand({
  643. args: {
  644. direction: 3 /* CursorMove_.Direction.Down */,
  645. unit: 2 /* CursorMove_.Unit.WrappedLine */,
  646. select: false,
  647. value: -1 /* Constants.PAGE_SIZE_MARKER */
  648. },
  649. id: 'cursorPageDown',
  650. precondition: undefined,
  651. kbOpts: {
  652. weight: CORE_WEIGHT,
  653. kbExpr: EditorContextKeys.textInputFocus,
  654. primary: 12 /* KeyCode.PageDown */
  655. }
  656. }));
  657. CoreNavigationCommands.CursorPageDownSelect = registerEditorCommand(new CursorMoveBasedCommand({
  658. args: {
  659. direction: 3 /* CursorMove_.Direction.Down */,
  660. unit: 2 /* CursorMove_.Unit.WrappedLine */,
  661. select: true,
  662. value: -1 /* Constants.PAGE_SIZE_MARKER */
  663. },
  664. id: 'cursorPageDownSelect',
  665. precondition: undefined,
  666. kbOpts: {
  667. weight: CORE_WEIGHT,
  668. kbExpr: EditorContextKeys.textInputFocus,
  669. primary: 1024 /* KeyMod.Shift */ | 12 /* KeyCode.PageDown */
  670. }
  671. }));
  672. CoreNavigationCommands.CreateCursor = registerEditorCommand(new class extends CoreEditorCommand {
  673. constructor() {
  674. super({
  675. id: 'createCursor',
  676. precondition: undefined
  677. });
  678. }
  679. runCoreEditorCommand(viewModel, args) {
  680. let newState;
  681. if (args.wholeLine) {
  682. newState = CursorMoveCommands.line(viewModel, viewModel.getPrimaryCursorState(), false, args.position, args.viewPosition);
  683. }
  684. else {
  685. newState = CursorMoveCommands.moveTo(viewModel, viewModel.getPrimaryCursorState(), false, args.position, args.viewPosition);
  686. }
  687. const states = viewModel.getCursorStates();
  688. // Check if we should remove a cursor (sort of like a toggle)
  689. if (states.length > 1) {
  690. const newModelPosition = (newState.modelState ? newState.modelState.position : null);
  691. const newViewPosition = (newState.viewState ? newState.viewState.position : null);
  692. for (let i = 0, len = states.length; i < len; i++) {
  693. const state = states[i];
  694. if (newModelPosition && !state.modelState.selection.containsPosition(newModelPosition)) {
  695. continue;
  696. }
  697. if (newViewPosition && !state.viewState.selection.containsPosition(newViewPosition)) {
  698. continue;
  699. }
  700. // => Remove the cursor
  701. states.splice(i, 1);
  702. viewModel.model.pushStackElement();
  703. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, states);
  704. return;
  705. }
  706. }
  707. // => Add the new cursor
  708. states.push(newState);
  709. viewModel.model.pushStackElement();
  710. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, states);
  711. }
  712. });
  713. CoreNavigationCommands.LastCursorMoveToSelect = registerEditorCommand(new class extends CoreEditorCommand {
  714. constructor() {
  715. super({
  716. id: '_lastCursorMoveToSelect',
  717. precondition: undefined
  718. });
  719. }
  720. runCoreEditorCommand(viewModel, args) {
  721. const lastAddedCursorIndex = viewModel.getLastAddedCursorIndex();
  722. const states = viewModel.getCursorStates();
  723. const newStates = states.slice(0);
  724. newStates[lastAddedCursorIndex] = CursorMoveCommands.moveTo(viewModel, states[lastAddedCursorIndex], true, args.position, args.viewPosition);
  725. viewModel.model.pushStackElement();
  726. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, newStates);
  727. }
  728. });
  729. class HomeCommand extends CoreEditorCommand {
  730. constructor(opts) {
  731. super(opts);
  732. this._inSelectionMode = opts.inSelectionMode;
  733. }
  734. runCoreEditorCommand(viewModel, args) {
  735. viewModel.model.pushStackElement();
  736. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, CursorMoveCommands.moveToBeginningOfLine(viewModel, viewModel.getCursorStates(), this._inSelectionMode));
  737. viewModel.revealPrimaryCursor(args.source, true);
  738. }
  739. }
  740. CoreNavigationCommands.CursorHome = registerEditorCommand(new HomeCommand({
  741. inSelectionMode: false,
  742. id: 'cursorHome',
  743. precondition: undefined,
  744. kbOpts: {
  745. weight: CORE_WEIGHT,
  746. kbExpr: EditorContextKeys.textInputFocus,
  747. primary: 14 /* KeyCode.Home */,
  748. mac: { primary: 14 /* KeyCode.Home */, secondary: [2048 /* KeyMod.CtrlCmd */ | 15 /* KeyCode.LeftArrow */] }
  749. }
  750. }));
  751. CoreNavigationCommands.CursorHomeSelect = registerEditorCommand(new HomeCommand({
  752. inSelectionMode: true,
  753. id: 'cursorHomeSelect',
  754. precondition: undefined,
  755. kbOpts: {
  756. weight: CORE_WEIGHT,
  757. kbExpr: EditorContextKeys.textInputFocus,
  758. primary: 1024 /* KeyMod.Shift */ | 14 /* KeyCode.Home */,
  759. mac: { primary: 1024 /* KeyMod.Shift */ | 14 /* KeyCode.Home */, secondary: [2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 15 /* KeyCode.LeftArrow */] }
  760. }
  761. }));
  762. class LineStartCommand extends CoreEditorCommand {
  763. constructor(opts) {
  764. super(opts);
  765. this._inSelectionMode = opts.inSelectionMode;
  766. }
  767. runCoreEditorCommand(viewModel, args) {
  768. viewModel.model.pushStackElement();
  769. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, this._exec(viewModel.getCursorStates()));
  770. viewModel.revealPrimaryCursor(args.source, true);
  771. }
  772. _exec(cursors) {
  773. const result = [];
  774. for (let i = 0, len = cursors.length; i < len; i++) {
  775. const cursor = cursors[i];
  776. const lineNumber = cursor.modelState.position.lineNumber;
  777. result[i] = CursorState.fromModelState(cursor.modelState.move(this._inSelectionMode, lineNumber, 1, 0));
  778. }
  779. return result;
  780. }
  781. }
  782. CoreNavigationCommands.CursorLineStart = registerEditorCommand(new LineStartCommand({
  783. inSelectionMode: false,
  784. id: 'cursorLineStart',
  785. precondition: undefined,
  786. kbOpts: {
  787. weight: CORE_WEIGHT,
  788. kbExpr: EditorContextKeys.textInputFocus,
  789. primary: 0,
  790. mac: { primary: 256 /* KeyMod.WinCtrl */ | 31 /* KeyCode.KeyA */ }
  791. }
  792. }));
  793. CoreNavigationCommands.CursorLineStartSelect = registerEditorCommand(new LineStartCommand({
  794. inSelectionMode: true,
  795. id: 'cursorLineStartSelect',
  796. precondition: undefined,
  797. kbOpts: {
  798. weight: CORE_WEIGHT,
  799. kbExpr: EditorContextKeys.textInputFocus,
  800. primary: 0,
  801. mac: { primary: 256 /* KeyMod.WinCtrl */ | 1024 /* KeyMod.Shift */ | 31 /* KeyCode.KeyA */ }
  802. }
  803. }));
  804. class EndCommand extends CoreEditorCommand {
  805. constructor(opts) {
  806. super(opts);
  807. this._inSelectionMode = opts.inSelectionMode;
  808. }
  809. runCoreEditorCommand(viewModel, args) {
  810. viewModel.model.pushStackElement();
  811. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, CursorMoveCommands.moveToEndOfLine(viewModel, viewModel.getCursorStates(), this._inSelectionMode, args.sticky || false));
  812. viewModel.revealPrimaryCursor(args.source, true);
  813. }
  814. }
  815. CoreNavigationCommands.CursorEnd = registerEditorCommand(new EndCommand({
  816. inSelectionMode: false,
  817. id: 'cursorEnd',
  818. precondition: undefined,
  819. kbOpts: {
  820. args: { sticky: false },
  821. weight: CORE_WEIGHT,
  822. kbExpr: EditorContextKeys.textInputFocus,
  823. primary: 13 /* KeyCode.End */,
  824. mac: { primary: 13 /* KeyCode.End */, secondary: [2048 /* KeyMod.CtrlCmd */ | 17 /* KeyCode.RightArrow */] }
  825. },
  826. description: {
  827. description: `Go to End`,
  828. args: [{
  829. name: 'args',
  830. schema: {
  831. type: 'object',
  832. properties: {
  833. 'sticky': {
  834. description: nls.localize('stickydesc', "Stick to the end even when going to longer lines"),
  835. type: 'boolean',
  836. default: false
  837. }
  838. }
  839. }
  840. }]
  841. }
  842. }));
  843. CoreNavigationCommands.CursorEndSelect = registerEditorCommand(new EndCommand({
  844. inSelectionMode: true,
  845. id: 'cursorEndSelect',
  846. precondition: undefined,
  847. kbOpts: {
  848. args: { sticky: false },
  849. weight: CORE_WEIGHT,
  850. kbExpr: EditorContextKeys.textInputFocus,
  851. primary: 1024 /* KeyMod.Shift */ | 13 /* KeyCode.End */,
  852. mac: { primary: 1024 /* KeyMod.Shift */ | 13 /* KeyCode.End */, secondary: [2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 17 /* KeyCode.RightArrow */] }
  853. },
  854. description: {
  855. description: `Select to End`,
  856. args: [{
  857. name: 'args',
  858. schema: {
  859. type: 'object',
  860. properties: {
  861. 'sticky': {
  862. description: nls.localize('stickydesc', "Stick to the end even when going to longer lines"),
  863. type: 'boolean',
  864. default: false
  865. }
  866. }
  867. }
  868. }]
  869. }
  870. }));
  871. class LineEndCommand extends CoreEditorCommand {
  872. constructor(opts) {
  873. super(opts);
  874. this._inSelectionMode = opts.inSelectionMode;
  875. }
  876. runCoreEditorCommand(viewModel, args) {
  877. viewModel.model.pushStackElement();
  878. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, this._exec(viewModel, viewModel.getCursorStates()));
  879. viewModel.revealPrimaryCursor(args.source, true);
  880. }
  881. _exec(viewModel, cursors) {
  882. const result = [];
  883. for (let i = 0, len = cursors.length; i < len; i++) {
  884. const cursor = cursors[i];
  885. const lineNumber = cursor.modelState.position.lineNumber;
  886. const maxColumn = viewModel.model.getLineMaxColumn(lineNumber);
  887. result[i] = CursorState.fromModelState(cursor.modelState.move(this._inSelectionMode, lineNumber, maxColumn, 0));
  888. }
  889. return result;
  890. }
  891. }
  892. CoreNavigationCommands.CursorLineEnd = registerEditorCommand(new LineEndCommand({
  893. inSelectionMode: false,
  894. id: 'cursorLineEnd',
  895. precondition: undefined,
  896. kbOpts: {
  897. weight: CORE_WEIGHT,
  898. kbExpr: EditorContextKeys.textInputFocus,
  899. primary: 0,
  900. mac: { primary: 256 /* KeyMod.WinCtrl */ | 35 /* KeyCode.KeyE */ }
  901. }
  902. }));
  903. CoreNavigationCommands.CursorLineEndSelect = registerEditorCommand(new LineEndCommand({
  904. inSelectionMode: true,
  905. id: 'cursorLineEndSelect',
  906. precondition: undefined,
  907. kbOpts: {
  908. weight: CORE_WEIGHT,
  909. kbExpr: EditorContextKeys.textInputFocus,
  910. primary: 0,
  911. mac: { primary: 256 /* KeyMod.WinCtrl */ | 1024 /* KeyMod.Shift */ | 35 /* KeyCode.KeyE */ }
  912. }
  913. }));
  914. class TopCommand extends CoreEditorCommand {
  915. constructor(opts) {
  916. super(opts);
  917. this._inSelectionMode = opts.inSelectionMode;
  918. }
  919. runCoreEditorCommand(viewModel, args) {
  920. viewModel.model.pushStackElement();
  921. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, CursorMoveCommands.moveToBeginningOfBuffer(viewModel, viewModel.getCursorStates(), this._inSelectionMode));
  922. viewModel.revealPrimaryCursor(args.source, true);
  923. }
  924. }
  925. CoreNavigationCommands.CursorTop = registerEditorCommand(new TopCommand({
  926. inSelectionMode: false,
  927. id: 'cursorTop',
  928. precondition: undefined,
  929. kbOpts: {
  930. weight: CORE_WEIGHT,
  931. kbExpr: EditorContextKeys.textInputFocus,
  932. primary: 2048 /* KeyMod.CtrlCmd */ | 14 /* KeyCode.Home */,
  933. mac: { primary: 2048 /* KeyMod.CtrlCmd */ | 16 /* KeyCode.UpArrow */ }
  934. }
  935. }));
  936. CoreNavigationCommands.CursorTopSelect = registerEditorCommand(new TopCommand({
  937. inSelectionMode: true,
  938. id: 'cursorTopSelect',
  939. precondition: undefined,
  940. kbOpts: {
  941. weight: CORE_WEIGHT,
  942. kbExpr: EditorContextKeys.textInputFocus,
  943. primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 14 /* KeyCode.Home */,
  944. mac: { primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 16 /* KeyCode.UpArrow */ }
  945. }
  946. }));
  947. class BottomCommand extends CoreEditorCommand {
  948. constructor(opts) {
  949. super(opts);
  950. this._inSelectionMode = opts.inSelectionMode;
  951. }
  952. runCoreEditorCommand(viewModel, args) {
  953. viewModel.model.pushStackElement();
  954. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, CursorMoveCommands.moveToEndOfBuffer(viewModel, viewModel.getCursorStates(), this._inSelectionMode));
  955. viewModel.revealPrimaryCursor(args.source, true);
  956. }
  957. }
  958. CoreNavigationCommands.CursorBottom = registerEditorCommand(new BottomCommand({
  959. inSelectionMode: false,
  960. id: 'cursorBottom',
  961. precondition: undefined,
  962. kbOpts: {
  963. weight: CORE_WEIGHT,
  964. kbExpr: EditorContextKeys.textInputFocus,
  965. primary: 2048 /* KeyMod.CtrlCmd */ | 13 /* KeyCode.End */,
  966. mac: { primary: 2048 /* KeyMod.CtrlCmd */ | 18 /* KeyCode.DownArrow */ }
  967. }
  968. }));
  969. CoreNavigationCommands.CursorBottomSelect = registerEditorCommand(new BottomCommand({
  970. inSelectionMode: true,
  971. id: 'cursorBottomSelect',
  972. precondition: undefined,
  973. kbOpts: {
  974. weight: CORE_WEIGHT,
  975. kbExpr: EditorContextKeys.textInputFocus,
  976. primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 13 /* KeyCode.End */,
  977. mac: { primary: 2048 /* KeyMod.CtrlCmd */ | 1024 /* KeyMod.Shift */ | 18 /* KeyCode.DownArrow */ }
  978. }
  979. }));
  980. class EditorScrollImpl extends CoreEditorCommand {
  981. constructor() {
  982. super({
  983. id: 'editorScroll',
  984. precondition: undefined,
  985. description: EditorScroll_.description
  986. });
  987. }
  988. runCoreEditorCommand(viewModel, args) {
  989. const parsed = EditorScroll_.parse(args);
  990. if (!parsed) {
  991. // illegal arguments
  992. return;
  993. }
  994. this._runEditorScroll(viewModel, args.source, parsed);
  995. }
  996. _runEditorScroll(viewModel, source, args) {
  997. const desiredScrollTop = this._computeDesiredScrollTop(viewModel, args);
  998. if (args.revealCursor) {
  999. // must ensure cursor is in new visible range
  1000. const desiredVisibleViewRange = viewModel.getCompletelyVisibleViewRangeAtScrollTop(desiredScrollTop);
  1001. viewModel.setCursorStates(source, 3 /* CursorChangeReason.Explicit */, [
  1002. CursorMoveCommands.findPositionInViewportIfOutside(viewModel, viewModel.getPrimaryCursorState(), desiredVisibleViewRange, args.select)
  1003. ]);
  1004. }
  1005. viewModel.viewLayout.setScrollPosition({ scrollTop: desiredScrollTop }, 0 /* ScrollType.Smooth */);
  1006. }
  1007. _computeDesiredScrollTop(viewModel, args) {
  1008. if (args.unit === 1 /* EditorScroll_.Unit.Line */) {
  1009. // scrolling by model lines
  1010. const visibleViewRange = viewModel.getCompletelyVisibleViewRange();
  1011. const visibleModelRange = viewModel.coordinatesConverter.convertViewRangeToModelRange(visibleViewRange);
  1012. let desiredTopModelLineNumber;
  1013. if (args.direction === 1 /* EditorScroll_.Direction.Up */) {
  1014. // must go x model lines up
  1015. desiredTopModelLineNumber = Math.max(1, visibleModelRange.startLineNumber - args.value);
  1016. }
  1017. else {
  1018. // must go x model lines down
  1019. desiredTopModelLineNumber = Math.min(viewModel.model.getLineCount(), visibleModelRange.startLineNumber + args.value);
  1020. }
  1021. const viewPosition = viewModel.coordinatesConverter.convertModelPositionToViewPosition(new Position(desiredTopModelLineNumber, 1));
  1022. return viewModel.viewLayout.getVerticalOffsetForLineNumber(viewPosition.lineNumber);
  1023. }
  1024. if (args.unit === 5 /* EditorScroll_.Unit.Editor */) {
  1025. let desiredTopModelLineNumber = 0;
  1026. if (args.direction === 2 /* EditorScroll_.Direction.Down */) {
  1027. desiredTopModelLineNumber = viewModel.model.getLineCount() - viewModel.cursorConfig.pageSize;
  1028. }
  1029. return viewModel.viewLayout.getVerticalOffsetForLineNumber(desiredTopModelLineNumber);
  1030. }
  1031. let noOfLines;
  1032. if (args.unit === 3 /* EditorScroll_.Unit.Page */) {
  1033. noOfLines = viewModel.cursorConfig.pageSize * args.value;
  1034. }
  1035. else if (args.unit === 4 /* EditorScroll_.Unit.HalfPage */) {
  1036. noOfLines = Math.round(viewModel.cursorConfig.pageSize / 2) * args.value;
  1037. }
  1038. else {
  1039. noOfLines = args.value;
  1040. }
  1041. const deltaLines = (args.direction === 1 /* EditorScroll_.Direction.Up */ ? -1 : 1) * noOfLines;
  1042. return viewModel.viewLayout.getCurrentScrollTop() + deltaLines * viewModel.cursorConfig.lineHeight;
  1043. }
  1044. }
  1045. CoreNavigationCommands.EditorScrollImpl = EditorScrollImpl;
  1046. CoreNavigationCommands.EditorScroll = registerEditorCommand(new EditorScrollImpl());
  1047. CoreNavigationCommands.ScrollLineUp = registerEditorCommand(new class extends CoreEditorCommand {
  1048. constructor() {
  1049. super({
  1050. id: 'scrollLineUp',
  1051. precondition: undefined,
  1052. kbOpts: {
  1053. weight: CORE_WEIGHT,
  1054. kbExpr: EditorContextKeys.textInputFocus,
  1055. primary: 2048 /* KeyMod.CtrlCmd */ | 16 /* KeyCode.UpArrow */,
  1056. mac: { primary: 256 /* KeyMod.WinCtrl */ | 11 /* KeyCode.PageUp */ }
  1057. }
  1058. });
  1059. }
  1060. runCoreEditorCommand(viewModel, args) {
  1061. CoreNavigationCommands.EditorScroll._runEditorScroll(viewModel, args.source, {
  1062. direction: 1 /* EditorScroll_.Direction.Up */,
  1063. unit: 2 /* EditorScroll_.Unit.WrappedLine */,
  1064. value: 1,
  1065. revealCursor: false,
  1066. select: false
  1067. });
  1068. }
  1069. });
  1070. CoreNavigationCommands.ScrollPageUp = registerEditorCommand(new class extends CoreEditorCommand {
  1071. constructor() {
  1072. super({
  1073. id: 'scrollPageUp',
  1074. precondition: undefined,
  1075. kbOpts: {
  1076. weight: CORE_WEIGHT,
  1077. kbExpr: EditorContextKeys.textInputFocus,
  1078. primary: 2048 /* KeyMod.CtrlCmd */ | 11 /* KeyCode.PageUp */,
  1079. win: { primary: 512 /* KeyMod.Alt */ | 11 /* KeyCode.PageUp */ },
  1080. linux: { primary: 512 /* KeyMod.Alt */ | 11 /* KeyCode.PageUp */ }
  1081. }
  1082. });
  1083. }
  1084. runCoreEditorCommand(viewModel, args) {
  1085. CoreNavigationCommands.EditorScroll._runEditorScroll(viewModel, args.source, {
  1086. direction: 1 /* EditorScroll_.Direction.Up */,
  1087. unit: 3 /* EditorScroll_.Unit.Page */,
  1088. value: 1,
  1089. revealCursor: false,
  1090. select: false
  1091. });
  1092. }
  1093. });
  1094. CoreNavigationCommands.ScrollEditorTop = registerEditorCommand(new class extends CoreEditorCommand {
  1095. constructor() {
  1096. super({
  1097. id: 'scrollEditorTop',
  1098. precondition: undefined,
  1099. kbOpts: {
  1100. weight: CORE_WEIGHT,
  1101. kbExpr: EditorContextKeys.textInputFocus,
  1102. }
  1103. });
  1104. }
  1105. runCoreEditorCommand(viewModel, args) {
  1106. CoreNavigationCommands.EditorScroll._runEditorScroll(viewModel, args.source, {
  1107. direction: 1 /* EditorScroll_.Direction.Up */,
  1108. unit: 5 /* EditorScroll_.Unit.Editor */,
  1109. value: 1,
  1110. revealCursor: false,
  1111. select: false
  1112. });
  1113. }
  1114. });
  1115. CoreNavigationCommands.ScrollLineDown = registerEditorCommand(new class extends CoreEditorCommand {
  1116. constructor() {
  1117. super({
  1118. id: 'scrollLineDown',
  1119. precondition: undefined,
  1120. kbOpts: {
  1121. weight: CORE_WEIGHT,
  1122. kbExpr: EditorContextKeys.textInputFocus,
  1123. primary: 2048 /* KeyMod.CtrlCmd */ | 18 /* KeyCode.DownArrow */,
  1124. mac: { primary: 256 /* KeyMod.WinCtrl */ | 12 /* KeyCode.PageDown */ }
  1125. }
  1126. });
  1127. }
  1128. runCoreEditorCommand(viewModel, args) {
  1129. CoreNavigationCommands.EditorScroll._runEditorScroll(viewModel, args.source, {
  1130. direction: 2 /* EditorScroll_.Direction.Down */,
  1131. unit: 2 /* EditorScroll_.Unit.WrappedLine */,
  1132. value: 1,
  1133. revealCursor: false,
  1134. select: false
  1135. });
  1136. }
  1137. });
  1138. CoreNavigationCommands.ScrollPageDown = registerEditorCommand(new class extends CoreEditorCommand {
  1139. constructor() {
  1140. super({
  1141. id: 'scrollPageDown',
  1142. precondition: undefined,
  1143. kbOpts: {
  1144. weight: CORE_WEIGHT,
  1145. kbExpr: EditorContextKeys.textInputFocus,
  1146. primary: 2048 /* KeyMod.CtrlCmd */ | 12 /* KeyCode.PageDown */,
  1147. win: { primary: 512 /* KeyMod.Alt */ | 12 /* KeyCode.PageDown */ },
  1148. linux: { primary: 512 /* KeyMod.Alt */ | 12 /* KeyCode.PageDown */ }
  1149. }
  1150. });
  1151. }
  1152. runCoreEditorCommand(viewModel, args) {
  1153. CoreNavigationCommands.EditorScroll._runEditorScroll(viewModel, args.source, {
  1154. direction: 2 /* EditorScroll_.Direction.Down */,
  1155. unit: 3 /* EditorScroll_.Unit.Page */,
  1156. value: 1,
  1157. revealCursor: false,
  1158. select: false
  1159. });
  1160. }
  1161. });
  1162. CoreNavigationCommands.ScrollEditorBottom = registerEditorCommand(new class extends CoreEditorCommand {
  1163. constructor() {
  1164. super({
  1165. id: 'scrollEditorBottom',
  1166. precondition: undefined,
  1167. kbOpts: {
  1168. weight: CORE_WEIGHT,
  1169. kbExpr: EditorContextKeys.textInputFocus,
  1170. }
  1171. });
  1172. }
  1173. runCoreEditorCommand(viewModel, args) {
  1174. CoreNavigationCommands.EditorScroll._runEditorScroll(viewModel, args.source, {
  1175. direction: 2 /* EditorScroll_.Direction.Down */,
  1176. unit: 5 /* EditorScroll_.Unit.Editor */,
  1177. value: 1,
  1178. revealCursor: false,
  1179. select: false
  1180. });
  1181. }
  1182. });
  1183. class WordCommand extends CoreEditorCommand {
  1184. constructor(opts) {
  1185. super(opts);
  1186. this._inSelectionMode = opts.inSelectionMode;
  1187. }
  1188. runCoreEditorCommand(viewModel, args) {
  1189. viewModel.model.pushStackElement();
  1190. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, [
  1191. CursorMoveCommands.word(viewModel, viewModel.getPrimaryCursorState(), this._inSelectionMode, args.position)
  1192. ]);
  1193. viewModel.revealPrimaryCursor(args.source, true);
  1194. }
  1195. }
  1196. CoreNavigationCommands.WordSelect = registerEditorCommand(new WordCommand({
  1197. inSelectionMode: false,
  1198. id: '_wordSelect',
  1199. precondition: undefined
  1200. }));
  1201. CoreNavigationCommands.WordSelectDrag = registerEditorCommand(new WordCommand({
  1202. inSelectionMode: true,
  1203. id: '_wordSelectDrag',
  1204. precondition: undefined
  1205. }));
  1206. CoreNavigationCommands.LastCursorWordSelect = registerEditorCommand(new class extends CoreEditorCommand {
  1207. constructor() {
  1208. super({
  1209. id: 'lastCursorWordSelect',
  1210. precondition: undefined
  1211. });
  1212. }
  1213. runCoreEditorCommand(viewModel, args) {
  1214. const lastAddedCursorIndex = viewModel.getLastAddedCursorIndex();
  1215. const states = viewModel.getCursorStates();
  1216. const newStates = states.slice(0);
  1217. const lastAddedState = states[lastAddedCursorIndex];
  1218. newStates[lastAddedCursorIndex] = CursorMoveCommands.word(viewModel, lastAddedState, lastAddedState.modelState.hasSelection(), args.position);
  1219. viewModel.model.pushStackElement();
  1220. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, newStates);
  1221. }
  1222. });
  1223. class LineCommand extends CoreEditorCommand {
  1224. constructor(opts) {
  1225. super(opts);
  1226. this._inSelectionMode = opts.inSelectionMode;
  1227. }
  1228. runCoreEditorCommand(viewModel, args) {
  1229. viewModel.model.pushStackElement();
  1230. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, [
  1231. CursorMoveCommands.line(viewModel, viewModel.getPrimaryCursorState(), this._inSelectionMode, args.position, args.viewPosition)
  1232. ]);
  1233. viewModel.revealPrimaryCursor(args.source, false);
  1234. }
  1235. }
  1236. CoreNavigationCommands.LineSelect = registerEditorCommand(new LineCommand({
  1237. inSelectionMode: false,
  1238. id: '_lineSelect',
  1239. precondition: undefined
  1240. }));
  1241. CoreNavigationCommands.LineSelectDrag = registerEditorCommand(new LineCommand({
  1242. inSelectionMode: true,
  1243. id: '_lineSelectDrag',
  1244. precondition: undefined
  1245. }));
  1246. class LastCursorLineCommand extends CoreEditorCommand {
  1247. constructor(opts) {
  1248. super(opts);
  1249. this._inSelectionMode = opts.inSelectionMode;
  1250. }
  1251. runCoreEditorCommand(viewModel, args) {
  1252. const lastAddedCursorIndex = viewModel.getLastAddedCursorIndex();
  1253. const states = viewModel.getCursorStates();
  1254. const newStates = states.slice(0);
  1255. newStates[lastAddedCursorIndex] = CursorMoveCommands.line(viewModel, states[lastAddedCursorIndex], this._inSelectionMode, args.position, args.viewPosition);
  1256. viewModel.model.pushStackElement();
  1257. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, newStates);
  1258. }
  1259. }
  1260. CoreNavigationCommands.LastCursorLineSelect = registerEditorCommand(new LastCursorLineCommand({
  1261. inSelectionMode: false,
  1262. id: 'lastCursorLineSelect',
  1263. precondition: undefined
  1264. }));
  1265. CoreNavigationCommands.LastCursorLineSelectDrag = registerEditorCommand(new LastCursorLineCommand({
  1266. inSelectionMode: true,
  1267. id: 'lastCursorLineSelectDrag',
  1268. precondition: undefined
  1269. }));
  1270. CoreNavigationCommands.CancelSelection = registerEditorCommand(new class extends CoreEditorCommand {
  1271. constructor() {
  1272. super({
  1273. id: 'cancelSelection',
  1274. precondition: EditorContextKeys.hasNonEmptySelection,
  1275. kbOpts: {
  1276. weight: CORE_WEIGHT,
  1277. kbExpr: EditorContextKeys.textInputFocus,
  1278. primary: 9 /* KeyCode.Escape */,
  1279. secondary: [1024 /* KeyMod.Shift */ | 9 /* KeyCode.Escape */]
  1280. }
  1281. });
  1282. }
  1283. runCoreEditorCommand(viewModel, args) {
  1284. viewModel.model.pushStackElement();
  1285. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, [
  1286. CursorMoveCommands.cancelSelection(viewModel, viewModel.getPrimaryCursorState())
  1287. ]);
  1288. viewModel.revealPrimaryCursor(args.source, true);
  1289. }
  1290. });
  1291. CoreNavigationCommands.RemoveSecondaryCursors = registerEditorCommand(new class extends CoreEditorCommand {
  1292. constructor() {
  1293. super({
  1294. id: 'removeSecondaryCursors',
  1295. precondition: EditorContextKeys.hasMultipleSelections,
  1296. kbOpts: {
  1297. weight: CORE_WEIGHT + 1,
  1298. kbExpr: EditorContextKeys.textInputFocus,
  1299. primary: 9 /* KeyCode.Escape */,
  1300. secondary: [1024 /* KeyMod.Shift */ | 9 /* KeyCode.Escape */]
  1301. }
  1302. });
  1303. }
  1304. runCoreEditorCommand(viewModel, args) {
  1305. viewModel.model.pushStackElement();
  1306. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, [
  1307. viewModel.getPrimaryCursorState()
  1308. ]);
  1309. viewModel.revealPrimaryCursor(args.source, true);
  1310. status(nls.localize('removedCursor', "Removed secondary cursors"));
  1311. }
  1312. });
  1313. CoreNavigationCommands.RevealLine = registerEditorCommand(new class extends CoreEditorCommand {
  1314. constructor() {
  1315. super({
  1316. id: 'revealLine',
  1317. precondition: undefined,
  1318. description: RevealLine_.description
  1319. });
  1320. }
  1321. runCoreEditorCommand(viewModel, args) {
  1322. const revealLineArg = args;
  1323. const lineNumberArg = revealLineArg.lineNumber || 0;
  1324. let lineNumber = typeof lineNumberArg === 'number' ? (lineNumberArg + 1) : (parseInt(lineNumberArg) + 1);
  1325. if (lineNumber < 1) {
  1326. lineNumber = 1;
  1327. }
  1328. const lineCount = viewModel.model.getLineCount();
  1329. if (lineNumber > lineCount) {
  1330. lineNumber = lineCount;
  1331. }
  1332. const range = new Range(lineNumber, 1, lineNumber, viewModel.model.getLineMaxColumn(lineNumber));
  1333. let revealAt = 0 /* VerticalRevealType.Simple */;
  1334. if (revealLineArg.at) {
  1335. switch (revealLineArg.at) {
  1336. case RevealLine_.RawAtArgument.Top:
  1337. revealAt = 3 /* VerticalRevealType.Top */;
  1338. break;
  1339. case RevealLine_.RawAtArgument.Center:
  1340. revealAt = 1 /* VerticalRevealType.Center */;
  1341. break;
  1342. case RevealLine_.RawAtArgument.Bottom:
  1343. revealAt = 4 /* VerticalRevealType.Bottom */;
  1344. break;
  1345. default:
  1346. break;
  1347. }
  1348. }
  1349. const viewRange = viewModel.coordinatesConverter.convertModelRangeToViewRange(range);
  1350. viewModel.revealRange(args.source, false, viewRange, revealAt, 0 /* ScrollType.Smooth */);
  1351. }
  1352. });
  1353. CoreNavigationCommands.SelectAll = new class extends EditorOrNativeTextInputCommand {
  1354. constructor() {
  1355. super(SelectAllCommand);
  1356. }
  1357. runDOMCommand() {
  1358. if (isFirefox) {
  1359. document.activeElement.focus();
  1360. document.activeElement.select();
  1361. }
  1362. document.execCommand('selectAll');
  1363. }
  1364. runEditorCommand(accessor, editor, args) {
  1365. const viewModel = editor._getViewModel();
  1366. if (!viewModel) {
  1367. // the editor has no view => has no cursors
  1368. return;
  1369. }
  1370. this.runCoreEditorCommand(viewModel, args);
  1371. }
  1372. runCoreEditorCommand(viewModel, args) {
  1373. viewModel.model.pushStackElement();
  1374. viewModel.setCursorStates('keyboard', 3 /* CursorChangeReason.Explicit */, [
  1375. CursorMoveCommands.selectAll(viewModel, viewModel.getPrimaryCursorState())
  1376. ]);
  1377. }
  1378. }();
  1379. CoreNavigationCommands.SetSelection = registerEditorCommand(new class extends CoreEditorCommand {
  1380. constructor() {
  1381. super({
  1382. id: 'setSelection',
  1383. precondition: undefined
  1384. });
  1385. }
  1386. runCoreEditorCommand(viewModel, args) {
  1387. viewModel.model.pushStackElement();
  1388. viewModel.setCursorStates(args.source, 3 /* CursorChangeReason.Explicit */, [
  1389. CursorState.fromModelSelection(args.selection)
  1390. ]);
  1391. }
  1392. });
  1393. })(CoreNavigationCommands || (CoreNavigationCommands = {}));
  1394. const columnSelectionCondition = ContextKeyExpr.and(EditorContextKeys.textInputFocus, EditorContextKeys.columnSelection);
  1395. function registerColumnSelection(id, keybinding) {
  1396. KeybindingsRegistry.registerKeybindingRule({
  1397. id: id,
  1398. primary: keybinding,
  1399. when: columnSelectionCondition,
  1400. weight: CORE_WEIGHT + 1
  1401. });
  1402. }
  1403. registerColumnSelection(CoreNavigationCommands.CursorColumnSelectLeft.id, 1024 /* KeyMod.Shift */ | 15 /* KeyCode.LeftArrow */);
  1404. registerColumnSelection(CoreNavigationCommands.CursorColumnSelectRight.id, 1024 /* KeyMod.Shift */ | 17 /* KeyCode.RightArrow */);
  1405. registerColumnSelection(CoreNavigationCommands.CursorColumnSelectUp.id, 1024 /* KeyMod.Shift */ | 16 /* KeyCode.UpArrow */);
  1406. registerColumnSelection(CoreNavigationCommands.CursorColumnSelectPageUp.id, 1024 /* KeyMod.Shift */ | 11 /* KeyCode.PageUp */);
  1407. registerColumnSelection(CoreNavigationCommands.CursorColumnSelectDown.id, 1024 /* KeyMod.Shift */ | 18 /* KeyCode.DownArrow */);
  1408. registerColumnSelection(CoreNavigationCommands.CursorColumnSelectPageDown.id, 1024 /* KeyMod.Shift */ | 12 /* KeyCode.PageDown */);
  1409. function registerCommand(command) {
  1410. command.register();
  1411. return command;
  1412. }
  1413. export var CoreEditingCommands;
  1414. (function (CoreEditingCommands) {
  1415. class CoreEditingCommand extends EditorCommand {
  1416. runEditorCommand(accessor, editor, args) {
  1417. const viewModel = editor._getViewModel();
  1418. if (!viewModel) {
  1419. // the editor has no view => has no cursors
  1420. return;
  1421. }
  1422. this.runCoreEditingCommand(editor, viewModel, args || {});
  1423. }
  1424. }
  1425. CoreEditingCommands.CoreEditingCommand = CoreEditingCommand;
  1426. CoreEditingCommands.LineBreakInsert = registerEditorCommand(new class extends CoreEditingCommand {
  1427. constructor() {
  1428. super({
  1429. id: 'lineBreakInsert',
  1430. precondition: EditorContextKeys.writable,
  1431. kbOpts: {
  1432. weight: CORE_WEIGHT,
  1433. kbExpr: EditorContextKeys.textInputFocus,
  1434. primary: 0,
  1435. mac: { primary: 256 /* KeyMod.WinCtrl */ | 45 /* KeyCode.KeyO */ }
  1436. }
  1437. });
  1438. }
  1439. runCoreEditingCommand(editor, viewModel, args) {
  1440. editor.pushUndoStop();
  1441. editor.executeCommands(this.id, TypeOperations.lineBreakInsert(viewModel.cursorConfig, viewModel.model, viewModel.getCursorStates().map(s => s.modelState.selection)));
  1442. }
  1443. });
  1444. CoreEditingCommands.Outdent = registerEditorCommand(new class extends CoreEditingCommand {
  1445. constructor() {
  1446. super({
  1447. id: 'outdent',
  1448. precondition: EditorContextKeys.writable,
  1449. kbOpts: {
  1450. weight: CORE_WEIGHT,
  1451. kbExpr: ContextKeyExpr.and(EditorContextKeys.editorTextFocus, EditorContextKeys.tabDoesNotMoveFocus),
  1452. primary: 1024 /* KeyMod.Shift */ | 2 /* KeyCode.Tab */
  1453. }
  1454. });
  1455. }
  1456. runCoreEditingCommand(editor, viewModel, args) {
  1457. editor.pushUndoStop();
  1458. editor.executeCommands(this.id, TypeOperations.outdent(viewModel.cursorConfig, viewModel.model, viewModel.getCursorStates().map(s => s.modelState.selection)));
  1459. editor.pushUndoStop();
  1460. }
  1461. });
  1462. CoreEditingCommands.Tab = registerEditorCommand(new class extends CoreEditingCommand {
  1463. constructor() {
  1464. super({
  1465. id: 'tab',
  1466. precondition: EditorContextKeys.writable,
  1467. kbOpts: {
  1468. weight: CORE_WEIGHT,
  1469. kbExpr: ContextKeyExpr.and(EditorContextKeys.editorTextFocus, EditorContextKeys.tabDoesNotMoveFocus),
  1470. primary: 2 /* KeyCode.Tab */
  1471. }
  1472. });
  1473. }
  1474. runCoreEditingCommand(editor, viewModel, args) {
  1475. editor.pushUndoStop();
  1476. editor.executeCommands(this.id, TypeOperations.tab(viewModel.cursorConfig, viewModel.model, viewModel.getCursorStates().map(s => s.modelState.selection)));
  1477. editor.pushUndoStop();
  1478. }
  1479. });
  1480. CoreEditingCommands.DeleteLeft = registerEditorCommand(new class extends CoreEditingCommand {
  1481. constructor() {
  1482. super({
  1483. id: 'deleteLeft',
  1484. precondition: undefined,
  1485. kbOpts: {
  1486. weight: CORE_WEIGHT,
  1487. kbExpr: EditorContextKeys.textInputFocus,
  1488. primary: 1 /* KeyCode.Backspace */,
  1489. secondary: [1024 /* KeyMod.Shift */ | 1 /* KeyCode.Backspace */],
  1490. mac: { primary: 1 /* KeyCode.Backspace */, secondary: [1024 /* KeyMod.Shift */ | 1 /* KeyCode.Backspace */, 256 /* KeyMod.WinCtrl */ | 38 /* KeyCode.KeyH */, 256 /* KeyMod.WinCtrl */ | 1 /* KeyCode.Backspace */] }
  1491. }
  1492. });
  1493. }
  1494. runCoreEditingCommand(editor, viewModel, args) {
  1495. const [shouldPushStackElementBefore, commands] = DeleteOperations.deleteLeft(viewModel.getPrevEditOperationType(), viewModel.cursorConfig, viewModel.model, viewModel.getCursorStates().map(s => s.modelState.selection), viewModel.getCursorAutoClosedCharacters());
  1496. if (shouldPushStackElementBefore) {
  1497. editor.pushUndoStop();
  1498. }
  1499. editor.executeCommands(this.id, commands);
  1500. viewModel.setPrevEditOperationType(2 /* EditOperationType.DeletingLeft */);
  1501. }
  1502. });
  1503. CoreEditingCommands.DeleteRight = registerEditorCommand(new class extends CoreEditingCommand {
  1504. constructor() {
  1505. super({
  1506. id: 'deleteRight',
  1507. precondition: undefined,
  1508. kbOpts: {
  1509. weight: CORE_WEIGHT,
  1510. kbExpr: EditorContextKeys.textInputFocus,
  1511. primary: 20 /* KeyCode.Delete */,
  1512. mac: { primary: 20 /* KeyCode.Delete */, secondary: [256 /* KeyMod.WinCtrl */ | 34 /* KeyCode.KeyD */, 256 /* KeyMod.WinCtrl */ | 20 /* KeyCode.Delete */] }
  1513. }
  1514. });
  1515. }
  1516. runCoreEditingCommand(editor, viewModel, args) {
  1517. const [shouldPushStackElementBefore, commands] = DeleteOperations.deleteRight(viewModel.getPrevEditOperationType(), viewModel.cursorConfig, viewModel.model, viewModel.getCursorStates().map(s => s.modelState.selection));
  1518. if (shouldPushStackElementBefore) {
  1519. editor.pushUndoStop();
  1520. }
  1521. editor.executeCommands(this.id, commands);
  1522. viewModel.setPrevEditOperationType(3 /* EditOperationType.DeletingRight */);
  1523. }
  1524. });
  1525. CoreEditingCommands.Undo = new class extends EditorOrNativeTextInputCommand {
  1526. constructor() {
  1527. super(UndoCommand);
  1528. }
  1529. runDOMCommand() {
  1530. document.execCommand('undo');
  1531. }
  1532. runEditorCommand(accessor, editor, args) {
  1533. if (!editor.hasModel() || editor.getOption(83 /* EditorOption.readOnly */) === true) {
  1534. return;
  1535. }
  1536. return editor.getModel().undo();
  1537. }
  1538. }();
  1539. CoreEditingCommands.Redo = new class extends EditorOrNativeTextInputCommand {
  1540. constructor() {
  1541. super(RedoCommand);
  1542. }
  1543. runDOMCommand() {
  1544. document.execCommand('redo');
  1545. }
  1546. runEditorCommand(accessor, editor, args) {
  1547. if (!editor.hasModel() || editor.getOption(83 /* EditorOption.readOnly */) === true) {
  1548. return;
  1549. }
  1550. return editor.getModel().redo();
  1551. }
  1552. }();
  1553. })(CoreEditingCommands || (CoreEditingCommands = {}));
  1554. /**
  1555. * A command that will invoke a command on the focused editor.
  1556. */
  1557. class EditorHandlerCommand extends Command {
  1558. constructor(id, handlerId, description) {
  1559. super({
  1560. id: id,
  1561. precondition: undefined,
  1562. description: description
  1563. });
  1564. this._handlerId = handlerId;
  1565. }
  1566. runCommand(accessor, args) {
  1567. const editor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
  1568. if (!editor) {
  1569. return;
  1570. }
  1571. editor.trigger('keyboard', this._handlerId, args);
  1572. }
  1573. }
  1574. function registerOverwritableCommand(handlerId, description) {
  1575. registerCommand(new EditorHandlerCommand('default:' + handlerId, handlerId));
  1576. registerCommand(new EditorHandlerCommand(handlerId, handlerId, description));
  1577. }
  1578. registerOverwritableCommand("type" /* Handler.Type */, {
  1579. description: `Type`,
  1580. args: [{
  1581. name: 'args',
  1582. schema: {
  1583. 'type': 'object',
  1584. 'required': ['text'],
  1585. 'properties': {
  1586. 'text': {
  1587. 'type': 'string'
  1588. }
  1589. },
  1590. }
  1591. }]
  1592. });
  1593. registerOverwritableCommand("replacePreviousChar" /* Handler.ReplacePreviousChar */);
  1594. registerOverwritableCommand("compositionType" /* Handler.CompositionType */);
  1595. registerOverwritableCommand("compositionStart" /* Handler.CompositionStart */);
  1596. registerOverwritableCommand("compositionEnd" /* Handler.CompositionEnd */);
  1597. registerOverwritableCommand("paste" /* Handler.Paste */);
  1598. registerOverwritableCommand("cut" /* Handler.Cut */);