@opensumi/ide-editor 2.12.1-next-079c1930

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/README.md +565 -0
  2. package/lib/browser/breadcrumb/default.d.ts +28 -0
  3. package/lib/browser/breadcrumb/default.d.ts.map +1 -0
  4. package/lib/browser/breadcrumb/default.js +283 -0
  5. package/lib/browser/breadcrumb/default.js.map +1 -0
  6. package/lib/browser/breadcrumb/document-symbol.d.ts +36 -0
  7. package/lib/browser/breadcrumb/document-symbol.d.ts.map +1 -0
  8. package/lib/browser/breadcrumb/document-symbol.js +161 -0
  9. package/lib/browser/breadcrumb/document-symbol.js.map +1 -0
  10. package/lib/browser/breadcrumb/index.d.ts +20 -0
  11. package/lib/browser/breadcrumb/index.d.ts.map +1 -0
  12. package/lib/browser/breadcrumb/index.js +90 -0
  13. package/lib/browser/breadcrumb/index.js.map +1 -0
  14. package/lib/browser/component/scroll/scroll.d.ts +66 -0
  15. package/lib/browser/component/scroll/scroll.d.ts.map +1 -0
  16. package/lib/browser/component/scroll/scroll.js +263 -0
  17. package/lib/browser/component/scroll/scroll.js.map +1 -0
  18. package/lib/browser/component/scroll/scroll.module.less +83 -0
  19. package/lib/browser/component.d.ts +23 -0
  20. package/lib/browser/component.d.ts.map +1 -0
  21. package/lib/browser/component.js +165 -0
  22. package/lib/browser/component.js.map +1 -0
  23. package/lib/browser/decoration-applier.d.ts +25 -0
  24. package/lib/browser/decoration-applier.d.ts.map +1 -0
  25. package/lib/browser/decoration-applier.js +224 -0
  26. package/lib/browser/decoration-applier.js.map +1 -0
  27. package/lib/browser/diff/compare.d.ts +14 -0
  28. package/lib/browser/diff/compare.d.ts.map +1 -0
  29. package/lib/browser/diff/compare.js +94 -0
  30. package/lib/browser/diff/compare.js.map +1 -0
  31. package/lib/browser/diff/index.d.ts +19 -0
  32. package/lib/browser/diff/index.d.ts.map +1 -0
  33. package/lib/browser/diff/index.js +92 -0
  34. package/lib/browser/diff/index.js.map +1 -0
  35. package/lib/browser/doc-cache/empty-doc-cache.d.ts +12 -0
  36. package/lib/browser/doc-cache/empty-doc-cache.d.ts.map +1 -0
  37. package/lib/browser/doc-cache/empty-doc-cache.js +27 -0
  38. package/lib/browser/doc-cache/empty-doc-cache.js.map +1 -0
  39. package/lib/browser/doc-cache/index.d.ts +3 -0
  40. package/lib/browser/doc-cache/index.d.ts.map +1 -0
  41. package/lib/browser/doc-cache/index.js +6 -0
  42. package/lib/browser/doc-cache/index.js.map +1 -0
  43. package/lib/browser/doc-cache/local-storage-cache.d.ts +32 -0
  44. package/lib/browser/doc-cache/local-storage-cache.d.ts.map +1 -0
  45. package/lib/browser/doc-cache/local-storage-cache.js +69 -0
  46. package/lib/browser/doc-cache/local-storage-cache.js.map +1 -0
  47. package/lib/browser/doc-model/editor-document-error.d.ts +7 -0
  48. package/lib/browser/doc-model/editor-document-error.d.ts.map +1 -0
  49. package/lib/browser/doc-model/editor-document-error.js +15 -0
  50. package/lib/browser/doc-model/editor-document-error.js.map +1 -0
  51. package/lib/browser/doc-model/editor-document-model-service.d.ts +40 -0
  52. package/lib/browser/doc-model/editor-document-model-service.d.ts.map +1 -0
  53. package/lib/browser/doc-model/editor-document-model-service.js +276 -0
  54. package/lib/browser/doc-model/editor-document-model-service.js.map +1 -0
  55. package/lib/browser/doc-model/editor-document-model.d.ts +85 -0
  56. package/lib/browser/doc-model/editor-document-model.d.ts.map +1 -0
  57. package/lib/browser/doc-model/editor-document-model.js +463 -0
  58. package/lib/browser/doc-model/editor-document-model.js.map +1 -0
  59. package/lib/browser/doc-model/editor-document-registry.d.ts +15 -0
  60. package/lib/browser/doc-model/editor-document-registry.d.ts.map +1 -0
  61. package/lib/browser/doc-model/editor-document-registry.js +110 -0
  62. package/lib/browser/doc-model/editor-document-registry.js.map +1 -0
  63. package/lib/browser/doc-model/editor-is-fn.d.ts +4 -0
  64. package/lib/browser/doc-model/editor-is-fn.d.ts.map +1 -0
  65. package/lib/browser/doc-model/editor-is-fn.js +12 -0
  66. package/lib/browser/doc-model/editor-is-fn.js.map +1 -0
  67. package/lib/browser/doc-model/main.d.ts +5 -0
  68. package/lib/browser/doc-model/main.d.ts.map +1 -0
  69. package/lib/browser/doc-model/main.js +8 -0
  70. package/lib/browser/doc-model/main.js.map +1 -0
  71. package/lib/browser/doc-model/override.d.ts +12 -0
  72. package/lib/browser/doc-model/override.d.ts.map +1 -0
  73. package/lib/browser/doc-model/override.js +46 -0
  74. package/lib/browser/doc-model/override.js.map +1 -0
  75. package/lib/browser/doc-model/save-task.d.ts +19 -0
  76. package/lib/browser/doc-model/save-task.d.ts.map +1 -0
  77. package/lib/browser/doc-model/save-task.js +34 -0
  78. package/lib/browser/doc-model/save-task.js.map +1 -0
  79. package/lib/browser/doc-model/saveParticipants.d.ts +21 -0
  80. package/lib/browser/doc-model/saveParticipants.d.ts.map +1 -0
  81. package/lib/browser/doc-model/saveParticipants.js +133 -0
  82. package/lib/browser/doc-model/saveParticipants.js.map +1 -0
  83. package/lib/browser/doc-model/types.d.ts +253 -0
  84. package/lib/browser/doc-model/types.d.ts.map +1 -0
  85. package/lib/browser/doc-model/types.js +31 -0
  86. package/lib/browser/doc-model/types.js.map +1 -0
  87. package/lib/browser/editor-collection.service.d.ts +137 -0
  88. package/lib/browser/editor-collection.service.d.ts.map +1 -0
  89. package/lib/browser/editor-collection.service.js +607 -0
  90. package/lib/browser/editor-collection.service.js.map +1 -0
  91. package/lib/browser/editor-opener.d.ts +10 -0
  92. package/lib/browser/editor-opener.d.ts.map +1 -0
  93. package/lib/browser/editor-opener.js +51 -0
  94. package/lib/browser/editor-opener.js.map +1 -0
  95. package/lib/browser/editor.contribution.d.ts +54 -0
  96. package/lib/browser/editor.contribution.d.ts.map +1 -0
  97. package/lib/browser/editor.contribution.js +1059 -0
  98. package/lib/browser/editor.contribution.js.map +1 -0
  99. package/lib/browser/editor.decoration.service.d.ts +28 -0
  100. package/lib/browser/editor.decoration.service.d.ts.map +1 -0
  101. package/lib/browser/editor.decoration.service.js +216 -0
  102. package/lib/browser/editor.decoration.service.js.map +1 -0
  103. package/lib/browser/editor.less +4 -0
  104. package/lib/browser/editor.module.less +493 -0
  105. package/lib/browser/editor.override.d.ts +24 -0
  106. package/lib/browser/editor.override.d.ts.map +1 -0
  107. package/lib/browser/editor.override.js +85 -0
  108. package/lib/browser/editor.override.js.map +1 -0
  109. package/lib/browser/editor.status-bar.service.d.ts +12 -0
  110. package/lib/browser/editor.status-bar.service.d.ts.map +1 -0
  111. package/lib/browser/editor.status-bar.service.js +114 -0
  112. package/lib/browser/editor.status-bar.service.js.map +1 -0
  113. package/lib/browser/editor.view.d.ts +33 -0
  114. package/lib/browser/editor.view.d.ts.map +1 -0
  115. package/lib/browser/editor.view.js +411 -0
  116. package/lib/browser/editor.view.js.map +1 -0
  117. package/lib/browser/error.d.ts +14 -0
  118. package/lib/browser/error.d.ts.map +1 -0
  119. package/lib/browser/error.js +19 -0
  120. package/lib/browser/error.js.map +1 -0
  121. package/lib/browser/feature.d.ts +14 -0
  122. package/lib/browser/feature.d.ts.map +1 -0
  123. package/lib/browser/feature.js +56 -0
  124. package/lib/browser/feature.js.map +1 -0
  125. package/lib/browser/format/formatterSelect.d.ts +11 -0
  126. package/lib/browser/format/formatterSelect.d.ts.map +1 -0
  127. package/lib/browser/format/formatterSelect.js +61 -0
  128. package/lib/browser/format/formatterSelect.js.map +1 -0
  129. package/lib/browser/fs-resource/file-tree-set.d.ts +31 -0
  130. package/lib/browser/fs-resource/file-tree-set.d.ts.map +1 -0
  131. package/lib/browser/fs-resource/file-tree-set.js +123 -0
  132. package/lib/browser/fs-resource/file-tree-set.js.map +1 -0
  133. package/lib/browser/fs-resource/fs-editor-doc.d.ts +47 -0
  134. package/lib/browser/fs-resource/fs-editor-doc.d.ts.map +1 -0
  135. package/lib/browser/fs-resource/fs-editor-doc.js +148 -0
  136. package/lib/browser/fs-resource/fs-editor-doc.js.map +1 -0
  137. package/lib/browser/fs-resource/fs-resource.d.ts +25 -0
  138. package/lib/browser/fs-resource/fs-resource.d.ts.map +1 -0
  139. package/lib/browser/fs-resource/fs-resource.js +211 -0
  140. package/lib/browser/fs-resource/fs-resource.js.map +1 -0
  141. package/lib/browser/fs-resource/index.d.ts +12 -0
  142. package/lib/browser/fs-resource/index.d.ts.map +1 -0
  143. package/lib/browser/fs-resource/index.js +30 -0
  144. package/lib/browser/fs-resource/index.js.map +1 -0
  145. package/lib/browser/grid/grid.service.d.ts +44 -0
  146. package/lib/browser/grid/grid.service.d.ts.map +1 -0
  147. package/lib/browser/grid/grid.service.js +255 -0
  148. package/lib/browser/grid/grid.service.js.map +1 -0
  149. package/lib/browser/history/index.d.ts +31 -0
  150. package/lib/browser/history/index.d.ts.map +1 -0
  151. package/lib/browser/history/index.js +164 -0
  152. package/lib/browser/history/index.js.map +1 -0
  153. package/lib/browser/index.d.ts +33 -0
  154. package/lib/browser/index.d.ts.map +1 -0
  155. package/lib/browser/index.js +212 -0
  156. package/lib/browser/index.js.map +1 -0
  157. package/lib/browser/language/diagnostic-collection.d.ts +28 -0
  158. package/lib/browser/language/diagnostic-collection.d.ts.map +1 -0
  159. package/lib/browser/language/diagnostic-collection.js +72 -0
  160. package/lib/browser/language/diagnostic-collection.js.map +1 -0
  161. package/lib/browser/language/language.service.d.ts +19 -0
  162. package/lib/browser/language/language.service.d.ts.map +1 -0
  163. package/lib/browser/language/language.service.js +146 -0
  164. package/lib/browser/language/language.service.js.map +1 -0
  165. package/lib/browser/language/workspace-symbol-quickopen.d.ts +43 -0
  166. package/lib/browser/language/workspace-symbol-quickopen.d.ts.map +1 -0
  167. package/lib/browser/language/workspace-symbol-quickopen.js +231 -0
  168. package/lib/browser/language/workspace-symbol-quickopen.js.map +1 -0
  169. package/lib/browser/menu/editor.context.d.ts +20 -0
  170. package/lib/browser/menu/editor.context.d.ts.map +1 -0
  171. package/lib/browser/menu/editor.context.js +139 -0
  172. package/lib/browser/menu/editor.context.js.map +1 -0
  173. package/lib/browser/menu/editor.menu.d.ts +13 -0
  174. package/lib/browser/menu/editor.menu.d.ts.map +1 -0
  175. package/lib/browser/menu/editor.menu.js +48 -0
  176. package/lib/browser/menu/editor.menu.js.map +1 -0
  177. package/lib/browser/menu/title-context.menu.d.ts +13 -0
  178. package/lib/browser/menu/title-context.menu.d.ts.map +1 -0
  179. package/lib/browser/menu/title-context.menu.js +55 -0
  180. package/lib/browser/menu/title-context.menu.js.map +1 -0
  181. package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.contribution.d.ts +20 -0
  182. package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.contribution.d.ts.map +1 -0
  183. package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.contribution.js +64 -0
  184. package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.contribution.js.map +1 -0
  185. package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.service.d.ts +35 -0
  186. package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.service.d.ts.map +1 -0
  187. package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.service.js +144 -0
  188. package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.service.js.map +1 -0
  189. package/lib/browser/monaco-contrib/command/command.service.d.ts +141 -0
  190. package/lib/browser/monaco-contrib/command/command.service.d.ts.map +1 -0
  191. package/lib/browser/monaco-contrib/command/command.service.js +370 -0
  192. package/lib/browser/monaco-contrib/command/command.service.js.map +1 -0
  193. package/lib/browser/monaco-contrib/index.d.ts +3 -0
  194. package/lib/browser/monaco-contrib/index.d.ts.map +1 -0
  195. package/lib/browser/monaco-contrib/index.js +6 -0
  196. package/lib/browser/monaco-contrib/index.js.map +1 -0
  197. package/lib/browser/monaco-contrib/tokenizer/textmate-registry.d.ts +46 -0
  198. package/lib/browser/monaco-contrib/tokenizer/textmate-registry.d.ts.map +1 -0
  199. package/lib/browser/monaco-contrib/tokenizer/textmate-registry.js +79 -0
  200. package/lib/browser/monaco-contrib/tokenizer/textmate-registry.js.map +1 -0
  201. package/lib/browser/monaco-contrib/tokenizer/textmate-tokenizer.d.ts +58 -0
  202. package/lib/browser/monaco-contrib/tokenizer/textmate-tokenizer.d.ts.map +1 -0
  203. package/lib/browser/monaco-contrib/tokenizer/textmate-tokenizer.js +75 -0
  204. package/lib/browser/monaco-contrib/tokenizer/textmate-tokenizer.js.map +1 -0
  205. package/lib/browser/monaco-contrib/tokenizer/textmate.service.d.ts +54 -0
  206. package/lib/browser/monaco-contrib/tokenizer/textmate.service.d.ts.map +1 -0
  207. package/lib/browser/monaco-contrib/tokenizer/textmate.service.js +596 -0
  208. package/lib/browser/monaco-contrib/tokenizer/textmate.service.js.map +1 -0
  209. package/lib/browser/navigation.module.less +86 -0
  210. package/lib/browser/navigation.view.d.ts +29 -0
  211. package/lib/browser/navigation.view.d.ts.map +1 -0
  212. package/lib/browser/navigation.view.js +183 -0
  213. package/lib/browser/navigation.view.js.map +1 -0
  214. package/lib/browser/preference/contribution.d.ts +5 -0
  215. package/lib/browser/preference/contribution.d.ts.map +1 -0
  216. package/lib/browser/preference/contribution.js +16 -0
  217. package/lib/browser/preference/contribution.js.map +1 -0
  218. package/lib/browser/preference/converter.d.ts +34 -0
  219. package/lib/browser/preference/converter.d.ts.map +1 -0
  220. package/lib/browser/preference/converter.js +632 -0
  221. package/lib/browser/preference/converter.js.map +1 -0
  222. package/lib/browser/preference/schema.d.ts +230 -0
  223. package/lib/browser/preference/schema.d.ts.map +1 -0
  224. package/lib/browser/preference/schema.js +1453 -0
  225. package/lib/browser/preference/schema.js.map +1 -0
  226. package/lib/browser/preference/util.d.ts +4 -0
  227. package/lib/browser/preference/util.d.ts.map +1 -0
  228. package/lib/browser/preference/util.js +13 -0
  229. package/lib/browser/preference/util.js.map +1 -0
  230. package/lib/browser/resource.service.d.ts +32 -0
  231. package/lib/browser/resource.service.d.ts.map +1 -0
  232. package/lib/browser/resource.service.js +219 -0
  233. package/lib/browser/resource.service.js.map +1 -0
  234. package/lib/browser/tab.view.d.ts +12 -0
  235. package/lib/browser/tab.view.d.ts.map +1 -0
  236. package/lib/browser/tab.view.js +330 -0
  237. package/lib/browser/tab.view.js.map +1 -0
  238. package/lib/browser/types.d.ts +344 -0
  239. package/lib/browser/types.d.ts.map +1 -0
  240. package/lib/browser/types.js +94 -0
  241. package/lib/browser/types.js.map +1 -0
  242. package/lib/browser/untitled-resource.d.ts +33 -0
  243. package/lib/browser/untitled-resource.d.ts.map +1 -0
  244. package/lib/browser/untitled-resource.js +114 -0
  245. package/lib/browser/untitled-resource.js.map +1 -0
  246. package/lib/browser/view/editor.react.d.ts +10 -0
  247. package/lib/browser/view/editor.react.d.ts.map +1 -0
  248. package/lib/browser/view/editor.react.js +69 -0
  249. package/lib/browser/view/editor.react.js.map +1 -0
  250. package/lib/browser/view/react-hook.d.ts +3 -0
  251. package/lib/browser/view/react-hook.d.ts.map +1 -0
  252. package/lib/browser/view/react-hook.js +9 -0
  253. package/lib/browser/view/react-hook.js.map +1 -0
  254. package/lib/browser/view/suggest-widget.d.ts +8 -0
  255. package/lib/browser/view/suggest-widget.d.ts.map +1 -0
  256. package/lib/browser/view/suggest-widget.js +51 -0
  257. package/lib/browser/view/suggest-widget.js.map +1 -0
  258. package/lib/browser/view/topPadding.d.ts +6 -0
  259. package/lib/browser/view/topPadding.d.ts.map +1 -0
  260. package/lib/browser/view/topPadding.js +18 -0
  261. package/lib/browser/view/topPadding.js.map +1 -0
  262. package/lib/browser/workbench-editor.service.d.ts +244 -0
  263. package/lib/browser/workbench-editor.service.d.ts.map +1 -0
  264. package/lib/browser/workbench-editor.service.js +1689 -0
  265. package/lib/browser/workbench-editor.service.js.map +1 -0
  266. package/lib/common/doc-cache.d.ts +80 -0
  267. package/lib/common/doc-cache.d.ts.map +1 -0
  268. package/lib/common/doc-cache.js +39 -0
  269. package/lib/common/doc-cache.js.map +1 -0
  270. package/lib/common/editor.d.ts +571 -0
  271. package/lib/common/editor.d.ts.map +1 -0
  272. package/lib/common/editor.js +125 -0
  273. package/lib/common/editor.js.map +1 -0
  274. package/lib/common/index.d.ts +6 -0
  275. package/lib/common/index.d.ts.map +1 -0
  276. package/lib/common/index.js +9 -0
  277. package/lib/common/index.js.map +1 -0
  278. package/lib/common/language.d.ts +108 -0
  279. package/lib/common/language.d.ts.map +1 -0
  280. package/lib/common/language.js +72 -0
  281. package/lib/common/language.js.map +1 -0
  282. package/lib/common/mocks/workbench-editor.service.d.ts +21 -0
  283. package/lib/common/mocks/workbench-editor.service.d.ts.map +1 -0
  284. package/lib/common/mocks/workbench-editor.service.js +48 -0
  285. package/lib/common/mocks/workbench-editor.service.js.map +1 -0
  286. package/lib/common/resource.d.ts +94 -0
  287. package/lib/common/resource.d.ts.map +1 -0
  288. package/lib/common/resource.js +31 -0
  289. package/lib/common/resource.js.map +1 -0
  290. package/lib/common/utils.d.ts +3 -0
  291. package/lib/common/utils.d.ts.map +1 -0
  292. package/lib/common/utils.js +14 -0
  293. package/lib/common/utils.js.map +1 -0
  294. package/lib/index.d.ts +2 -0
  295. package/lib/index.d.ts.map +1 -0
  296. package/lib/index.js +5 -0
  297. package/lib/index.js.map +1 -0
  298. package/package.json +33 -0
@@ -0,0 +1,1689 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EditorGroup = exports.WorkbenchEditorServiceImpl = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const monaco = (0, tslib_1.__importStar)(require("@opensumi/monaco-editor-core/esm/vs/editor/editor.api"));
6
+ const common_1 = require("../common");
7
+ const di_1 = require("@opensumi/di");
8
+ const ide_core_common_1 = require("@opensumi/ide-core-common");
9
+ const types_1 = require("./types");
10
+ const grid_service_1 = require("./grid/grid.service");
11
+ const functional_1 = require("@opensumi/ide-core-common/lib/functional");
12
+ const ide_core_browser_1 = require("@opensumi/ide-core-browser");
13
+ const types_2 = require("./doc-model/types");
14
+ const ide_core_common_2 = require("@opensumi/ide-core-common");
15
+ const resource_1 = require("@opensumi/ide-core-browser/lib/contextkey/resource");
16
+ const ide_overlay_1 = require("@opensumi/ide-overlay");
17
+ const error_1 = require("./error");
18
+ let WorkbenchEditorServiceImpl = class WorkbenchEditorServiceImpl extends ide_core_common_1.WithEventBus {
19
+ constructor() {
20
+ super();
21
+ this.editorGroups = [];
22
+ this._onDidEditorGroupsChanged = new ide_core_common_1.Emitter();
23
+ this.onDidEditorGroupsChanged = this._onDidEditorGroupsChanged.event;
24
+ this._sortedEditorGroups = [];
25
+ this._onActiveResourceChange = new ide_core_common_1.Emitter();
26
+ this.onActiveResourceChange = this._onActiveResourceChange.event;
27
+ this._onActiveEditorUriChange = new ide_core_common_1.Emitter();
28
+ this.onActiveEditorUriChange = this._onActiveEditorUriChange.event;
29
+ this._onCursorChange = new ide_core_common_1.Emitter();
30
+ this.onCursorChange = this._onCursorChange.event;
31
+ this._onDidCurrentEditorGroupChanged = new ide_core_common_1.Emitter();
32
+ this.onDidCurrentEditorGroupChanged = this._onDidCurrentEditorGroupChanged.event;
33
+ this._restoring = true;
34
+ this.contributionsReady = new ide_core_common_1.Deferred();
35
+ this.untitledIndex = 1;
36
+ this.untitledCloseIndex = [];
37
+ this.gridReady = false;
38
+ this._onDidGridReady = new ide_core_common_1.Emitter();
39
+ this.onDidGridReady = this._onDidGridReady.event;
40
+ this.initialize();
41
+ }
42
+ setEditorContextKeyService(contextKeyService) {
43
+ this.editorContextKeyService = contextKeyService;
44
+ }
45
+ setCurrentGroup(editorGroup) {
46
+ var _a;
47
+ if (editorGroup) {
48
+ if (this._currentEditorGroup === editorGroup) {
49
+ return;
50
+ }
51
+ this._currentEditorGroup = editorGroup;
52
+ this._onActiveResourceChange.fire(editorGroup.currentResource);
53
+ this.eventBus.fire(new types_1.EditorActiveResourceStateChangedEvent({
54
+ resource: editorGroup.currentResource,
55
+ openType: editorGroup.currentOpenType,
56
+ editorUri: (_a = this.currentEditor) === null || _a === void 0 ? void 0 : _a.currentUri,
57
+ }));
58
+ this._onDidCurrentEditorGroupChanged.fire(this._currentEditorGroup);
59
+ }
60
+ }
61
+ onEditorGroupChangeEvent(e) {
62
+ var _a;
63
+ if (e.payload.group === this.currentEditorGroup) {
64
+ this.eventBus.fire(new types_1.EditorActiveResourceStateChangedEvent({
65
+ resource: e.payload.newResource,
66
+ openType: e.payload.newOpenType,
67
+ editorUri: (_a = this.currentEditor) === null || _a === void 0 ? void 0 : _a.currentUri,
68
+ }));
69
+ }
70
+ }
71
+ getAllOpenedUris() {
72
+ const uris = [];
73
+ for (const group of this.editorGroups) {
74
+ for (const resource of group.resources) {
75
+ const index = uris.findIndex((u) => u.isEqual(resource.uri));
76
+ if (index === -1) {
77
+ uris.push(resource.uri);
78
+ }
79
+ }
80
+ }
81
+ return uris;
82
+ }
83
+ async saveAll(includeUntitled, reason) {
84
+ for (const editorGroup of this.editorGroups) {
85
+ await editorGroup.saveAll(includeUntitled, reason);
86
+ }
87
+ }
88
+ hasDirty() {
89
+ for (const editorGroup of this.editorGroups) {
90
+ if (editorGroup.hasDirty()) {
91
+ return true;
92
+ }
93
+ }
94
+ return false;
95
+ }
96
+ createEditorGroup() {
97
+ const editorGroup = this.injector.get(EditorGroup, [this.generateRandomEditorGroupName()]);
98
+ this.editorGroups.push(editorGroup);
99
+ const currentWatchDisposer = new ide_core_common_1.Disposable(editorGroup.onDidEditorGroupBodyChanged(() => {
100
+ if (editorGroup === this.currentEditorGroup) {
101
+ if (!editorGroup.currentOpenType && editorGroup.currentResource) {
102
+ // 暂时状态,不发事件
103
+ }
104
+ else {
105
+ this._onActiveResourceChange.fire(editorGroup.currentResource);
106
+ }
107
+ }
108
+ }), editorGroup.onDidEditorFocusChange(() => {
109
+ var _a;
110
+ if (editorGroup === this.currentEditorGroup) {
111
+ if (!editorGroup.currentOpenType && editorGroup.currentResource) {
112
+ // 暂时状态,不发事件
113
+ }
114
+ else {
115
+ this._onActiveEditorUriChange.fire((_a = editorGroup.currentOrPreviousFocusedEditor) === null || _a === void 0 ? void 0 : _a.currentUri);
116
+ }
117
+ }
118
+ }));
119
+ editorGroup.addDispose({
120
+ dispose: () => {
121
+ currentWatchDisposer.dispose();
122
+ },
123
+ });
124
+ const groupChangeDisposer = editorGroup.onDidEditorGroupTabChanged(() => {
125
+ this.saveOpenedResourceState();
126
+ });
127
+ editorGroup.addDispose({
128
+ dispose: () => {
129
+ groupChangeDisposer.dispose();
130
+ },
131
+ });
132
+ editorGroup.onCurrentEditorCursorChange((e) => {
133
+ if (this._currentEditorGroup === editorGroup) {
134
+ this._onCursorChange.fire(e);
135
+ }
136
+ });
137
+ this._sortedEditorGroups = undefined;
138
+ this._onDidEditorGroupsChanged.fire();
139
+ return editorGroup;
140
+ }
141
+ /**
142
+ * 随机生成一个不重复的editor Group
143
+ */
144
+ generateRandomEditorGroupName() {
145
+ let name = (0, functional_1.makeRandomHexString)(5);
146
+ while (this.editorGroups.findIndex((g) => g.name === name) !== -1) {
147
+ name = (0, functional_1.makeRandomHexString)(5);
148
+ }
149
+ return name;
150
+ }
151
+ initialize() {
152
+ if (!this.initializing) {
153
+ this.initializing = this.doInitialize();
154
+ }
155
+ return this.initializing;
156
+ }
157
+ async doInitialize() {
158
+ this.openedResourceState = await this.initializeState();
159
+ await this.contributionsReady.promise;
160
+ await this.restoreState();
161
+ this._currentEditorGroup = this.editorGroups[0];
162
+ }
163
+ async initializeState() {
164
+ const state = await this.getStorage(ide_core_common_1.STORAGE_NAMESPACE.WORKBENCH);
165
+ return state;
166
+ }
167
+ get currentEditor() {
168
+ return this.currentEditorGroup && this.currentEditorGroup.currentEditor;
169
+ }
170
+ get currentCodeEditor() {
171
+ return this.currentEditorGroup.currentCodeEditor;
172
+ }
173
+ get currentEditorGroup() {
174
+ return this._currentEditorGroup;
175
+ }
176
+ async open(uri, options) {
177
+ await this.initialize();
178
+ let group = this.currentEditorGroup;
179
+ let groupIndex;
180
+ if (options && (typeof options.groupIndex !== 'undefined')) {
181
+ groupIndex = options.groupIndex;
182
+ }
183
+ else if (options && options.relativeGroupIndex) {
184
+ groupIndex = this.currentEditorGroup.index + options.relativeGroupIndex;
185
+ }
186
+ if (typeof groupIndex === 'number' && groupIndex >= 0) {
187
+ if (groupIndex >= this.editorGroups.length) {
188
+ return group.open(uri, Object.assign({}, options, { split: common_1.EditorGroupSplitAction.Right }));
189
+ }
190
+ else {
191
+ group = this.sortedEditorGroups[groupIndex] || this.currentEditorGroup;
192
+ }
193
+ }
194
+ return group.open(uri, options);
195
+ }
196
+ async openUris(uris) {
197
+ await this.initialize();
198
+ await this.currentEditorGroup.openUris(uris);
199
+ return;
200
+ }
201
+ getEditorGroup(name) {
202
+ return this.editorGroups.find((g) => g.name === name);
203
+ }
204
+ get currentResource() {
205
+ if (!this.currentEditorGroup) {
206
+ return null;
207
+ }
208
+ return this.currentEditorGroup.currentResource;
209
+ }
210
+ removeGroup(group) {
211
+ const index = this.editorGroups.findIndex((e) => e === group);
212
+ if (index !== -1) {
213
+ if (this.editorGroups.length === 1) {
214
+ return;
215
+ }
216
+ this.editorGroups.splice(index, 1);
217
+ if (this.currentEditorGroup === group) {
218
+ this.setCurrentGroup(this.editorGroups[0]);
219
+ }
220
+ for (let i = index; i < this.editorGroups.length; i++) {
221
+ this.eventBus.fire(new types_1.EditorGroupIndexChangedEvent({
222
+ group: this.editorGroups[i],
223
+ index: i,
224
+ }));
225
+ }
226
+ this._onDidEditorGroupsChanged.fire();
227
+ }
228
+ this._sortedEditorGroups = undefined;
229
+ }
230
+ async saveOpenedResourceState() {
231
+ if (this._restoring) {
232
+ return;
233
+ }
234
+ const state = this.topGrid.serialize();
235
+ await this.openedResourceState.set('grid', state);
236
+ }
237
+ prepareContextKeyService() {
238
+ // contextKeys
239
+ const getLanguageFromModel = (uri) => {
240
+ let result = null;
241
+ const modelRef = this.documentModelManager.getModelReference(uri, 'resourceContextKey');
242
+ if (modelRef) {
243
+ if (modelRef) {
244
+ result = modelRef.instance.languageId;
245
+ }
246
+ modelRef.dispose();
247
+ }
248
+ return result;
249
+ };
250
+ const resourceContext = new resource_1.ResourceContextKey(this.editorContextKeyService, (uri) => {
251
+ const res = getLanguageFromModel(uri);
252
+ if (res) {
253
+ return res;
254
+ }
255
+ else {
256
+ return getLanguageFromModel(uri);
257
+ }
258
+ });
259
+ this.onActiveResourceChange((resource) => {
260
+ if (this.currentEditor && this.currentEditor.currentUri) {
261
+ resourceContext.set(this.currentEditor.currentUri);
262
+ }
263
+ else {
264
+ if (resource) {
265
+ resourceContext.set(resource.uri);
266
+ }
267
+ else {
268
+ resourceContext.reset();
269
+ }
270
+ }
271
+ });
272
+ if (this.currentEditor && this.currentEditor.currentUri) {
273
+ resourceContext.set(this.currentEditor.currentUri);
274
+ }
275
+ else {
276
+ if (this.currentResource) {
277
+ resourceContext.set(this.currentResource.uri);
278
+ }
279
+ else {
280
+ resourceContext.reset();
281
+ }
282
+ }
283
+ }
284
+ onDomCreated(domNode) {
285
+ this._domNode = domNode;
286
+ if (this.editorContextKeyService) {
287
+ this.editorContextKeyService.attachToDomNode(domNode);
288
+ }
289
+ }
290
+ async restoreState() {
291
+ let state = { editorGroup: { uris: [], previewIndex: -1 } };
292
+ state = this.openedResourceState.get('grid', state);
293
+ this.topGrid = new grid_service_1.EditorGrid();
294
+ const editorRestorePromises = [];
295
+ const promise = this.topGrid.deserialize(state, () => {
296
+ return this.createEditorGroup();
297
+ }, editorRestorePromises).then(() => {
298
+ if (this.topGrid.children.length === 0 && !this.topGrid.editorGroup) {
299
+ this.topGrid.setEditorGroup(this.createEditorGroup());
300
+ }
301
+ this.gridReady = true;
302
+ this._onDidGridReady.fire();
303
+ });
304
+ Promise.all(editorRestorePromises).then(() => {
305
+ this._restoring = false;
306
+ for (const contribution of this.contributions.getContributions()) {
307
+ if (contribution.onDidRestoreState) {
308
+ contribution.onDidRestoreState();
309
+ }
310
+ }
311
+ });
312
+ return promise;
313
+ }
314
+ async closeAll(uri, force) {
315
+ for (const group of this.editorGroups.slice(0)) {
316
+ if (uri) {
317
+ await group.close(uri, { force });
318
+ }
319
+ else {
320
+ await group.closeAll();
321
+ }
322
+ }
323
+ }
324
+ async close(uri, force) {
325
+ return this.closeAll(uri, force);
326
+ }
327
+ get sortedEditorGroups() {
328
+ if (!this._sortedEditorGroups) {
329
+ this._sortedEditorGroups = [];
330
+ this.topGrid.sortEditorGroups(this._sortedEditorGroups);
331
+ }
332
+ return this._sortedEditorGroups;
333
+ }
334
+ handleOnCloseUntitledResource(e) {
335
+ if (e.payload.resource.uri.scheme === ide_core_common_2.Schemas.untitled) {
336
+ const { index } = e.payload.resource.uri.getParsedQuery();
337
+ this.untitledCloseIndex.push(parseInt(index, 10));
338
+ // 升序排序,每次可以去到最小的 index
339
+ this.untitledCloseIndex.sort((a, b) => a - b);
340
+ }
341
+ }
342
+ createUntitledURI() {
343
+ // 优先从已删除的 index 中获取
344
+ const index = this.untitledCloseIndex.shift() || this.untitledIndex++;
345
+ return new ide_core_common_1.URI()
346
+ .withScheme(ide_core_common_2.Schemas.untitled)
347
+ .withQuery(`name=Untitled-${index}&index=${index}`);
348
+ }
349
+ createUntitledResource(options = {
350
+ uri: this.createUntitledURI(),
351
+ }) {
352
+ return this.open(options.uri, Object.assign({ preview: false, focus: true }, options.resourceOpenOptions));
353
+ }
354
+ };
355
+ (0, tslib_1.__decorate)([
356
+ (0, di_1.Autowired)(di_1.INJECTOR_TOKEN),
357
+ (0, tslib_1.__metadata)("design:type", di_1.Injector)
358
+ ], WorkbenchEditorServiceImpl.prototype, "injector", void 0);
359
+ (0, tslib_1.__decorate)([
360
+ (0, di_1.Autowired)(ide_core_common_1.StorageProvider),
361
+ (0, tslib_1.__metadata)("design:type", Function)
362
+ ], WorkbenchEditorServiceImpl.prototype, "getStorage", void 0);
363
+ (0, tslib_1.__decorate)([
364
+ (0, di_1.Autowired)(types_1.BrowserEditorContribution),
365
+ (0, tslib_1.__metadata)("design:type", Object)
366
+ ], WorkbenchEditorServiceImpl.prototype, "contributions", void 0);
367
+ (0, tslib_1.__decorate)([
368
+ (0, di_1.Autowired)(types_2.IEditorDocumentModelService),
369
+ (0, tslib_1.__metadata)("design:type", Object)
370
+ ], WorkbenchEditorServiceImpl.prototype, "documentModelManager", void 0);
371
+ (0, tslib_1.__decorate)([
372
+ (0, ide_core_common_1.OnEvent)(types_1.EditorGroupChangeEvent),
373
+ (0, tslib_1.__metadata)("design:type", Function),
374
+ (0, tslib_1.__metadata)("design:paramtypes", [types_1.EditorGroupChangeEvent]),
375
+ (0, tslib_1.__metadata)("design:returntype", void 0)
376
+ ], WorkbenchEditorServiceImpl.prototype, "onEditorGroupChangeEvent", null);
377
+ (0, tslib_1.__decorate)([
378
+ (0, ide_core_common_1.OnEvent)(types_1.EditorGroupCloseEvent),
379
+ (0, tslib_1.__metadata)("design:type", Function),
380
+ (0, tslib_1.__metadata)("design:paramtypes", [types_1.EditorGroupCloseEvent]),
381
+ (0, tslib_1.__metadata)("design:returntype", void 0)
382
+ ], WorkbenchEditorServiceImpl.prototype, "handleOnCloseUntitledResource", null);
383
+ WorkbenchEditorServiceImpl = (0, tslib_1.__decorate)([
384
+ (0, di_1.Injectable)(),
385
+ (0, tslib_1.__metadata)("design:paramtypes", [])
386
+ ], WorkbenchEditorServiceImpl);
387
+ exports.WorkbenchEditorServiceImpl = WorkbenchEditorServiceImpl;
388
+ /**
389
+ * Editor Group是一个可视的编辑区域
390
+ * 它由tab,editor,diff-editor,富组件container组成
391
+ */
392
+ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
393
+ constructor(name) {
394
+ super();
395
+ this.name = name;
396
+ this.openingPromise = new Map();
397
+ this._onDidEditorFocusChange = this.registerDispose(new ide_core_common_1.Emitter());
398
+ this.onDidEditorFocusChange = this._onDidEditorFocusChange.event;
399
+ /**
400
+ * 当编辑器的tab部分发生变更
401
+ */
402
+ this._onDidEditorGroupTabChanged = new ide_core_common_1.Emitter();
403
+ this.onDidEditorGroupTabChanged = this._onDidEditorGroupTabChanged.event;
404
+ /**
405
+ * 当编辑器的主体部分发生变更
406
+ */
407
+ this._onDidEditorGroupBodyChanged = new ide_core_common_1.Emitter();
408
+ this.onDidEditorGroupBodyChanged = this._onDidEditorGroupBodyChanged.event;
409
+ /**
410
+ * 当编辑器有内容处于加载状态
411
+ */
412
+ this._onDidEditorGroupContentLoading = new ide_core_common_1.Emitter();
413
+ this.onDidEditorGroupContentLoading = this._onDidEditorGroupContentLoading.event;
414
+ /**
415
+ * 每个group只能有一个preview
416
+ */
417
+ this.previewURI = null;
418
+ /**
419
+ * 当前打开的所有resource
420
+ */
421
+ // @observable.shallow
422
+ this.resources = [];
423
+ this.resourceStatus = new Map();
424
+ /**
425
+ * 当前resource的打开方式
426
+ */
427
+ this.cachedResourcesActiveOpenTypes = new Map();
428
+ this.cachedResourcesOpenTypes = new Map();
429
+ this.availableOpenTypes = [];
430
+ this.activeComponents = new Map();
431
+ this.activateComponentsProps = new Map();
432
+ this.holdDocumentModelRefs = new Map();
433
+ this.toDispose = [];
434
+ this._prevDomHeight = 0;
435
+ this._prevDomWidth = 0;
436
+ this._codeEditorPendingLayout = false;
437
+ this._diffEditorPendingLayout = false;
438
+ // 当前为EditorComponent,且monaco光标变化时触发
439
+ this._onCurrentEditorCursorChange = new ide_core_common_1.Emitter();
440
+ this.onCurrentEditorCursorChange = this._onCurrentEditorCursorChange.event;
441
+ this.resourceOpenHistory = [];
442
+ this._domNode = null;
443
+ this.codeEditorReady = new ide_core_common_1.ReadyEvent();
444
+ this.diffEditorReady = new ide_core_common_1.ReadyEvent();
445
+ this._restoringState = false;
446
+ this.eventBus.on(ide_core_browser_1.ResizeEvent, (e) => {
447
+ if (e.payload.slotLocation === (0, ide_core_browser_1.getSlotLocation)('@opensumi/ide-editor', this.config.layoutConfig)) {
448
+ this.doLayoutEditors();
449
+ }
450
+ });
451
+ this.eventBus.on(types_1.GridResizeEvent, (e) => {
452
+ if (e.payload.gridId === this.grid.uid) {
453
+ this.doLayoutEditors();
454
+ }
455
+ });
456
+ this.eventBus.on(types_1.EditorComponentDisposeEvent, (e) => {
457
+ this.activeComponents.delete(e.payload);
458
+ this.activateComponentsProps.delete(e.payload);
459
+ });
460
+ this.listenToExplorerAutoRevealConfig();
461
+ }
462
+ listenToExplorerAutoRevealConfig() {
463
+ this.explorerAutoRevealConfig = !!this.preferenceService.get('explorer.autoReveal');
464
+ this.disposables.push(this.preferenceService.onPreferenceChanged((change) => {
465
+ if (change.preferenceName === 'explorer.autoReveal') {
466
+ this.explorerAutoRevealConfig = change.newValue;
467
+ }
468
+ }));
469
+ }
470
+ attachToDom(domNode) {
471
+ this._domNode = domNode;
472
+ if (domNode) {
473
+ this.contextKeyService.attachToDomNode(domNode);
474
+ this.layoutEditors();
475
+ }
476
+ }
477
+ layoutEditors() {
478
+ if (this._domNode) {
479
+ const currentWidth = this._domNode.offsetWidth;
480
+ const currentHeight = this._domNode.offsetHeight;
481
+ if (currentWidth !== this._prevDomWidth || currentHeight !== this._prevDomHeight) {
482
+ this.doLayoutEditors();
483
+ }
484
+ this._prevDomWidth = currentWidth;
485
+ this._prevDomHeight = currentHeight;
486
+ }
487
+ }
488
+ doLayoutEditors() {
489
+ if (this.codeEditor) {
490
+ if (this.currentOpenType && this.currentOpenType.type === 'code') {
491
+ this.codeEditor.layout();
492
+ this._codeEditorPendingLayout = false;
493
+ }
494
+ else {
495
+ this._codeEditorPendingLayout = true;
496
+ }
497
+ }
498
+ if (this.diffEditor) {
499
+ if (this.currentOpenType && this.currentOpenType.type === 'diff') {
500
+ this.diffEditor.layout();
501
+ this._diffEditorPendingLayout = false;
502
+ }
503
+ else {
504
+ this._diffEditorPendingLayout = true;
505
+ }
506
+ }
507
+ }
508
+ // get currentState() {
509
+ // return this._currentState;
510
+ // }
511
+ // set currentState(value: IEditorCurrentState | null) {
512
+ // const oldResource = this.currentResource;
513
+ // const oldOpenType = this.currentOpenType;
514
+ // this._currentState = value;
515
+ // this._pendingState = null;
516
+ // if (oldResource && this.resourceOpenHistory[this.resourceOpenHistory.length - 1] !== oldResource.uri) {
517
+ // this.resourceOpenHistory.push(oldResource.uri);
518
+ // }
519
+ // this.eventBus.fire(new EditorGroupChangeEvent({
520
+ // group: this,
521
+ // newOpenType: this.currentOpenType,
522
+ // newResource: this.currentResource,
523
+ // oldOpenType,
524
+ // oldResource,
525
+ // }));
526
+ // this.setContextKeys();
527
+ // }
528
+ setContextKeys() {
529
+ var _a;
530
+ if (!this._resourceContext) {
531
+ const getLanguageFromModel = (uri) => {
532
+ let result = null;
533
+ const modelRef = this.documentModelManager.getModelReference(uri, 'resourceContextKey');
534
+ if (modelRef) {
535
+ if (modelRef) {
536
+ result = modelRef.instance.languageId;
537
+ }
538
+ modelRef.dispose();
539
+ }
540
+ return result;
541
+ };
542
+ this._resourceContext = new resource_1.ResourceContextKey(this.contextKeyService, (uri) => {
543
+ const res = getLanguageFromModel(uri);
544
+ if (res) {
545
+ return res;
546
+ }
547
+ else {
548
+ return getLanguageFromModel(uri);
549
+ }
550
+ });
551
+ this._editorLangIDContextKey = this.contextKeyService.createKey('editorLangId', '');
552
+ this._isInDiffEditorContextKey = this.contextKeyService.createKey('isInDiffEditor', false);
553
+ this._isInDiffRightEditorContextKey = this.contextKeyService.createKey('isInDiffRightEditor', false);
554
+ this._isInEditorComponentContextKey = this.contextKeyService.createKey('inEditorComponent', false);
555
+ }
556
+ if (this.currentOrPreviousFocusedEditor && this.currentOrPreviousFocusedEditor.currentUri) {
557
+ this._resourceContext.set(this.currentOrPreviousFocusedEditor.currentUri);
558
+ if (this.currentOrPreviousFocusedEditor.currentDocumentModel) {
559
+ this._editorLangIDContextKey.set(this.currentOrPreviousFocusedEditor.currentDocumentModel.languageId);
560
+ }
561
+ }
562
+ else if (this.currentEditor && this.currentEditor.currentUri) {
563
+ this._resourceContext.set(this.currentEditor.currentUri);
564
+ if (this.currentEditor.currentDocumentModel) {
565
+ this._editorLangIDContextKey.set(this.currentEditor.currentDocumentModel.languageId);
566
+ }
567
+ }
568
+ else {
569
+ if (this.currentResource) {
570
+ this._resourceContext.set(this.currentResource.uri);
571
+ }
572
+ else {
573
+ this._resourceContext.reset();
574
+ }
575
+ this._editorLangIDContextKey.reset();
576
+ }
577
+ this._isInDiffEditorContextKey.set(!!this.currentOpenType && this.currentOpenType.type === 'diff');
578
+ // 没有 focus 的时候默认添加在 RightDiffEditor
579
+ this._isInDiffRightEditorContextKey.set(!!this.currentOpenType && this.currentOpenType.type === 'diff');
580
+ this._isInEditorComponentContextKey.set(((_a = this.currentOpenType) === null || _a === void 0 ? void 0 : _a.type) === 'component');
581
+ this.updateContextKeyWhenDiffEditorChangesFocus();
582
+ }
583
+ updateContextKeyWhenDiffEditorChangesFocus() {
584
+ if (this.updateContextKeyWhenEditorChangesFocusDisposer || !this.diffEditor) {
585
+ return;
586
+ }
587
+ const emitIfNoEditorFocused = () => {
588
+ if (!this.currentFocusedEditor) {
589
+ this.setContextKeys();
590
+ this._onDidEditorFocusChange.fire();
591
+ }
592
+ };
593
+ this.updateContextKeyWhenEditorChangesFocusDisposer = new ide_core_common_1.Disposable(this.diffEditor.modifiedEditor.onFocus(() => {
594
+ this._currentOrPreviousFocusedEditor = this.diffEditor.modifiedEditor;
595
+ this.setContextKeys();
596
+ this._onDidEditorFocusChange.fire();
597
+ }), this.diffEditor.originalEditor.onFocus(() => {
598
+ this._currentOrPreviousFocusedEditor = this.diffEditor.originalEditor;
599
+ this.setContextKeys();
600
+ this._onDidEditorFocusChange.fire();
601
+ }), this.codeEditor.onFocus(() => {
602
+ this._currentOrPreviousFocusedEditor = this.codeEditor;
603
+ this.setContextKeys();
604
+ this._onDidEditorFocusChange.fire();
605
+ }), this.codeEditor.onBlur(emitIfNoEditorFocused), this.diffEditor.originalEditor.onBlur(emitIfNoEditorFocused), this.diffEditor.modifiedEditor.onBlur(emitIfNoEditorFocused));
606
+ this.addDispose(this.updateContextKeyWhenEditorChangesFocusDisposer);
607
+ }
608
+ get contextKeyService() {
609
+ if (!this._contextKeyService) {
610
+ this._contextKeyService = this.workbenchEditorService.editorContextKeyService.createScoped();
611
+ }
612
+ return this._contextKeyService;
613
+ }
614
+ get index() {
615
+ return this.workbenchEditorService.sortedEditorGroups.indexOf(this);
616
+ }
617
+ onResourceDecorationChangeEvent(e) {
618
+ if (e.payload.decoration.dirty) {
619
+ if (this.previewURI && this.previewURI.isEqual(e.payload.uri)) {
620
+ this.pinPreviewed();
621
+ }
622
+ }
623
+ const existingResource = this.resources.find((r) => r.uri.isEqual(e.payload.uri));
624
+ if (existingResource) {
625
+ this.notifyTabChanged();
626
+ }
627
+ }
628
+ oResourceOpenTypeChangedEvent(e) {
629
+ const uri = e.payload;
630
+ if (this.cachedResourcesOpenTypes.has(uri.toString())) {
631
+ this.cachedResourcesOpenTypes.delete(uri.toString());
632
+ }
633
+ if (this.currentResource && this.currentResource.uri.isEqual(uri)) {
634
+ this._currentOpenType = null;
635
+ this.notifyBodyChanged();
636
+ this.displayResourceComponent(this.currentResource, {});
637
+ }
638
+ }
639
+ pinPreviewed(uri) {
640
+ const previous = this.previewURI;
641
+ if (uri === undefined) {
642
+ this.previewURI = null;
643
+ }
644
+ else if (this.previewURI && this.previewURI.isEqual(uri)) {
645
+ this.previewURI = null;
646
+ }
647
+ if (previous !== this.previewURI) {
648
+ this.notifyTabChanged();
649
+ }
650
+ }
651
+ notifyTabChanged() {
652
+ if (this._restoringState) {
653
+ return;
654
+ }
655
+ this._onDidEditorGroupTabChanged.fire();
656
+ }
657
+ notifyBodyChanged() {
658
+ this._onDidEditorGroupBodyChanged.fire();
659
+ }
660
+ notifyTabLoading(resource) {
661
+ this._onDidEditorGroupContentLoading.fire(resource);
662
+ }
663
+ get currentEditor() {
664
+ if (this.currentOpenType) {
665
+ if (this.currentOpenType.type === 'code') {
666
+ return this.codeEditor;
667
+ }
668
+ else if (this.currentOpenType.type === 'diff') {
669
+ return this.diffEditor.modifiedEditor;
670
+ }
671
+ else {
672
+ return null;
673
+ }
674
+ }
675
+ else {
676
+ return null;
677
+ }
678
+ }
679
+ get currentOrPreviousFocusedEditor() {
680
+ return this._currentOrPreviousFocusedEditor || this.currentEditor;
681
+ }
682
+ get currentFocusedEditor() {
683
+ if (this.currentOpenType) {
684
+ if (this.currentOpenType.type === 'code') {
685
+ if (this.codeEditor.monacoEditor.hasWidgetFocus()) {
686
+ return this.codeEditor;
687
+ }
688
+ }
689
+ else if (this.currentOpenType.type === 'diff') {
690
+ if (this.diffEditor.modifiedEditor.monacoEditor.hasTextFocus()) {
691
+ return this.diffEditor.modifiedEditor;
692
+ }
693
+ else if (this.diffEditor.originalEditor.monacoEditor.hasTextFocus()) {
694
+ return this.diffEditor.originalEditor;
695
+ }
696
+ if (this.diffEditor.modifiedEditor.monacoEditor.hasWidgetFocus()) {
697
+ return this.diffEditor.modifiedEditor;
698
+ }
699
+ else if (this.diffEditor.originalEditor.monacoEditor.hasWidgetFocus()) {
700
+ return this.diffEditor.originalEditor;
701
+ }
702
+ }
703
+ }
704
+ return null;
705
+ }
706
+ get currentCodeEditor() {
707
+ if (this.currentOpenType) {
708
+ if (this.currentOpenType.type === 'code') {
709
+ return this.codeEditor;
710
+ }
711
+ else {
712
+ return null;
713
+ }
714
+ }
715
+ else {
716
+ return null;
717
+ }
718
+ }
719
+ createEditor(dom) {
720
+ this.codeEditor = this.collectionService.createCodeEditor(dom, {}, {
721
+ [ide_core_browser_1.ServiceNames.CONTEXT_KEY_SERVICE]: this.contextKeyService.contextKeyService,
722
+ });
723
+ setTimeout(() => {
724
+ this.codeEditor.layout();
725
+ });
726
+ this.toDispose.push(this.codeEditor.onCursorPositionChanged((e) => {
727
+ this._onCurrentEditorCursorChange.fire(e);
728
+ }));
729
+ this.toDispose.push(this.codeEditor.onSelectionsChanged((e) => {
730
+ if (this.currentOpenType && this.currentOpenType.type === 'code') {
731
+ this.eventBus.fire(new types_1.EditorSelectionChangeEvent({
732
+ group: this,
733
+ resource: this.currentResource,
734
+ selections: e.selections,
735
+ source: e.source,
736
+ editorUri: this.codeEditor.currentUri,
737
+ }));
738
+ }
739
+ }));
740
+ this.toDispose.push(this.codeEditor.onVisibleRangesChanged((e) => {
741
+ if (this.currentOpenType && this.currentOpenType.type === 'code') {
742
+ this.eventBus.fire(new types_1.EditorVisibleChangeEvent({
743
+ group: this,
744
+ resource: this.currentResource,
745
+ visibleRanges: e,
746
+ editorUri: this.codeEditor.currentUri,
747
+ }));
748
+ }
749
+ }));
750
+ this.toDispose.push(this.codeEditor.onConfigurationChanged(() => {
751
+ if (this.currentOpenType && this.currentOpenType.type === 'code') {
752
+ this.eventBus.fire(new types_1.EditorConfigurationChangedEvent({
753
+ group: this,
754
+ resource: this.currentResource,
755
+ editorUri: this.codeEditor.currentUri,
756
+ }));
757
+ }
758
+ }));
759
+ this.eventBus.fire(new types_1.CodeEditorDidVisibleEvent({
760
+ groupName: this.name,
761
+ type: 'code',
762
+ editorId: this.codeEditor.getId(),
763
+ }));
764
+ this.codeEditorReady.ready();
765
+ }
766
+ createDiffEditor(dom) {
767
+ this.diffEditor = this.collectionService.createDiffEditor(dom, {}, {
768
+ [ide_core_browser_1.ServiceNames.CONTEXT_KEY_SERVICE]: this.contextKeyService.contextKeyService,
769
+ });
770
+ setTimeout(() => {
771
+ this.diffEditor.layout();
772
+ });
773
+ // 这里应该还要加上 originalEditor 的相关监听,目前为了避免复杂度,先不放
774
+ this.toDispose.push(this.diffEditor.modifiedEditor.onSelectionsChanged((e) => {
775
+ if (this.currentOpenType && this.currentOpenType.type === 'diff') {
776
+ this.eventBus.fire(new types_1.EditorSelectionChangeEvent({
777
+ group: this,
778
+ resource: this.currentResource,
779
+ selections: e.selections,
780
+ source: e.source,
781
+ editorUri: this.diffEditor.modifiedEditor.currentUri,
782
+ }));
783
+ }
784
+ }));
785
+ this.toDispose.push(this.diffEditor.modifiedEditor.onVisibleRangesChanged((e) => {
786
+ if (this.currentOpenType && this.currentOpenType.type === 'diff') {
787
+ this.eventBus.fire(new types_1.EditorVisibleChangeEvent({
788
+ group: this,
789
+ resource: this.currentResource,
790
+ visibleRanges: e,
791
+ editorUri: this.diffEditor.modifiedEditor.currentUri,
792
+ }));
793
+ }
794
+ }));
795
+ this.toDispose.push(this.diffEditor.modifiedEditor.onConfigurationChanged(() => {
796
+ if (this.currentOpenType && this.currentOpenType.type === 'diff') {
797
+ this.eventBus.fire(new types_1.EditorConfigurationChangedEvent({
798
+ group: this,
799
+ resource: this.currentResource,
800
+ editorUri: this.diffEditor.modifiedEditor.currentUri,
801
+ }));
802
+ }
803
+ }));
804
+ this.eventBus.fire(new types_1.CodeEditorDidVisibleEvent({
805
+ groupName: this.name,
806
+ type: 'diff',
807
+ editorId: this.diffEditor.modifiedEditor.getId(),
808
+ }));
809
+ this.diffEditorReady.ready();
810
+ }
811
+ async split(action, uri, options) {
812
+ var _a, _b, _c;
813
+ const editorGroup = this.workbenchEditorService.createEditorGroup();
814
+ const direction = (action === common_1.EditorGroupSplitAction.Left || action === common_1.EditorGroupSplitAction.Right) ? grid_service_1.SplitDirection.Horizontal : grid_service_1.SplitDirection.Vertical;
815
+ const before = (action === common_1.EditorGroupSplitAction.Left || action === common_1.EditorGroupSplitAction.Top) ? true : false;
816
+ this.grid.split(direction, editorGroup, before);
817
+ // 对于同一个编辑器分栏的场景,希望保留原本的滚动状态,与 VS Code 保持一致
818
+ if (options && !options.scrollTop) {
819
+ options.scrollTop = (_a = this.currentEditor) === null || _a === void 0 ? void 0 : _a.monacoEditor.getScrollTop();
820
+ }
821
+ if (options && !options.scrollLeft) {
822
+ options.scrollLeft = (_b = this.currentEditor) === null || _b === void 0 ? void 0 : _b.monacoEditor.getScrollLeft();
823
+ }
824
+ if (options && !(options === null || options === void 0 ? void 0 : options.range)) {
825
+ const selection = (_c = this.currentCodeEditor) === null || _c === void 0 ? void 0 : _c.monacoEditor.getSelection();
826
+ if (selection) {
827
+ options.range = new monaco.Range(selection.startLineNumber, selection.startColumn, selection.endLineNumber, selection.endColumn);
828
+ }
829
+ }
830
+ return editorGroup.open(uri, Object.assign(Object.assign({}, options), { preview: false }));
831
+ }
832
+ async open(uri, options = {}) {
833
+ if (uri.scheme === ide_core_common_2.Schemas.file) {
834
+ // 只记录 file 类型的
835
+ this.recentFilesManager.setMostRecentlyOpenedFile(uri.withoutFragment().toString());
836
+ }
837
+ if (options && options.split) {
838
+ return this.split(options.split, uri, Object.assign({}, options, { split: undefined, preview: false }));
839
+ }
840
+ if (!this.openingPromise.has(uri.toString())) {
841
+ const promise = this.doOpen(uri, options);
842
+ this.openingPromise.set(uri.toString(), promise);
843
+ promise.then(() => {
844
+ this.openingPromise.delete(uri.toString());
845
+ }, () => {
846
+ this.openingPromise.delete(uri.toString());
847
+ });
848
+ }
849
+ const previewMode = this.preferenceService.get('editor.previewMode') && ((0, ide_core_common_2.isUndefinedOrNull)(options.preview) ? true : options.preview);
850
+ if (!previewMode) {
851
+ this.openingPromise.get(uri.toString()).then(() => {
852
+ this.pinPreviewed(uri);
853
+ });
854
+ }
855
+ return this.openingPromise.get(uri.toString());
856
+ }
857
+ async pin(uri) {
858
+ return this.pinPreviewed(uri);
859
+ }
860
+ async doOpen(uri, options = {}) {
861
+ var _a, _b;
862
+ if (!this.resourceService.handlesUri(uri)) {
863
+ this.openerService.open(uri);
864
+ return false;
865
+ }
866
+ let resourceReady;
867
+ try {
868
+ const previewMode = this.preferenceService.get('editor.previewMode') && ((0, ide_core_common_2.isUndefinedOrNull)(options.preview) ? true : options.preview);
869
+ if (this.currentResource && this.currentResource.uri.isEqual(uri)) {
870
+ // 就是当前打开的resource
871
+ if (options.focus && this.currentEditor) {
872
+ (_a = this._domNode) === null || _a === void 0 ? void 0 : _a.focus();
873
+ this.currentEditor.monacoEditor.focus();
874
+ }
875
+ if (options.range && this.currentEditor) {
876
+ this.currentEditor.monacoEditor.revealRangeInCenter(options.range);
877
+ this.currentEditor.monacoEditor.setSelection(options.range);
878
+ }
879
+ if ((options && options.disableNavigate) || (options && options.backend)) {
880
+ // no-op
881
+ }
882
+ else {
883
+ this.locateInFileTree(uri);
884
+ }
885
+ this.notifyTabChanged();
886
+ return {
887
+ group: this,
888
+ resource: this.currentResource,
889
+ };
890
+ }
891
+ else {
892
+ const oldOpenType = this._currentOpenType;
893
+ const oldResource = this._currentResource;
894
+ let resource = this.resources.find((r) => r.uri.toString() === uri.toString());
895
+ if (!resource) {
896
+ // open new resource
897
+ resource = await this.resourceService.getResource(uri);
898
+ if (!resource) {
899
+ throw new Error('This uri cannot be opened!: ' + uri);
900
+ }
901
+ if (resource.deleted) {
902
+ if (options.deletedPolicy === 'fail') {
903
+ throw new Error('resource deleted ' + uri);
904
+ }
905
+ else if (options.deletedPolicy === 'skip') {
906
+ return false;
907
+ }
908
+ }
909
+ if (options && options.label) {
910
+ resource.name = options.label;
911
+ }
912
+ let replaceResource = null;
913
+ if (options && options.index !== undefined && options.index < this.resources.length) {
914
+ replaceResource = this.resources[options.index];
915
+ this.resources.splice(options.index, 0, resource);
916
+ }
917
+ else {
918
+ if (this.currentResource) {
919
+ const currentIndex = this.resources.indexOf(this.currentResource);
920
+ this.resources.splice(currentIndex + 1, 0, resource);
921
+ replaceResource = this.currentResource;
922
+ }
923
+ else {
924
+ this.resources.push(resource);
925
+ }
926
+ }
927
+ if (previewMode) {
928
+ if (this.previewURI) {
929
+ await this.close(this.previewURI, { treatAsNotCurrent: true });
930
+ }
931
+ this.previewURI = resource.uri;
932
+ }
933
+ if (options.replace && replaceResource) {
934
+ await this.close(replaceResource.uri, { treatAsNotCurrent: true });
935
+ }
936
+ }
937
+ if (options.backend) {
938
+ this.notifyTabChanged();
939
+ return false;
940
+ }
941
+ if (oldResource && this.resourceOpenHistory[this.resourceOpenHistory.length - 1] !== oldResource.uri) {
942
+ this.resourceOpenHistory.push(oldResource.uri);
943
+ const oldResourceSelections = (_b = this.currentCodeEditor) === null || _b === void 0 ? void 0 : _b.getSelections();
944
+ if (oldResourceSelections && oldResourceSelections.length > 0) {
945
+ this.recentFilesManager.updateMostRecentlyOpenedFile(oldResource.uri.toString(), {
946
+ lineNumber: oldResourceSelections[0].selectionStartLineNumber,
947
+ column: oldResourceSelections[0].selectionStartColumn,
948
+ });
949
+ }
950
+ }
951
+ this._currentResource = resource;
952
+ this.notifyTabChanged();
953
+ this._currentOpenType = null;
954
+ this.notifyBodyChanged();
955
+ // 只有真正打开的文件才会走到这里,backend模式的只更新了tab,文件内容并未加载
956
+ const reportTimer = this.reporterService.time(ide_core_common_2.REPORT_NAME.EDITOR_REACTIVE);
957
+ resourceReady = new ide_core_common_1.Deferred();
958
+ this.resourceStatus.set(resource, resourceReady.promise);
959
+ // 超过60ms loading时间的才展示加载
960
+ const delayTimer = setTimeout(() => {
961
+ this.notifyTabLoading(resource);
962
+ }, 60);
963
+ await this.displayResourceComponent(resource, options);
964
+ clearTimeout(delayTimer);
965
+ resourceReady.resolve();
966
+ reportTimer.timeEnd(resource.uri.toString());
967
+ this._currentOrPreviousFocusedEditor = this.currentEditor;
968
+ this._onDidEditorFocusChange.fire();
969
+ this.setContextKeys();
970
+ this.eventBus.fire(new types_1.EditorGroupOpenEvent({
971
+ group: this,
972
+ resource,
973
+ }));
974
+ if ((options && options.disableNavigate) || (options && options.backend)) {
975
+ // no-op
976
+ }
977
+ else {
978
+ this.locateInFileTree(uri);
979
+ }
980
+ this.eventBus.fire(new types_1.EditorGroupChangeEvent({
981
+ group: this,
982
+ newOpenType: this.currentOpenType,
983
+ newResource: this.currentResource,
984
+ oldOpenType,
985
+ oldResource,
986
+ }));
987
+ return {
988
+ group: this,
989
+ resource,
990
+ };
991
+ }
992
+ }
993
+ catch (e) {
994
+ (0, ide_core_common_1.getDebugLogger)().error(e);
995
+ resourceReady && resourceReady.reject();
996
+ if (!(0, error_1.isEditorError)(e, error_1.EditorTabChangedError)) {
997
+ this.messageService.error((0, ide_core_common_1.formatLocalize)('editor.failToOpen', uri.displayName, e.message), [], true);
998
+ }
999
+ return false;
1000
+ // todo 给用户显示error
1001
+ }
1002
+ }
1003
+ locateInFileTree(uri) {
1004
+ if (this.explorerAutoRevealConfig) {
1005
+ this.commands.tryExecuteCommand(ide_core_browser_1.FILE_COMMANDS.LOCATION.id, uri);
1006
+ }
1007
+ }
1008
+ async openUris(uris) {
1009
+ for (const uri of uris) {
1010
+ await this.open(uri);
1011
+ }
1012
+ }
1013
+ async getDocumentModelRef(uri) {
1014
+ if (!this.holdDocumentModelRefs.has(uri.toString())) {
1015
+ this.holdDocumentModelRefs.set(uri.toString(), await this.documentModelManager.createModelReference(uri, 'editor-group-' + this.name));
1016
+ }
1017
+ return this.holdDocumentModelRefs.get(uri.toString());
1018
+ }
1019
+ disposeDocumentRef(uri) {
1020
+ if (uri.scheme === 'diff') {
1021
+ const query = uri.getParsedQuery();
1022
+ this.doDisposeDocRef(new ide_core_common_1.URI(query.original));
1023
+ this.doDisposeDocRef(new ide_core_common_1.URI(query.modified));
1024
+ }
1025
+ else {
1026
+ this.doDisposeDocRef(uri);
1027
+ }
1028
+ }
1029
+ doDisposeDocRef(uri) {
1030
+ if (this.holdDocumentModelRefs.has(uri.toString())) {
1031
+ this.holdDocumentModelRefs.get(uri.toString()).dispose();
1032
+ this.holdDocumentModelRefs.delete(uri.toString());
1033
+ }
1034
+ }
1035
+ async displayResourceComponent(resource, options = {}) {
1036
+ const _resource = resource;
1037
+ const result = await this.resolveOpenType(resource, options);
1038
+ if (result) {
1039
+ const { activeOpenType, openTypes } = result;
1040
+ this.availableOpenTypes = openTypes;
1041
+ if (options.preserveFocus) {
1042
+ options.focus = false;
1043
+ }
1044
+ if (activeOpenType.type === 'code') {
1045
+ const documentRef = await this.getDocumentModelRef(resource.uri);
1046
+ await this.codeEditorReady.onceReady(async () => {
1047
+ var _a;
1048
+ await this.codeEditor.open(documentRef, options.range ? new monaco.Range(options.range.startLineNumber, options.range.startColumn, options.range.endLineNumber, options.range.endColumn) : undefined);
1049
+ setTimeout(() => {
1050
+ if (options.scrollTop) {
1051
+ this.codeEditor.monacoEditor.setScrollTop(options.scrollTop);
1052
+ }
1053
+ if (options.scrollLeft) {
1054
+ this.codeEditor.monacoEditor.setScrollLeft(options.scrollLeft);
1055
+ }
1056
+ }, 0);
1057
+ if (options.focus) {
1058
+ (_a = this._domNode) === null || _a === void 0 ? void 0 : _a.focus();
1059
+ // monaco 编辑器的 focus 多了一步检查,由于此时其实对应编辑器的 dom 的 display 为 none (需要等 React 下一次渲染才会改变为 block),
1060
+ // 会引起 document.activeElement !== editor.textArea.domNode,进而会导致focus失败
1061
+ // 需要等待真正 append 之后再
1062
+ const disposer = this.eventBus.on(types_1.CodeEditorDidVisibleEvent, (e) => {
1063
+ var _a;
1064
+ if (e.payload.groupName === this.name && e.payload.type === 'code') {
1065
+ disposer.dispose();
1066
+ // 此处必须多做一些检查以免不必要的 focus
1067
+ if (this.disposed) {
1068
+ return;
1069
+ }
1070
+ if (this !== this.workbenchEditorService.currentEditorGroup) {
1071
+ return;
1072
+ }
1073
+ if (this.currentEditor === this.codeEditor && ((_a = this.codeEditor.currentUri) === null || _a === void 0 ? void 0 : _a.isEqual(resource.uri))) {
1074
+ try {
1075
+ this.codeEditor.focus();
1076
+ }
1077
+ catch (e) {
1078
+ // noop
1079
+ }
1080
+ }
1081
+ }
1082
+ });
1083
+ }
1084
+ });
1085
+ // 可能在diff Editor中修改导致为脏
1086
+ if (documentRef.instance.dirty) {
1087
+ this.pinPreviewed(resource.uri);
1088
+ }
1089
+ }
1090
+ else if (activeOpenType.type === 'diff') {
1091
+ const diffResource = resource;
1092
+ const [original, modified] = await Promise.all([this.getDocumentModelRef(diffResource.metadata.original), this.getDocumentModelRef(diffResource.metadata.modified)]);
1093
+ await this.diffEditorReady.onceReady(async () => {
1094
+ var _a;
1095
+ await this.diffEditor.compare(original, modified, options, resource.uri);
1096
+ if (options.focus) {
1097
+ (_a = this._domNode) === null || _a === void 0 ? void 0 : _a.focus();
1098
+ // 理由见上方 codeEditor.focus 部分
1099
+ const disposer = this.eventBus.on(types_1.CodeEditorDidVisibleEvent, (e) => {
1100
+ if (e.payload.groupName === this.name && e.payload.type === 'diff') {
1101
+ disposer.dispose();
1102
+ if (this.disposed) {
1103
+ return;
1104
+ }
1105
+ if (this !== this.workbenchEditorService.currentEditorGroup) {
1106
+ return;
1107
+ }
1108
+ if (this.currentEditor === this.diffEditor.modifiedEditor) {
1109
+ try {
1110
+ this.diffEditor.focus();
1111
+ }
1112
+ catch (e) {
1113
+ // noop
1114
+ }
1115
+ }
1116
+ }
1117
+ });
1118
+ }
1119
+ });
1120
+ }
1121
+ else if (activeOpenType.type === 'component') {
1122
+ const component = this.editorComponentRegistry.getEditorComponent(activeOpenType.componentId);
1123
+ const initialProps = this.editorComponentRegistry.getEditorInitialProps(activeOpenType.componentId);
1124
+ if (!component) {
1125
+ throw new Error('Cannot find Editor Component with id: ' + activeOpenType.componentId);
1126
+ }
1127
+ else {
1128
+ this.activateComponentsProps.set(component, initialProps);
1129
+ if (component.renderMode === types_1.EditorComponentRenderMode.ONE_PER_RESOURCE) {
1130
+ const openedResources = this.activeComponents.get(component) || [];
1131
+ const index = openedResources.findIndex((r) => r.uri.toString() === resource.uri.toString());
1132
+ if (index === -1) {
1133
+ openedResources.push(resource);
1134
+ }
1135
+ this.activeComponents.set(component, openedResources);
1136
+ }
1137
+ else if (component.renderMode === types_1.EditorComponentRenderMode.ONE_PER_GROUP) {
1138
+ this.activeComponents.set(component, [resource]);
1139
+ }
1140
+ else if (component.renderMode === types_1.EditorComponentRenderMode.ONE_PER_WORKBENCH) {
1141
+ const promises = [];
1142
+ this.workbenchEditorService.editorGroups.forEach((g) => {
1143
+ if (g === this) {
1144
+ return;
1145
+ }
1146
+ const r = g.resources.find((r) => r.uri.isEqual(resource.uri));
1147
+ if (r) {
1148
+ promises.push(g.close(r.uri));
1149
+ }
1150
+ });
1151
+ await Promise.all(promises).catch((0, ide_core_common_1.getDebugLogger)().error);
1152
+ this.activeComponents.set(component, [resource]);
1153
+ }
1154
+ }
1155
+ // 打开非编辑器的component时需要手动触发
1156
+ this._onCurrentEditorCursorChange.fire({
1157
+ position: null,
1158
+ selectionLength: 0,
1159
+ });
1160
+ }
1161
+ else {
1162
+ return; // other type not handled
1163
+ }
1164
+ if (_resource !== this.currentResource) {
1165
+ throw new error_1.EditorTabChangedError(); // 在打开过程中已经改变了
1166
+ }
1167
+ this._currentOpenType = activeOpenType;
1168
+ this.notifyBodyChanged();
1169
+ if ((this._codeEditorPendingLayout && activeOpenType.type === 'code') || (this._diffEditorPendingLayout && activeOpenType.type === 'diff')) {
1170
+ this.doLayoutEditors();
1171
+ }
1172
+ this.cachedResourcesActiveOpenTypes.set(resource.uri.toString(), activeOpenType);
1173
+ }
1174
+ }
1175
+ async resolveOpenType(resource, options) {
1176
+ const openTypes = this.cachedResourcesOpenTypes.get(resource.uri.toString()) || await this.editorComponentRegistry.resolveEditorComponent(resource);
1177
+ const activeOpenType = findSuitableOpenType(openTypes, this.cachedResourcesActiveOpenTypes.get(resource.uri.toString()), options.forceOpenType);
1178
+ this.cachedResourcesOpenTypes.set(resource.uri.toString(), openTypes);
1179
+ return { activeOpenType, openTypes };
1180
+ }
1181
+ async close(uri, { treatAsNotCurrent, force } = {}) {
1182
+ const index = this.resources.findIndex((r) => r.uri.toString() === uri.toString());
1183
+ if (index !== -1) {
1184
+ const resource = this.resources[index];
1185
+ if (!force) {
1186
+ if (!await this.shouldClose(resource)) {
1187
+ return;
1188
+ }
1189
+ }
1190
+ this.resources.splice(index, 1);
1191
+ this.eventBus.fire(new types_1.EditorGroupCloseEvent({
1192
+ group: this,
1193
+ resource,
1194
+ }));
1195
+ if (this.previewURI && this.previewURI.isEqual(uri)) {
1196
+ this.previewURI = null;
1197
+ }
1198
+ // 优先打开用户打开历史中的uri,
1199
+ // 如果历史中的不可打开,打开去除当前关闭目标uri后相同位置的uri, 如果没有,则一直往前找到第一个可用的uri
1200
+ if (resource === this.currentResource && !treatAsNotCurrent) {
1201
+ let nextUri;
1202
+ while (this.resourceOpenHistory.length > 0) {
1203
+ if (this.resources.findIndex((r) => r.uri === this.resourceOpenHistory[this.resourceOpenHistory.length - 1]) !== -1) {
1204
+ nextUri = this.resourceOpenHistory.pop();
1205
+ break;
1206
+ }
1207
+ else {
1208
+ this.resourceOpenHistory.pop();
1209
+ }
1210
+ }
1211
+ if (nextUri) {
1212
+ this.open(nextUri);
1213
+ }
1214
+ else {
1215
+ let i = index;
1216
+ while (i > 0 && !this.resources[i]) {
1217
+ i--;
1218
+ }
1219
+ if (this.resources[i]) {
1220
+ this.open(this.resources[i].uri);
1221
+ }
1222
+ else {
1223
+ this.backToEmpty();
1224
+ }
1225
+ }
1226
+ }
1227
+ else {
1228
+ this.notifyTabChanged();
1229
+ }
1230
+ for (const resources of this.activeComponents.values()) {
1231
+ const i = resources.indexOf(resource);
1232
+ if (i !== -1) {
1233
+ resources.splice(i, 1);
1234
+ }
1235
+ }
1236
+ this.disposeDocumentRef(uri);
1237
+ }
1238
+ if (this.resources.length === 0) {
1239
+ if (this.grid.parent) {
1240
+ // 当前不是最后一个 editor Group
1241
+ this.dispose();
1242
+ }
1243
+ this.availableOpenTypes = [];
1244
+ }
1245
+ }
1246
+ async shouldClose(resource) {
1247
+ // TODO: 自定义打开方式如果存在保存能力,也要能阻止关闭
1248
+ const openedResources = this.workbenchEditorService.editorGroups.map((group) => group.resources);
1249
+ if (!await this.resourceService.shouldCloseResource(resource, openedResources)) {
1250
+ return false;
1251
+ }
1252
+ else {
1253
+ let count = 0;
1254
+ for (const group of openedResources) {
1255
+ for (const res of group) {
1256
+ if (res.uri.isEqual(resource.uri)) {
1257
+ count++;
1258
+ if (count >= 2) {
1259
+ break;
1260
+ }
1261
+ }
1262
+ }
1263
+ }
1264
+ if (count <= 1) {
1265
+ this.resourceService.disposeResource(resource);
1266
+ }
1267
+ return true;
1268
+ }
1269
+ }
1270
+ backToEmpty() {
1271
+ const oldOpenType = this._currentOpenType;
1272
+ const oldResource = this._currentResource;
1273
+ this._currentResource = null;
1274
+ this._currentOpenType = null;
1275
+ this.notifyTabChanged();
1276
+ this.notifyBodyChanged();
1277
+ this._currentOrPreviousFocusedEditor = null;
1278
+ this._onDidEditorFocusChange.fire();
1279
+ // 关闭最后一个时,应该发送一个 EditorGroupChangeEvent
1280
+ this.eventBus.fire(new types_1.EditorGroupChangeEvent({
1281
+ group: this,
1282
+ newOpenType: this.currentOpenType,
1283
+ newResource: this.currentResource,
1284
+ oldOpenType,
1285
+ oldResource,
1286
+ }));
1287
+ }
1288
+ /**
1289
+ * 关闭全部
1290
+ */
1291
+ async closeAll() {
1292
+ for (const resource of this.resources) {
1293
+ if (!await this.shouldClose(resource)) {
1294
+ return;
1295
+ }
1296
+ }
1297
+ const closed = this.resources.splice(0, this.resources.length);
1298
+ closed.forEach((resource) => {
1299
+ this.clearResourceOnClose(resource);
1300
+ });
1301
+ this.activeComponents.clear();
1302
+ if (this.workbenchEditorService.editorGroups.length > 1) {
1303
+ this.dispose();
1304
+ }
1305
+ this.previewURI = null;
1306
+ this.backToEmpty();
1307
+ }
1308
+ /**
1309
+ * 关闭已保存(非dirty)
1310
+ */
1311
+ async closeSaved() {
1312
+ const saved = this.resources.filter((r) => {
1313
+ const decoration = this.resourceService.getResourceDecoration(r.uri);
1314
+ if (!decoration || !decoration.dirty) {
1315
+ return true;
1316
+ }
1317
+ });
1318
+ for (const resource of saved) {
1319
+ if (!await this.shouldClose(resource)) {
1320
+ return;
1321
+ }
1322
+ }
1323
+ for (const resource of saved) {
1324
+ await this.close(resource.uri);
1325
+ }
1326
+ }
1327
+ /**
1328
+ * 关闭向右的tab
1329
+ * @param uri
1330
+ */
1331
+ async closeToRight(uri) {
1332
+ const index = this.resources.findIndex((r) => r.uri.toString() === uri.toString());
1333
+ if (index !== -1) {
1334
+ const resourcesToClose = this.resources.slice(index + 1);
1335
+ for (const resource of resourcesToClose) {
1336
+ if (!await this.shouldClose(resource)) {
1337
+ return;
1338
+ }
1339
+ }
1340
+ this.resources.splice(index + 1);
1341
+ for (const resource of resourcesToClose) {
1342
+ this.clearResourceOnClose(resource);
1343
+ }
1344
+ this.open(uri);
1345
+ }
1346
+ }
1347
+ clearResourceOnClose(resource) {
1348
+ this.eventBus.fire(new types_1.EditorGroupCloseEvent({
1349
+ group: this,
1350
+ resource,
1351
+ }));
1352
+ for (const resources of this.activeComponents.values()) {
1353
+ const i = resources.indexOf(resource);
1354
+ if (i !== -1) {
1355
+ resources.splice(i, 1);
1356
+ }
1357
+ }
1358
+ }
1359
+ async closeOthers(uri) {
1360
+ const index = this.resources.findIndex((r) => r.uri.toString() === uri.toString());
1361
+ if (index !== -1) {
1362
+ const resourcesToClose = this.resources.filter((v, i) => i !== index);
1363
+ for (const resource of resourcesToClose) {
1364
+ if (!await this.shouldClose(resource)) {
1365
+ return;
1366
+ }
1367
+ }
1368
+ this.resources = [this.resources[index]];
1369
+ for (const resource of resourcesToClose) {
1370
+ this.clearResourceOnClose(resource);
1371
+ }
1372
+ await this.open(uri);
1373
+ }
1374
+ }
1375
+ /**
1376
+ * 当前打开的resource
1377
+ */
1378
+ get currentResource() {
1379
+ return this._currentResource;
1380
+ }
1381
+ get currentOpenType() {
1382
+ return this._currentOpenType;
1383
+ }
1384
+ async changeOpenType(type) {
1385
+ if (!this.currentResource) {
1386
+ return;
1387
+ }
1388
+ if (openTypeSimilar(type, this.currentOpenType)) {
1389
+ return;
1390
+ }
1391
+ const oldOpenType = this.currentOpenType;
1392
+ await this.displayResourceComponent(this.currentResource, { forceOpenType: type });
1393
+ this.eventBus.fire(new types_1.EditorGroupChangeEvent({
1394
+ group: this,
1395
+ newOpenType: this.currentOpenType,
1396
+ newResource: this.currentResource,
1397
+ oldOpenType,
1398
+ oldResource: this.currentResource,
1399
+ }));
1400
+ }
1401
+ /**
1402
+ * 拖拽drop方法
1403
+ */
1404
+ async dropUri(uri, position, sourceGroup, targetResource) {
1405
+ if (position !== types_1.DragOverPosition.CENTER) {
1406
+ await this.split((0, common_1.getSplitActionFromDragDrop)(position), uri, { preview: false, focus: true });
1407
+ }
1408
+ else {
1409
+ // 扔在本体或者tab上
1410
+ if (!targetResource) {
1411
+ await this.open(uri, { preview: false, focus: true });
1412
+ }
1413
+ else {
1414
+ const targetIndex = this.resources.indexOf(targetResource);
1415
+ if (targetIndex === -1) {
1416
+ await this.open(uri, { preview: false, focus: true });
1417
+ }
1418
+ else {
1419
+ const sourceIndex = this.resources.findIndex((resource) => resource.uri.toString() === uri.toString());
1420
+ if (sourceIndex === -1) {
1421
+ await this.open(uri, {
1422
+ index: targetIndex,
1423
+ preview: false,
1424
+ });
1425
+ }
1426
+ else {
1427
+ // just move
1428
+ const sourceResource = this.resources[sourceIndex];
1429
+ if (sourceIndex > targetIndex) {
1430
+ this.resources.splice(sourceIndex, 1);
1431
+ this.resources.splice(targetIndex, 0, sourceResource);
1432
+ await this.open(uri, { preview: false });
1433
+ }
1434
+ else if (sourceIndex < targetIndex) {
1435
+ this.resources.splice(targetIndex + 1, 0, sourceResource);
1436
+ this.resources.splice(sourceIndex, 1);
1437
+ await this.open(uri, { preview: false });
1438
+ }
1439
+ }
1440
+ }
1441
+ }
1442
+ }
1443
+ if (sourceGroup) {
1444
+ if (sourceGroup !== this) {
1445
+ // 从其他group拖动过来
1446
+ await sourceGroup.close(uri);
1447
+ }
1448
+ else if (position !== types_1.DragOverPosition.CENTER) {
1449
+ // split行为
1450
+ await this.close(uri);
1451
+ }
1452
+ }
1453
+ }
1454
+ gainFocus() {
1455
+ this.workbenchEditorService.setCurrentGroup(this);
1456
+ }
1457
+ focus() {
1458
+ this.gainFocus();
1459
+ if (this.currentOpenType && this.currentOpenType.type === 'code') {
1460
+ this.codeEditor.focus();
1461
+ }
1462
+ if (this.currentOpenType && this.currentOpenType.type === 'diff') {
1463
+ this.diffEditor.focus();
1464
+ }
1465
+ }
1466
+ dispose() {
1467
+ this.grid.dispose();
1468
+ this.workbenchEditorService.removeGroup(this);
1469
+ super.dispose();
1470
+ this.codeEditor && this.codeEditor.dispose();
1471
+ this.diffEditor && this.diffEditor.dispose();
1472
+ this.toDispose.forEach((disposable) => disposable.dispose());
1473
+ this.eventBus.fire(new types_1.EditorGroupDisposeEvent({
1474
+ group: this,
1475
+ }));
1476
+ }
1477
+ getState() {
1478
+ const couldRevive = (r) => {
1479
+ return !!(r.supportsRevive && !r.deleted);
1480
+ };
1481
+ const uris = this.resources.filter(couldRevive).map((r) => r.uri.toString());
1482
+ return {
1483
+ uris,
1484
+ current: this.currentResource && couldRevive(this.currentResource) ? this.currentResource.uri.toString() : undefined,
1485
+ previewIndex: this.previewURI ? uris.indexOf(this.previewURI.toString()) : -1,
1486
+ };
1487
+ }
1488
+ isCodeEditorMode() {
1489
+ return this.currentOpenType && this.currentOpenType.type === 'code';
1490
+ }
1491
+ isDiffEditorMode() {
1492
+ return this.currentOpenType && this.currentOpenType.type === 'diff';
1493
+ }
1494
+ isComponentMode() {
1495
+ return this.currentOpenType && this.currentOpenType.type === 'component';
1496
+ }
1497
+ async restoreState(state) {
1498
+ this._restoringState = true;
1499
+ this.previewURI = state.uris[state.previewIndex] ? null : new ide_core_common_1.URI(state.uris[state.previewIndex]);
1500
+ for (const uri of state.uris) {
1501
+ await this.doOpen(new ide_core_common_1.URI(uri), { disableNavigate: true, backend: true, preview: false, deletedPolicy: 'skip' });
1502
+ }
1503
+ let targetUri;
1504
+ if (state.current) {
1505
+ targetUri = new ide_core_common_1.URI(state.current);
1506
+ }
1507
+ else {
1508
+ if (state.uris.length > 0) {
1509
+ targetUri = new ide_core_common_1.URI(state.uris[state.uris.length - 1]);
1510
+ }
1511
+ }
1512
+ if (targetUri) {
1513
+ if (!await this.open(targetUri, { deletedPolicy: 'skip' })) {
1514
+ if (this.resources[0]) {
1515
+ await this.open(this.resources[0].uri);
1516
+ }
1517
+ }
1518
+ }
1519
+ this._restoringState = false;
1520
+ this.notifyTabChanged();
1521
+ }
1522
+ async saveAll(includeUntitled, reason) {
1523
+ for (const r of this.resources) {
1524
+ // 不保存无标题文件
1525
+ if (!includeUntitled && r.uri.scheme === ide_core_common_2.Schemas.untitled) {
1526
+ continue;
1527
+ }
1528
+ await this.saveResource(r, reason);
1529
+ }
1530
+ }
1531
+ async saveResource(resource, reason = common_1.SaveReason.Manual) {
1532
+ // 尝试使用 openType 提供的保存方法保存
1533
+ if (await this.saveByOpenType(resource, reason)) {
1534
+ return;
1535
+ }
1536
+ // 否则使用 document 进行保存 (如果有)
1537
+ const docRef = this.documentModelManager.getModelReference(resource.uri);
1538
+ if (docRef) {
1539
+ if (docRef.instance.dirty) {
1540
+ await docRef.instance.save(undefined, reason);
1541
+ }
1542
+ docRef.dispose();
1543
+ }
1544
+ }
1545
+ async saveByOpenType(resource, reason) {
1546
+ const openType = this.cachedResourcesActiveOpenTypes.get(resource.uri.toString());
1547
+ if (openType && openType.saveResource) {
1548
+ try {
1549
+ await openType.saveResource(resource, reason);
1550
+ return true;
1551
+ }
1552
+ catch (e) {
1553
+ this.logger.error(e);
1554
+ }
1555
+ }
1556
+ return false;
1557
+ }
1558
+ async saveCurrent(reason = common_1.SaveReason.Manual) {
1559
+ const resource = this.currentResource;
1560
+ if (!resource) {
1561
+ return;
1562
+ }
1563
+ if (await this.saveByOpenType(resource, reason)) {
1564
+ return;
1565
+ }
1566
+ if (this.currentEditor) {
1567
+ return this.currentEditor.save();
1568
+ }
1569
+ }
1570
+ hasDirty() {
1571
+ for (const r of this.resources) {
1572
+ const docRef = this.documentModelManager.getModelReference(r.uri);
1573
+ if (docRef) {
1574
+ const isDirty = docRef.instance.dirty;
1575
+ docRef.dispose();
1576
+ if (isDirty) {
1577
+ return true;
1578
+ }
1579
+ }
1580
+ }
1581
+ return false;
1582
+ }
1583
+ componentUndo() {
1584
+ const currentOpenType = this.currentOpenType;
1585
+ if (currentOpenType === null || currentOpenType === void 0 ? void 0 : currentOpenType.undo) {
1586
+ currentOpenType.undo(this.currentResource);
1587
+ }
1588
+ }
1589
+ componentRedo() {
1590
+ const currentOpenType = this.currentOpenType;
1591
+ if (currentOpenType === null || currentOpenType === void 0 ? void 0 : currentOpenType.redo) {
1592
+ currentOpenType.redo(this.currentResource);
1593
+ }
1594
+ }
1595
+ /**
1596
+ * 防止作为参数被抛入插件进程时出错
1597
+ */
1598
+ toJSON() {
1599
+ return {
1600
+ name: this.name,
1601
+ };
1602
+ }
1603
+ };
1604
+ (0, tslib_1.__decorate)([
1605
+ (0, di_1.Autowired)(),
1606
+ (0, tslib_1.__metadata)("design:type", common_1.EditorCollectionService)
1607
+ ], EditorGroup.prototype, "collectionService", void 0);
1608
+ (0, tslib_1.__decorate)([
1609
+ (0, di_1.Autowired)(),
1610
+ (0, tslib_1.__metadata)("design:type", common_1.ResourceService)
1611
+ ], EditorGroup.prototype, "resourceService", void 0);
1612
+ (0, tslib_1.__decorate)([
1613
+ (0, di_1.Autowired)(),
1614
+ (0, tslib_1.__metadata)("design:type", types_1.EditorComponentRegistry)
1615
+ ], EditorGroup.prototype, "editorComponentRegistry", void 0);
1616
+ (0, tslib_1.__decorate)([
1617
+ (0, di_1.Autowired)(common_1.WorkbenchEditorService),
1618
+ (0, tslib_1.__metadata)("design:type", WorkbenchEditorServiceImpl)
1619
+ ], EditorGroup.prototype, "workbenchEditorService", void 0);
1620
+ (0, tslib_1.__decorate)([
1621
+ (0, di_1.Autowired)(types_2.IEditorDocumentModelService),
1622
+ (0, tslib_1.__metadata)("design:type", Object)
1623
+ ], EditorGroup.prototype, "documentModelManager", void 0);
1624
+ (0, tslib_1.__decorate)([
1625
+ (0, di_1.Autowired)(ide_core_common_1.CommandService),
1626
+ (0, tslib_1.__metadata)("design:type", Object)
1627
+ ], EditorGroup.prototype, "commands", void 0);
1628
+ (0, tslib_1.__decorate)([
1629
+ (0, di_1.Autowired)(ide_core_browser_1.PreferenceService),
1630
+ (0, tslib_1.__metadata)("design:type", Object)
1631
+ ], EditorGroup.prototype, "preferenceService", void 0);
1632
+ (0, tslib_1.__decorate)([
1633
+ (0, di_1.Autowired)(ide_core_browser_1.RecentFilesManager),
1634
+ (0, tslib_1.__metadata)("design:type", ide_core_browser_1.RecentFilesManager)
1635
+ ], EditorGroup.prototype, "recentFilesManager", void 0);
1636
+ (0, tslib_1.__decorate)([
1637
+ (0, di_1.Autowired)(ide_overlay_1.IMessageService),
1638
+ (0, tslib_1.__metadata)("design:type", Object)
1639
+ ], EditorGroup.prototype, "messageService", void 0);
1640
+ (0, tslib_1.__decorate)([
1641
+ (0, di_1.Autowired)(ide_core_common_1.IReporterService),
1642
+ (0, tslib_1.__metadata)("design:type", Object)
1643
+ ], EditorGroup.prototype, "reporterService", void 0);
1644
+ (0, tslib_1.__decorate)([
1645
+ (0, di_1.Autowired)(ide_core_browser_1.AppConfig),
1646
+ (0, tslib_1.__metadata)("design:type", Object)
1647
+ ], EditorGroup.prototype, "config", void 0);
1648
+ (0, tslib_1.__decorate)([
1649
+ (0, di_1.Autowired)(ide_core_browser_1.IOpenerService),
1650
+ (0, tslib_1.__metadata)("design:type", Object)
1651
+ ], EditorGroup.prototype, "openerService", void 0);
1652
+ (0, tslib_1.__decorate)([
1653
+ (0, di_1.Autowired)(ide_core_common_1.ILogger),
1654
+ (0, tslib_1.__metadata)("design:type", Object)
1655
+ ], EditorGroup.prototype, "logger", void 0);
1656
+ (0, tslib_1.__decorate)([
1657
+ (0, ide_core_common_1.OnEvent)(common_1.ResourceDecorationChangeEvent),
1658
+ (0, tslib_1.__metadata)("design:type", Function),
1659
+ (0, tslib_1.__metadata)("design:paramtypes", [common_1.ResourceDecorationChangeEvent]),
1660
+ (0, tslib_1.__metadata)("design:returntype", void 0)
1661
+ ], EditorGroup.prototype, "onResourceDecorationChangeEvent", null);
1662
+ (0, tslib_1.__decorate)([
1663
+ (0, ide_core_common_1.OnEvent)(types_1.ResourceOpenTypeChangedEvent),
1664
+ (0, tslib_1.__metadata)("design:type", Function),
1665
+ (0, tslib_1.__metadata)("design:paramtypes", [types_1.ResourceOpenTypeChangedEvent]),
1666
+ (0, tslib_1.__metadata)("design:returntype", void 0)
1667
+ ], EditorGroup.prototype, "oResourceOpenTypeChangedEvent", null);
1668
+ EditorGroup = (0, tslib_1.__decorate)([
1669
+ (0, di_1.Injectable)({ multiple: true }),
1670
+ (0, tslib_1.__metadata)("design:paramtypes", [String])
1671
+ ], EditorGroup);
1672
+ exports.EditorGroup = EditorGroup;
1673
+ function findSuitableOpenType(currentAvailable, prev, forceOpenType) {
1674
+ if (forceOpenType) {
1675
+ return currentAvailable.find((p) => {
1676
+ return openTypeSimilar(p, forceOpenType);
1677
+ }) || currentAvailable[0];
1678
+ }
1679
+ else if (prev) {
1680
+ return currentAvailable.find((p) => {
1681
+ return openTypeSimilar(p, prev);
1682
+ }) || currentAvailable[0];
1683
+ }
1684
+ return currentAvailable[0];
1685
+ }
1686
+ function openTypeSimilar(a, b) {
1687
+ return a.type === b.type && (a.type !== 'component' || a.componentId === b.componentId);
1688
+ }
1689
+ //# sourceMappingURL=workbench-editor.service.js.map