e5e447992253828c215386c2e5b87e156495975907d632afab634a8a4a7fa9496fee0f0e21f5685499f72ddf798b40b90381bed61ab0345619d9180d0bf353 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  9. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10. };
  11. var __param = (this && this.__param) || function (paramIndex, decorator) {
  12. return function (target, key) { decorator(target, key, paramIndex); }
  13. };
  14. import { IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
  15. let WordContextKey = class WordContextKey {
  16. constructor(_editor, contextKeyService) {
  17. this._editor = _editor;
  18. this._enabled = false;
  19. this._ckAtEnd = WordContextKey.AtEnd.bindTo(contextKeyService);
  20. this._configListener = this._editor.onDidChangeConfiguration(e => e.hasChanged(113 /* EditorOption.tabCompletion */) && this._update());
  21. this._update();
  22. }
  23. dispose() {
  24. var _a;
  25. this._configListener.dispose();
  26. (_a = this._selectionListener) === null || _a === void 0 ? void 0 : _a.dispose();
  27. this._ckAtEnd.reset();
  28. }
  29. _update() {
  30. // only update this when tab completions are enabled
  31. const enabled = this._editor.getOption(113 /* EditorOption.tabCompletion */) === 'on';
  32. if (this._enabled === enabled) {
  33. return;
  34. }
  35. this._enabled = enabled;
  36. if (this._enabled) {
  37. const checkForWordEnd = () => {
  38. if (!this._editor.hasModel()) {
  39. this._ckAtEnd.set(false);
  40. return;
  41. }
  42. const model = this._editor.getModel();
  43. const selection = this._editor.getSelection();
  44. const word = model.getWordAtPosition(selection.getStartPosition());
  45. if (!word) {
  46. this._ckAtEnd.set(false);
  47. return;
  48. }
  49. this._ckAtEnd.set(word.endColumn === selection.getStartPosition().column);
  50. };
  51. this._selectionListener = this._editor.onDidChangeCursorSelection(checkForWordEnd);
  52. checkForWordEnd();
  53. }
  54. else if (this._selectionListener) {
  55. this._ckAtEnd.reset();
  56. this._selectionListener.dispose();
  57. this._selectionListener = undefined;
  58. }
  59. }
  60. };
  61. WordContextKey.AtEnd = new RawContextKey('atEndOfWord', false);
  62. WordContextKey = __decorate([
  63. __param(1, IContextKeyService)
  64. ], WordContextKey);
  65. export { WordContextKey };