@opensumi/ide-notebook 3.4.5-next-1730119322.0
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.
- package/README.md +33 -0
- package/lib/browser/index.d.ts +12 -0
- package/lib/browser/index.d.ts.map +1 -0
- package/lib/browser/index.js +49 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/kernel-panel/collapse/collapse-content.d.ts +10 -0
- package/lib/browser/kernel-panel/collapse/collapse-content.d.ts.map +1 -0
- package/lib/browser/kernel-panel/collapse/collapse-content.js +27 -0
- package/lib/browser/kernel-panel/collapse/collapse-content.js.map +1 -0
- package/lib/browser/kernel-panel/collapse/icon.d.ts +7 -0
- package/lib/browser/kernel-panel/collapse/icon.d.ts.map +1 -0
- package/lib/browser/kernel-panel/collapse/icon.js +64 -0
- package/lib/browser/kernel-panel/collapse/icon.js.map +1 -0
- package/lib/browser/kernel-panel/collapse/index.d.ts +5 -0
- package/lib/browser/kernel-panel/collapse/index.d.ts.map +1 -0
- package/lib/browser/kernel-panel/collapse/index.js +66 -0
- package/lib/browser/kernel-panel/collapse/index.js.map +1 -0
- package/lib/browser/kernel-panel/collapse/index.less +95 -0
- package/lib/browser/kernel-panel/collapse/kernel-collapse-content-item.d.ts +9 -0
- package/lib/browser/kernel-panel/collapse/kernel-collapse-content-item.d.ts.map +1 -0
- package/lib/browser/kernel-panel/collapse/kernel-collapse-content-item.js +41 -0
- package/lib/browser/kernel-panel/collapse/kernel-collapse-content-item.js.map +1 -0
- package/lib/browser/kernel-panel/collapse/kernel-collapse-content.d.ts +10 -0
- package/lib/browser/kernel-panel/collapse/kernel-collapse-content.d.ts.map +1 -0
- package/lib/browser/kernel-panel/collapse/kernel-collapse-content.js +4 -0
- package/lib/browser/kernel-panel/collapse/kernel-collapse-content.js.map +1 -0
- package/lib/browser/kernel-panel/collapse/page-collapse-content.d.ts +10 -0
- package/lib/browser/kernel-panel/collapse/page-collapse-content.d.ts.map +1 -0
- package/lib/browser/kernel-panel/collapse/page-collapse-content.js +32 -0
- package/lib/browser/kernel-panel/collapse/page-collapse-content.js.map +1 -0
- package/lib/browser/kernel-panel/index.d.ts +5 -0
- package/lib/browser/kernel-panel/index.d.ts.map +1 -0
- package/lib/browser/kernel-panel/index.js +5 -0
- package/lib/browser/kernel-panel/index.js.map +1 -0
- package/lib/browser/kernel-panel/index.less +20 -0
- package/lib/browser/kernel-panel/kernel-panel-view.d.ts +4 -0
- package/lib/browser/kernel-panel/kernel-panel-view.d.ts.map +1 -0
- package/lib/browser/kernel-panel/kernel-panel-view.js +72 -0
- package/lib/browser/kernel-panel/kernel-panel-view.js.map +1 -0
- package/lib/browser/kernel-panel/kernel.panel.color.tokens.d.ts +2 -0
- package/lib/browser/kernel-panel/kernel.panel.color.tokens.d.ts.map +1 -0
- package/lib/browser/kernel-panel/kernel.panel.color.tokens.js +10 -0
- package/lib/browser/kernel-panel/kernel.panel.color.tokens.js.map +1 -0
- package/lib/browser/kernel-panel/kernel.panel.contribution.d.ts +7 -0
- package/lib/browser/kernel-panel/kernel.panel.contribution.d.ts.map +1 -0
- package/lib/browser/kernel-panel/kernel.panel.contribution.js +32 -0
- package/lib/browser/kernel-panel/kernel.panel.contribution.js.map +1 -0
- package/lib/browser/kernel-panel/kernel.panel.protocol.d.ts +25 -0
- package/lib/browser/kernel-panel/kernel.panel.protocol.d.ts.map +1 -0
- package/lib/browser/kernel-panel/kernel.panel.protocol.js +7 -0
- package/lib/browser/kernel-panel/kernel.panel.protocol.js.map +1 -0
- package/lib/browser/libro/editor/editor-contribution.d.ts +13 -0
- package/lib/browser/libro/editor/editor-contribution.d.ts.map +1 -0
- package/lib/browser/libro/editor/editor-contribution.js +30 -0
- package/lib/browser/libro/editor/editor-contribution.js.map +1 -0
- package/lib/browser/libro/editor/index.less +48 -0
- package/lib/browser/libro/editor/keybind-handler.d.ts +14 -0
- package/lib/browser/libro/editor/keybind-handler.d.ts.map +1 -0
- package/lib/browser/libro/editor/keybind-handler.js +132 -0
- package/lib/browser/libro/editor/keybind-handler.js.map +1 -0
- package/lib/browser/libro/editor/module.d.ts +3 -0
- package/lib/browser/libro/editor/module.d.ts.map +1 -0
- package/lib/browser/libro/editor/module.js +22 -0
- package/lib/browser/libro/editor/module.js.map +1 -0
- package/lib/browser/libro/editor/opensumi-editor.d.ts +251 -0
- package/lib/browser/libro/editor/opensumi-editor.d.ts.map +1 -0
- package/lib/browser/libro/editor/opensumi-editor.js +567 -0
- package/lib/browser/libro/editor/opensumi-editor.js.map +1 -0
- package/lib/browser/libro/index.d.ts +4 -0
- package/lib/browser/libro/index.d.ts.map +1 -0
- package/lib/browser/libro/index.js +4 -0
- package/lib/browser/libro/index.js.map +1 -0
- package/lib/browser/libro/libro-opensumi-content-contribution.d.ts +9 -0
- package/lib/browser/libro/libro-opensumi-content-contribution.d.ts.map +1 -0
- package/lib/browser/libro/libro-opensumi-content-contribution.js +71 -0
- package/lib/browser/libro/libro-opensumi-content-contribution.js.map +1 -0
- package/lib/browser/libro/libro-opensumi-save-content-contribution.d.ts +10 -0
- package/lib/browser/libro/libro-opensumi-save-content-contribution.d.ts.map +1 -0
- package/lib/browser/libro/libro-opensumi-save-content-contribution.js +51 -0
- package/lib/browser/libro/libro-opensumi-save-content-contribution.js.map +1 -0
- package/lib/browser/libro/mana-module.d.ts +3 -0
- package/lib/browser/libro/mana-module.d.ts.map +1 -0
- package/lib/browser/libro/mana-module.js +8 -0
- package/lib/browser/libro/mana-module.js.map +1 -0
- package/lib/browser/libro-keybind-contribution.d.ts +19 -0
- package/lib/browser/libro-keybind-contribution.d.ts.map +1 -0
- package/lib/browser/libro-keybind-contribution.js +142 -0
- package/lib/browser/libro-keybind-contribution.js.map +1 -0
- package/lib/browser/libro-opener.d.ts +12 -0
- package/lib/browser/libro-opener.d.ts.map +1 -0
- package/lib/browser/libro-opener.js +83 -0
- package/lib/browser/libro-opener.js.map +1 -0
- package/lib/browser/libro.color.tokens.d.ts +2 -0
- package/lib/browser/libro.color.tokens.d.ts.map +1 -0
- package/lib/browser/libro.color.tokens.js +9 -0
- package/lib/browser/libro.color.tokens.js.map +1 -0
- package/lib/browser/libro.command.d.ts +6 -0
- package/lib/browser/libro.command.d.ts.map +1 -0
- package/lib/browser/libro.command.js +66 -0
- package/lib/browser/libro.command.js.map +1 -0
- package/lib/browser/libro.contribution.d.ts +29 -0
- package/lib/browser/libro.contribution.d.ts.map +1 -0
- package/lib/browser/libro.contribution.js +140 -0
- package/lib/browser/libro.contribution.js.map +1 -0
- package/lib/browser/libro.module.less +40 -0
- package/lib/browser/libro.protocol.d.ts +3 -0
- package/lib/browser/libro.protocol.d.ts.map +1 -0
- package/lib/browser/libro.protocol.js +3 -0
- package/lib/browser/libro.protocol.js.map +1 -0
- package/lib/browser/libro.service.d.ts +24 -0
- package/lib/browser/libro.service.d.ts.map +1 -0
- package/lib/browser/libro.service.js +68 -0
- package/lib/browser/libro.service.js.map +1 -0
- package/lib/browser/libro.view.d.ts +3 -0
- package/lib/browser/libro.view.d.ts.map +1 -0
- package/lib/browser/libro.view.js +54 -0
- package/lib/browser/libro.view.js.map +1 -0
- package/lib/browser/libro.view.tracker.d.ts +6 -0
- package/lib/browser/libro.view.tracker.d.ts.map +1 -0
- package/lib/browser/libro.view.tracker.js +28 -0
- package/lib/browser/libro.view.tracker.js.map +1 -0
- package/lib/browser/mana/index.d.ts +8 -0
- package/lib/browser/mana/index.d.ts.map +1 -0
- package/lib/browser/mana/index.js +15 -0
- package/lib/browser/mana/index.js.map +1 -0
- package/lib/browser/notebook-document-content-provider.d.ts +22 -0
- package/lib/browser/notebook-document-content-provider.d.ts.map +1 -0
- package/lib/browser/notebook-document-content-provider.js +80 -0
- package/lib/browser/notebook-document-content-provider.js.map +1 -0
- package/lib/browser/notebook.service.d.ts +27 -0
- package/lib/browser/notebook.service.d.ts.map +1 -0
- package/lib/browser/notebook.service.js +186 -0
- package/lib/browser/notebook.service.js.map +1 -0
- package/lib/browser/toc/index.d.ts +4 -0
- package/lib/browser/toc/index.d.ts.map +1 -0
- package/lib/browser/toc/index.js +4 -0
- package/lib/browser/toc/index.js.map +1 -0
- package/lib/browser/toc/toc.contribution.d.ts +6 -0
- package/lib/browser/toc/toc.contribution.d.ts.map +1 -0
- package/lib/browser/toc/toc.contribution.js +25 -0
- package/lib/browser/toc/toc.contribution.js.map +1 -0
- package/lib/browser/toc/toc.module.less +23 -0
- package/lib/browser/toc/toc.panel.color.tokens.d.ts +2 -0
- package/lib/browser/toc/toc.panel.color.tokens.d.ts.map +1 -0
- package/lib/browser/toc/toc.panel.color.tokens.js +6 -0
- package/lib/browser/toc/toc.panel.color.tokens.js.map +1 -0
- package/lib/browser/toc/toc.panel.d.ts +6 -0
- package/lib/browser/toc/toc.panel.d.ts.map +1 -0
- package/lib/browser/toc/toc.panel.js +61 -0
- package/lib/browser/toc/toc.panel.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/package.json +42 -0
- package/src/browser/index.ts +44 -0
- package/src/browser/kernel-panel/collapse/collapse-content.tsx +46 -0
- package/src/browser/kernel-panel/collapse/icon.tsx +171 -0
- package/src/browser/kernel-panel/collapse/index.less +95 -0
- package/src/browser/kernel-panel/collapse/index.tsx +111 -0
- package/src/browser/kernel-panel/collapse/kernel-collapse-content-item.tsx +77 -0
- package/src/browser/kernel-panel/collapse/kernel-collapse-content.tsx +17 -0
- package/src/browser/kernel-panel/collapse/page-collapse-content.tsx +53 -0
- package/src/browser/kernel-panel/index.less +20 -0
- package/src/browser/kernel-panel/index.ts +4 -0
- package/src/browser/kernel-panel/kernel-panel-view.tsx +104 -0
- package/src/browser/kernel-panel/kernel.panel.color.tokens.ts +39 -0
- package/src/browser/kernel-panel/kernel.panel.contribution.ts +32 -0
- package/src/browser/kernel-panel/kernel.panel.protocol.ts +24 -0
- package/src/browser/libro/editor/editor-contribution.ts +41 -0
- package/src/browser/libro/editor/index.less +48 -0
- package/src/browser/libro/editor/keybind-handler.ts +133 -0
- package/src/browser/libro/editor/module.ts +30 -0
- package/src/browser/libro/editor/opensumi-editor.ts +826 -0
- package/src/browser/libro/index.ts +3 -0
- package/src/browser/libro/libro-opensumi-content-contribution.ts +63 -0
- package/src/browser/libro/libro-opensumi-save-content-contribution.ts +43 -0
- package/src/browser/libro/mana-module.ts +9 -0
- package/src/browser/libro-keybind-contribution.ts +147 -0
- package/src/browser/libro-opener.ts +96 -0
- package/src/browser/libro.color.tokens.ts +32 -0
- package/src/browser/libro.command.ts +63 -0
- package/src/browser/libro.contribution.tsx +189 -0
- package/src/browser/libro.module.less +40 -0
- package/src/browser/libro.protocol.ts +2 -0
- package/src/browser/libro.service.ts +85 -0
- package/src/browser/libro.view.tracker.ts +18 -0
- package/src/browser/libro.view.tsx +62 -0
- package/src/browser/mana/index.ts +20 -0
- package/src/browser/notebook-document-content-provider.ts +100 -0
- package/src/browser/notebook.service.ts +195 -0
- package/src/browser/toc/index.ts +3 -0
- package/src/browser/toc/toc.contribution.ts +24 -0
- package/src/browser/toc/toc.module.less +23 -0
- package/src/browser/toc/toc.panel.color.tokens.ts +11 -0
- package/src/browser/toc/toc.panel.tsx +66 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,826 @@
|
|
|
1
|
+
// eslint-disable-next-line import/order
|
|
2
|
+
import type {
|
|
3
|
+
CodeEditorFactory,
|
|
4
|
+
CompletionProvider,
|
|
5
|
+
EditorState,
|
|
6
|
+
ICoordinate,
|
|
7
|
+
IEditor,
|
|
8
|
+
IEditorConfig,
|
|
9
|
+
IEditorOptions,
|
|
10
|
+
IModel,
|
|
11
|
+
IModelContentChange,
|
|
12
|
+
IPosition,
|
|
13
|
+
IRange,
|
|
14
|
+
SearchMatch,
|
|
15
|
+
TooltipProvider,
|
|
16
|
+
} from '@difizen/libro-code-editor';
|
|
17
|
+
import { defaultConfig } from '@difizen/libro-code-editor';
|
|
18
|
+
import { MIME } from '@difizen/libro-common';
|
|
19
|
+
import { EditorStateFactory, IEditorStateOptions } from '@difizen/libro-jupyter/noeditor';
|
|
20
|
+
import {
|
|
21
|
+
CommandRegistry,
|
|
22
|
+
Deferred,
|
|
23
|
+
Disposable,
|
|
24
|
+
DisposableCollection,
|
|
25
|
+
Emitter,
|
|
26
|
+
ThemeService,
|
|
27
|
+
getOrigin,
|
|
28
|
+
inject,
|
|
29
|
+
transient,
|
|
30
|
+
watch,
|
|
31
|
+
} from '@difizen/mana-app';
|
|
32
|
+
|
|
33
|
+
import { Injector } from '@opensumi/di';
|
|
34
|
+
import { IEventBus, URI, uuid } from '@opensumi/ide-core-common';
|
|
35
|
+
import { EditorCollectionService, IEditorDocumentModelRef, ICodeEditor as IOpensumiEditor } from '@opensumi/ide-editor';
|
|
36
|
+
import { IEditorDocumentModelService } from '@opensumi/ide-editor/lib/browser/doc-model/types';
|
|
37
|
+
import * as monacoTypes from '@opensumi/ide-monaco';
|
|
38
|
+
import { ICodeEditor as IMonacoCodeEditor } from '@opensumi/ide-monaco/lib/browser/monaco-api/types';
|
|
39
|
+
import { Selection } from '@opensumi/monaco-editor-core';
|
|
40
|
+
import { Range as MonacoRange } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/range';
|
|
41
|
+
|
|
42
|
+
import { OpensumiInjector } from '../../mana';
|
|
43
|
+
|
|
44
|
+
import type { LSPProvider } from '@difizen/libro-lsp';
|
|
45
|
+
import type { IStandaloneEditorConstructionOptions as MonacoEditorOptions } from '@opensumi/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor';
|
|
46
|
+
import './index.less';
|
|
47
|
+
|
|
48
|
+
export interface LibroOpensumiEditorConfig extends IEditorConfig {
|
|
49
|
+
/**
|
|
50
|
+
* The mode to use.
|
|
51
|
+
*/
|
|
52
|
+
mode?: string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* content mimetype
|
|
56
|
+
*/
|
|
57
|
+
mimetype?: string;
|
|
58
|
+
|
|
59
|
+
// FIXME-TRANS: Handle theme localizable names
|
|
60
|
+
// themeDisplayName?: string
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether to use the context-sensitive indentation that the mode provides
|
|
64
|
+
* (or just indent the same as the line before).
|
|
65
|
+
*/
|
|
66
|
+
smartIndent?: boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Configures whether the editor should re-indent the current line when a
|
|
70
|
+
* character is typed that might change its proper indentation
|
|
71
|
+
* (only works if the mode supports indentation).
|
|
72
|
+
*/
|
|
73
|
+
electricChars?: boolean;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Configures the keymap to use. The default is "default", which is the
|
|
77
|
+
* only keymap defined in codemirror.js itself.
|
|
78
|
+
* Extra keymaps are found in the CodeMirror keymap directory.
|
|
79
|
+
*/
|
|
80
|
+
keyMap?: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Can be used to specify extra keybindings for the editor, alongside the
|
|
84
|
+
* ones defined by keyMap. Should be either null, or a valid keymap value.
|
|
85
|
+
*/
|
|
86
|
+
// extraKeys?: KeyBinding[] | null;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Can be used to add extra gutters (beyond or instead of the line number
|
|
90
|
+
* gutter).
|
|
91
|
+
* Should be an array of CSS class names, each of which defines a width
|
|
92
|
+
* (and optionally a background),
|
|
93
|
+
* and which will be used to draw the background of the gutters.
|
|
94
|
+
* May include the CodeMirror-linenumbers class, in order to explicitly
|
|
95
|
+
* set the position of the line number gutter
|
|
96
|
+
* (it will default to be to the right of all other gutters).
|
|
97
|
+
* These class names are the keys passed to setGutterMarker.
|
|
98
|
+
*/
|
|
99
|
+
gutters?: string[];
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Determines whether the gutter scrolls along with the content
|
|
103
|
+
* horizontally (false)
|
|
104
|
+
* or whether it stays fixed during horizontal scrolling (true,
|
|
105
|
+
* the default).
|
|
106
|
+
*/
|
|
107
|
+
fixedGutter?: boolean;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Whether the cursor should be drawn when a selection is active.
|
|
111
|
+
*/
|
|
112
|
+
showCursorWhenSelecting?: boolean;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* When fixedGutter is on, and there is a horizontal scrollbar, by default
|
|
116
|
+
* the gutter will be visible to the left of this scrollbar. If this
|
|
117
|
+
* option is set to true, it will be covered by an element with class
|
|
118
|
+
* CodeMirror-gutter-filler.
|
|
119
|
+
*/
|
|
120
|
+
coverGutterNextToScrollbar?: boolean;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Controls whether drag-and-drop is enabled.
|
|
124
|
+
*/
|
|
125
|
+
dragDrop?: boolean;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Explicitly set the line separator for the editor.
|
|
129
|
+
* By default (value null), the document will be split on CRLFs as well as
|
|
130
|
+
* lone CRs and LFs, and a single LF will be used as line separator in all
|
|
131
|
+
* output (such as getValue). When a specific string is given, lines will
|
|
132
|
+
* only be split on that string, and output will, by default, use that
|
|
133
|
+
* same separator.
|
|
134
|
+
*/
|
|
135
|
+
lineSeparator?: string | null;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Chooses a scrollbar implementation. The default is "native", showing
|
|
139
|
+
* native scrollbars. The core library also provides the "null" style,
|
|
140
|
+
* which completely hides the scrollbars. Addons can implement additional
|
|
141
|
+
* scrollbar models.
|
|
142
|
+
*/
|
|
143
|
+
scrollbarStyle?: string;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* When enabled, which is the default, doing copy or cut when there is no
|
|
147
|
+
* selection will copy or cut the whole lines that have cursors on them.
|
|
148
|
+
*/
|
|
149
|
+
lineWiseCopyCut?: boolean;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Whether to scroll past the end of the buffer.
|
|
153
|
+
*/
|
|
154
|
+
scrollPastEnd?: boolean;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Whether to give the wrapper of the line that contains the cursor the class
|
|
158
|
+
* cm-activeLine.
|
|
159
|
+
*/
|
|
160
|
+
styleActiveLine?: boolean;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Whether to causes the selected text to be marked with the CSS class
|
|
164
|
+
* CodeMirror-selectedtext. Useful to change the colour of the selection
|
|
165
|
+
* (in addition to the background).
|
|
166
|
+
*/
|
|
167
|
+
styleSelectedText?: boolean;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Defines the mouse cursor appearance when hovering over the selection.
|
|
171
|
+
* It can be set to a string, like "pointer", or to true,
|
|
172
|
+
* in which case the "default" (arrow) cursor will be used.
|
|
173
|
+
*/
|
|
174
|
+
selectionPointer?: boolean | string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export const LibroOpensumiEditorOptions = Symbol('LibroOpensumiEditorOptions');
|
|
178
|
+
|
|
179
|
+
export interface LibroOpensumiEditorOptions extends IEditorOptions {
|
|
180
|
+
lspProvider?: LSPProvider;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* The configuration options for the editor.
|
|
184
|
+
*/
|
|
185
|
+
config?: Partial<LibroOpensumiEditorConfig>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export const libroOpensumiEditorDefaultConfig: Required<LibroOpensumiEditorConfig> = {
|
|
189
|
+
...defaultConfig,
|
|
190
|
+
scrollBarHeight: 12,
|
|
191
|
+
mode: 'null',
|
|
192
|
+
mimetype: MIME.python,
|
|
193
|
+
smartIndent: true,
|
|
194
|
+
electricChars: true,
|
|
195
|
+
keyMap: 'default',
|
|
196
|
+
// extraKeys: null,
|
|
197
|
+
gutters: [],
|
|
198
|
+
fixedGutter: true,
|
|
199
|
+
showCursorWhenSelecting: false,
|
|
200
|
+
coverGutterNextToScrollbar: false,
|
|
201
|
+
dragDrop: true,
|
|
202
|
+
lineSeparator: null,
|
|
203
|
+
scrollbarStyle: 'native',
|
|
204
|
+
lineWiseCopyCut: true,
|
|
205
|
+
scrollPastEnd: false,
|
|
206
|
+
styleActiveLine: false,
|
|
207
|
+
styleSelectedText: true,
|
|
208
|
+
selectionPointer: false,
|
|
209
|
+
handlePaste: true,
|
|
210
|
+
lineWrap: 'off',
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export const LibroOpensumiEditorFactory = Symbol('LibroOpensumiEditorFactory');
|
|
214
|
+
export type LibroOpensumiEditorFactory = CodeEditorFactory;
|
|
215
|
+
|
|
216
|
+
export const OpensumiEditorClassname = 'libro-opensumi-editor';
|
|
217
|
+
|
|
218
|
+
export type OpensumiEditorState = IEditorDocumentModelRef | null;
|
|
219
|
+
export const LibroOpensumiEditorState = Symbol('LibroOpensumiEditorState');
|
|
220
|
+
export type LibroOpensumiEditorState = EditorState<OpensumiEditorState>;
|
|
221
|
+
|
|
222
|
+
export const stateFactory: (injector: Injector) => EditorStateFactory<OpensumiEditorState> =
|
|
223
|
+
(injector) => (options: IEditorStateOptions) => {
|
|
224
|
+
const docModelService: IEditorDocumentModelService = injector.get(IEditorDocumentModelService);
|
|
225
|
+
const uri = URI.parse(options.uuid);
|
|
226
|
+
const modeRef = getOrigin(docModelService).getModelReference(uri);
|
|
227
|
+
return {
|
|
228
|
+
toJSON: () => ({}),
|
|
229
|
+
dispose: () => {
|
|
230
|
+
modeRef?.instance.getMonacoModel()?.dispose();
|
|
231
|
+
},
|
|
232
|
+
state: modeRef,
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
@transient()
|
|
237
|
+
export class LibroOpensumiEditor implements IEditor {
|
|
238
|
+
protected editorReadyDeferred = new Deferred<void>();
|
|
239
|
+
editorReady = this.editorReadyDeferred.promise;
|
|
240
|
+
|
|
241
|
+
protected readonly themeService: ThemeService;
|
|
242
|
+
protected readonly injector: Injector;
|
|
243
|
+
|
|
244
|
+
@inject(CommandRegistry) protected readonly commandRegistry: CommandRegistry;
|
|
245
|
+
|
|
246
|
+
protected defaultLineHeight = 20;
|
|
247
|
+
|
|
248
|
+
protected toDispose = new DisposableCollection();
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The DOM node that hosts the editor.
|
|
252
|
+
*/
|
|
253
|
+
readonly host: HTMLElement;
|
|
254
|
+
/**
|
|
255
|
+
* The DOM node that hosts the monaco editor.
|
|
256
|
+
*/
|
|
257
|
+
readonly editorHost: HTMLElement;
|
|
258
|
+
|
|
259
|
+
protected oldDeltaDecorations: string[] = [];
|
|
260
|
+
|
|
261
|
+
protected _config: LibroOpensumiEditorConfig;
|
|
262
|
+
|
|
263
|
+
private intersectionObserver: IntersectionObserver;
|
|
264
|
+
|
|
265
|
+
private editorContentHeight: number;
|
|
266
|
+
|
|
267
|
+
protected _uuid = '';
|
|
268
|
+
/**
|
|
269
|
+
* The uuid of this editor;
|
|
270
|
+
*/
|
|
271
|
+
get uuid(): string {
|
|
272
|
+
return this._uuid;
|
|
273
|
+
}
|
|
274
|
+
set uuid(value: string) {
|
|
275
|
+
this._uuid = value;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
protected _model: IModel;
|
|
279
|
+
/**
|
|
280
|
+
* Returns a model for this editor.
|
|
281
|
+
*/
|
|
282
|
+
get model(): IModel {
|
|
283
|
+
return this._model;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
editorState: EditorState<OpensumiEditorState>;
|
|
287
|
+
|
|
288
|
+
protected _editor?: IOpensumiEditor;
|
|
289
|
+
get editor(): IOpensumiEditor | undefined {
|
|
290
|
+
return this?._editor;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
get monacoEditor(): IMonacoCodeEditor | undefined {
|
|
294
|
+
return getOrigin(this?._editor)?.monacoEditor;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
get lineCount(): number {
|
|
298
|
+
return this.monacoEditor?.getModel()?.getLineCount() || 0;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
protected onModelContentChangedEmitter = new Emitter<IModelContentChange[]>();
|
|
302
|
+
onModelContentChanged = this.onModelContentChangedEmitter.event;
|
|
303
|
+
|
|
304
|
+
lspProvider?: LSPProvider;
|
|
305
|
+
|
|
306
|
+
completionProvider?: CompletionProvider;
|
|
307
|
+
|
|
308
|
+
tooltipProvider?: TooltipProvider;
|
|
309
|
+
|
|
310
|
+
protected isLayouting = false;
|
|
311
|
+
|
|
312
|
+
protected hasHorizontalScrollbar = false;
|
|
313
|
+
|
|
314
|
+
get eventbus() {
|
|
315
|
+
return this.injector.get(IEventBus);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
constructor(
|
|
319
|
+
@inject(LibroOpensumiEditorOptions) options: LibroOpensumiEditorOptions,
|
|
320
|
+
@inject(LibroOpensumiEditorState) state: LibroOpensumiEditorState,
|
|
321
|
+
@inject(ThemeService) themeService: ThemeService,
|
|
322
|
+
@inject(OpensumiInjector) injector: Injector,
|
|
323
|
+
) {
|
|
324
|
+
this.themeService = themeService;
|
|
325
|
+
this.injector = injector;
|
|
326
|
+
this.host = options.host;
|
|
327
|
+
this.host.classList.add('libro-opensumi-editor-container');
|
|
328
|
+
this._uuid = options.uuid || uuid();
|
|
329
|
+
|
|
330
|
+
this._model = options.model;
|
|
331
|
+
|
|
332
|
+
const config = options.config || {};
|
|
333
|
+
const fullConfig = (this._config = {
|
|
334
|
+
...libroOpensumiEditorDefaultConfig,
|
|
335
|
+
...config,
|
|
336
|
+
mimetype: options.model.mimeType,
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
this.completionProvider = options.completionProvider;
|
|
340
|
+
this.tooltipProvider = options.tooltipProvider;
|
|
341
|
+
this.lspProvider = options.lspProvider;
|
|
342
|
+
|
|
343
|
+
this.editorHost = document.createElement('div');
|
|
344
|
+
this.host.append(this.editorHost);
|
|
345
|
+
|
|
346
|
+
this.editorState = state;
|
|
347
|
+
this.createEditor(this.editorHost, fullConfig);
|
|
348
|
+
|
|
349
|
+
this.onMimeTypeChanged();
|
|
350
|
+
this.onCursorActivity();
|
|
351
|
+
|
|
352
|
+
this.toDispose.push(watch(this._model, 'mimeType', this.onMimeTypeChanged));
|
|
353
|
+
// this.toDispose.push(watch(this._model, 'value', this.onValueChange));
|
|
354
|
+
this.toDispose.push(watch(this._model, 'selections', this.onSelectionChange));
|
|
355
|
+
// this.toDispose.push(this.themeService.onDidColorThemeChange(this.onThemeChange));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
get theme(): string {
|
|
359
|
+
const themetype = this.themeService.getActiveTheme().type;
|
|
360
|
+
return this._config.theme[themetype];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
protected toMonacoOptions(editorConfig: Partial<LibroOpensumiEditorConfig>): MonacoEditorOptions {
|
|
364
|
+
return {
|
|
365
|
+
minimap: {
|
|
366
|
+
enabled: false,
|
|
367
|
+
},
|
|
368
|
+
lineHeight: editorConfig.lineHeight ?? this.defaultLineHeight,
|
|
369
|
+
// fontSize: editorConfig.fontSize ?? 13,
|
|
370
|
+
lineNumbers: editorConfig.lineNumbers ? 'on' : 'off',
|
|
371
|
+
// folding: editorConfig.codeFolding,
|
|
372
|
+
wordWrap: editorConfig.lineWrap,
|
|
373
|
+
renderLineHighlightOnlyWhenFocus: true,
|
|
374
|
+
// lineDecorationsWidth: 15,
|
|
375
|
+
// lineNumbersMinChars: 3,
|
|
376
|
+
// suggestSelection: 'first',
|
|
377
|
+
// wordBasedSuggestions: 'off',
|
|
378
|
+
// lineDecorationsWidth: 15,
|
|
379
|
+
// lineNumbersMinChars: 3,
|
|
380
|
+
// suggestSelection: 'first',
|
|
381
|
+
// wordBasedSuggestions: 'off',
|
|
382
|
+
scrollBeyondLastLine: false,
|
|
383
|
+
// overflowWidgetsDomNode: document.getElementById('monaco-editor-overflow-widgets-root')!,
|
|
384
|
+
fixedOverflowWidgets: true,
|
|
385
|
+
// suggest: { snippetsPreventQuickSuggestions: false },
|
|
386
|
+
// autoClosingQuotes: editorConfig.autoClosingBrackets ? 'always' : 'never',
|
|
387
|
+
// autoDetectHighContrast: false,
|
|
388
|
+
// suggest: { snippetsPreventQuickSuggestions: false },
|
|
389
|
+
// autoClosingQuotes: editorConfig.autoClosingBrackets ? 'always' : 'never',
|
|
390
|
+
// autoDetectHighContrast: false,
|
|
391
|
+
scrollbar: {
|
|
392
|
+
alwaysConsumeMouseWheel: false,
|
|
393
|
+
verticalScrollbarSize: 0,
|
|
394
|
+
},
|
|
395
|
+
glyphMargin: false,
|
|
396
|
+
extraEditorClassName: OpensumiEditorClassname,
|
|
397
|
+
// renderLineHighlight: 'all',
|
|
398
|
+
// renderLineHighlightOnlyWhenFocus: true,
|
|
399
|
+
// renderLineHighlight: 'all',
|
|
400
|
+
// renderLineHighlightOnlyWhenFocus: true,
|
|
401
|
+
readOnly: editorConfig.readOnly,
|
|
402
|
+
// cursorWidth: 1,
|
|
403
|
+
// tabSize: editorConfig.tabSize,
|
|
404
|
+
// insertSpaces: editorConfig.insertSpaces,
|
|
405
|
+
// matchBrackets: editorConfig.matchBrackets ? 'always' : 'never',
|
|
406
|
+
// rulers: editorConfig.rulers,
|
|
407
|
+
// wordWrapColumn: editorConfig.wordWrapColumn,
|
|
408
|
+
// 'semanticHighlighting.enabled': true,
|
|
409
|
+
// cursorWidth: 1,
|
|
410
|
+
// tabSize: editorConfig.tabSize,
|
|
411
|
+
// insertSpaces: editorConfig.insertSpaces,
|
|
412
|
+
// matchBrackets: editorConfig.matchBrackets ? 'always' : 'never',
|
|
413
|
+
// rulers: editorConfig.rulers,
|
|
414
|
+
// wordWrapColumn: editorConfig.wordWrapColumn,
|
|
415
|
+
// 'semanticHighlighting.enabled': true,
|
|
416
|
+
maxTokenizationLineLength: 10000,
|
|
417
|
+
wrappingStrategy: 'advanced',
|
|
418
|
+
// hover: {
|
|
419
|
+
// enabled: true,
|
|
420
|
+
// },
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
getState(): EditorState<OpensumiEditorState> {
|
|
425
|
+
const cursorPosition = this.getCursorPosition();
|
|
426
|
+
const selections = this.getSelections();
|
|
427
|
+
return {
|
|
428
|
+
...this.editorState,
|
|
429
|
+
cursorPosition,
|
|
430
|
+
selections,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
protected async createEditor(host: HTMLElement, config: LibroOpensumiEditorConfig) {
|
|
435
|
+
const editorConfig: LibroOpensumiEditorConfig = {
|
|
436
|
+
...config,
|
|
437
|
+
};
|
|
438
|
+
this._config = editorConfig;
|
|
439
|
+
|
|
440
|
+
let modelRef = getOrigin(this.editorState.state);
|
|
441
|
+
|
|
442
|
+
const options: MonacoEditorOptions = {
|
|
443
|
+
...this.toMonacoOptions(editorConfig),
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
const editorCollectionService: EditorCollectionService = this.injector.get(EditorCollectionService);
|
|
447
|
+
|
|
448
|
+
if (!modelRef) {
|
|
449
|
+
const docModelService: IEditorDocumentModelService = this.injector.get(IEditorDocumentModelService);
|
|
450
|
+
const uri = URI.parse(this._uuid);
|
|
451
|
+
modelRef = await getOrigin(docModelService).createModelReference(uri, 'libro-opensumi-editor');
|
|
452
|
+
}
|
|
453
|
+
this._editor = getOrigin(editorCollectionService).createCodeEditor(host, options);
|
|
454
|
+
|
|
455
|
+
getOrigin(this._editor).open(modelRef);
|
|
456
|
+
|
|
457
|
+
this.toDispose.push(
|
|
458
|
+
modelRef.instance.getMonacoModel()?.onDidChangeContent((e) => {
|
|
459
|
+
const value = this.monacoEditor?.getValue();
|
|
460
|
+
this.model.value = value ?? '';
|
|
461
|
+
this.onModelContentChangedEmitter.fire(
|
|
462
|
+
e.changes.map((item) => ({
|
|
463
|
+
range: this.toEditorRange(item.range),
|
|
464
|
+
rangeLength: item.rangeLength,
|
|
465
|
+
rangeOffset: item.rangeOffset,
|
|
466
|
+
text: item.text,
|
|
467
|
+
})),
|
|
468
|
+
);
|
|
469
|
+
}) ?? Disposable.NONE,
|
|
470
|
+
);
|
|
471
|
+
this.toDispose.push(
|
|
472
|
+
this.monacoEditor?.onDidContentSizeChange(() => {
|
|
473
|
+
this.updateEditorSize();
|
|
474
|
+
}) ?? Disposable.NONE,
|
|
475
|
+
);
|
|
476
|
+
this.toDispose.push(
|
|
477
|
+
this.monacoEditor?.onDidBlurEditorText(() => {
|
|
478
|
+
this.blur();
|
|
479
|
+
}) ?? Disposable.NONE,
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
this.updateEditorSize();
|
|
483
|
+
this.inspectResize();
|
|
484
|
+
this.editorReadyDeferred.resolve();
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
protected inspectResize() {
|
|
488
|
+
this.intersectionObserver = new IntersectionObserver((entries) => {
|
|
489
|
+
if (entries[0].isIntersecting) {
|
|
490
|
+
this.updateEditorSize();
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
this.intersectionObserver.observe(this.host);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
protected getEditorNode() {
|
|
497
|
+
return Array.from(this.host.getElementsByClassName(OpensumiEditorClassname))[0] as HTMLDivElement;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
protected updateEditorSize() {
|
|
501
|
+
try {
|
|
502
|
+
this.isLayouting = true;
|
|
503
|
+
const contentHeight = this.monacoEditor?.getContentHeight() ?? this.defaultLineHeight;
|
|
504
|
+
|
|
505
|
+
const lineHeight = this.getOption('lineHeight') ?? this.defaultLineHeight;
|
|
506
|
+
|
|
507
|
+
if (contentHeight > this.lineCount * lineHeight) {
|
|
508
|
+
this.hasHorizontalScrollbar = true;
|
|
509
|
+
} else {
|
|
510
|
+
this.hasHorizontalScrollbar = false;
|
|
511
|
+
}
|
|
512
|
+
if (this.editorContentHeight === contentHeight) {
|
|
513
|
+
if (this.hasHorizontalScrollbar) {
|
|
514
|
+
this.monacoEditor?.layout({
|
|
515
|
+
height: contentHeight,
|
|
516
|
+
width: this.host.offsetWidth,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
return;
|
|
520
|
+
} else {
|
|
521
|
+
this.editorContentHeight = contentHeight;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
this.host.style.height = `${contentHeight + this.getOption('paddingTop') + this.getOption('paddingBottom')}px`;
|
|
525
|
+
this.monacoEditor?.layout({
|
|
526
|
+
width: this.host.offsetWidth,
|
|
527
|
+
height: contentHeight,
|
|
528
|
+
});
|
|
529
|
+
} finally {
|
|
530
|
+
this.isLayouting = false;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
protected onValueChange() {
|
|
535
|
+
// this.editor?.codeEditor.setValue(this.model.value);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
protected onSelectionChange() {
|
|
539
|
+
this.setSelections(this.model.selections);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// protected onThemeChange = () => {
|
|
543
|
+
// this.monacoEditor?.updateOptions({ theme: this.theme });
|
|
544
|
+
// };
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Handles a mime type change.
|
|
548
|
+
* 切换语言
|
|
549
|
+
* cell 切换没走这里
|
|
550
|
+
*/
|
|
551
|
+
protected onMimeTypeChanged(): void {
|
|
552
|
+
// const model = this.monacoEditor?.getModel();
|
|
553
|
+
// model?.setLanguage('')
|
|
554
|
+
// if (this.languageSpec && model) {
|
|
555
|
+
// editor.setModelLanguage(model, this.languageSpec.language);
|
|
556
|
+
// }
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Handles a cursor activity event.
|
|
561
|
+
*/
|
|
562
|
+
protected onCursorActivity(): void {
|
|
563
|
+
// Only add selections if the editor has focus. This avoids unwanted
|
|
564
|
+
// triggering of cursor activity due to collaborator actions.
|
|
565
|
+
if (this.hasFocus()) {
|
|
566
|
+
// const selections = this.getSelections();
|
|
567
|
+
// this.model.selections = selections;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
getOption<K extends keyof LibroOpensumiEditorConfig>(option: K) {
|
|
572
|
+
return this._config[option];
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
*
|
|
577
|
+
* @param option
|
|
578
|
+
* @param value
|
|
579
|
+
*/
|
|
580
|
+
setOption = <K extends keyof LibroOpensumiEditorConfig>(option: K, value: LibroOpensumiEditorConfig[K]) => {
|
|
581
|
+
if (value === null || value === undefined) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// if (option === 'theme') {
|
|
586
|
+
// this._config.theme = value as NonNullable<LibroE2EditorConfig['theme']>;
|
|
587
|
+
// this.monacoEditor?.updateOptions({
|
|
588
|
+
// theme: this.theme,
|
|
589
|
+
// });
|
|
590
|
+
// }
|
|
591
|
+
|
|
592
|
+
// if (option === 'placeholder') {
|
|
593
|
+
// this._config.placeholder = value as NonNullable<
|
|
594
|
+
// LibroE2EditorConfig['placeholder']
|
|
595
|
+
// >;
|
|
596
|
+
// this.placeholder.update(value as NonNullable<LibroE2EditorConfig['placeholder']>);
|
|
597
|
+
// }
|
|
598
|
+
|
|
599
|
+
const sizeKeys = ['fontFamily', 'fontSize', 'lineHeight', 'wordWrapColumn', 'lineWrap'];
|
|
600
|
+
const monacoOptionkeys = sizeKeys.concat(['readOnly', 'insertSpaces', 'tabSize']);
|
|
601
|
+
|
|
602
|
+
if (monacoOptionkeys.includes(option)) {
|
|
603
|
+
this._config = { ...this._config, [option]: value };
|
|
604
|
+
|
|
605
|
+
this.monacoEditor?.updateOptions(this.toMonacoOptions(this._config));
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (sizeKeys.includes(option)) {
|
|
609
|
+
this.updateEditorSize();
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
getLine = (line: number) => this.monacoEditor?.getModel()?.getLineContent(line);
|
|
614
|
+
getOffsetAt = (position: IPosition) =>
|
|
615
|
+
this.monacoEditor?.getModel()?.getOffsetAt({ lineNumber: position.line, column: position.column }) || 0;
|
|
616
|
+
undo = () => {
|
|
617
|
+
this.monacoEditor?.trigger('source', 'undo', {});
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
redo = () => {
|
|
621
|
+
this.monacoEditor?.trigger('source', 'redo', {});
|
|
622
|
+
};
|
|
623
|
+
focus = () => {
|
|
624
|
+
window.requestAnimationFrame(() => {
|
|
625
|
+
this.monacoEditor?.focus();
|
|
626
|
+
});
|
|
627
|
+
};
|
|
628
|
+
hasFocus = () => this.monacoEditor?.hasWidgetFocus() ?? false;
|
|
629
|
+
blur = () => {
|
|
630
|
+
document.documentElement.focus();
|
|
631
|
+
};
|
|
632
|
+
resizeToFit = () => {
|
|
633
|
+
this.monacoEditor?.layout();
|
|
634
|
+
};
|
|
635
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
636
|
+
getPositionForCoordinate = (coordinate: ICoordinate) => null;
|
|
637
|
+
|
|
638
|
+
protected modalChangeEmitter = new Emitter<boolean>();
|
|
639
|
+
get onModalChange() {
|
|
640
|
+
return this.modalChangeEmitter.event;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
protected toMonacoRange(range: IRange) {
|
|
644
|
+
const selection = range ?? this.getSelection();
|
|
645
|
+
const monacoSelection = {
|
|
646
|
+
startLineNumber: selection.start.line || 1,
|
|
647
|
+
startColumn: selection.start.column || 1,
|
|
648
|
+
endLineNumber: selection.end.line || 1,
|
|
649
|
+
endColumn: selection.end.column || 1,
|
|
650
|
+
};
|
|
651
|
+
return monacoSelection;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
protected toEditorRange(range: monacoTypes.IRange): IRange {
|
|
655
|
+
return {
|
|
656
|
+
start: {
|
|
657
|
+
line: range.startLineNumber - 1,
|
|
658
|
+
column: range.startColumn - 1,
|
|
659
|
+
},
|
|
660
|
+
end: {
|
|
661
|
+
line: range.endLineNumber - 1,
|
|
662
|
+
column: range.endColumn - 1,
|
|
663
|
+
},
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
getSelectionValue = (range?: IRange | undefined) => {
|
|
668
|
+
const selection = range ?? this.getSelection();
|
|
669
|
+
return this.monacoEditor?.getModel()?.getValueInRange(this.toMonacoRange(selection));
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
getPositionAt = (offset: number): IPosition | undefined => {
|
|
673
|
+
const position = this.monacoEditor?.getModel()?.getPositionAt(offset);
|
|
674
|
+
return position ? { line: position.lineNumber, column: position.column } : position;
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
protected toMonacoMatch(match: SearchMatch): monacoTypes.FindMatch {
|
|
678
|
+
const start = this.getPositionAt(match.position);
|
|
679
|
+
const end = this.getPositionAt(match.position + match.text.length);
|
|
680
|
+
return {
|
|
681
|
+
range: new MonacoRange(start?.line ?? 1, start?.column ?? 1, end?.line ?? 1, end?.column ?? 1),
|
|
682
|
+
matches: [match.text],
|
|
683
|
+
_findMatchBrand: undefined,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
replaceSelection = (text: string, range: IRange) => {
|
|
688
|
+
this.monacoEditor?.executeEdits(undefined, [
|
|
689
|
+
{
|
|
690
|
+
range: this.toMonacoRange(range),
|
|
691
|
+
text,
|
|
692
|
+
},
|
|
693
|
+
]);
|
|
694
|
+
this.monacoEditor?.pushUndoStop();
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
replaceSelections = (edits: { text: string; range: IRange }[]) => {
|
|
698
|
+
this.monacoEditor?.executeEdits(
|
|
699
|
+
undefined,
|
|
700
|
+
edits.map((item) => ({
|
|
701
|
+
range: this.toMonacoRange(item.range),
|
|
702
|
+
text: item.text,
|
|
703
|
+
})),
|
|
704
|
+
);
|
|
705
|
+
this.monacoEditor?.pushUndoStop();
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
getCursorPosition = () => {
|
|
709
|
+
const position: IPosition = {
|
|
710
|
+
line: this.monacoEditor?.getPosition()?.lineNumber || 1,
|
|
711
|
+
column: this.monacoEditor?.getPosition()?.column || 1,
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
return position;
|
|
715
|
+
};
|
|
716
|
+
setCursorPosition = (position: IPosition) => {
|
|
717
|
+
this.monacoEditor?.setPosition({
|
|
718
|
+
column: position.column + 1,
|
|
719
|
+
lineNumber: position.line + 1,
|
|
720
|
+
});
|
|
721
|
+
};
|
|
722
|
+
getSelection = () => {
|
|
723
|
+
const selection = {
|
|
724
|
+
start: {
|
|
725
|
+
line: this.monacoEditor?.getSelection()?.startLineNumber || 1,
|
|
726
|
+
column: this.monacoEditor?.getSelection()?.startColumn || 1,
|
|
727
|
+
} as IPosition,
|
|
728
|
+
end: {
|
|
729
|
+
line: this.monacoEditor?.getSelection()?.endLineNumber || 1,
|
|
730
|
+
column: this.monacoEditor?.getSelection()?.endColumn || 1,
|
|
731
|
+
} as IPosition,
|
|
732
|
+
};
|
|
733
|
+
return selection;
|
|
734
|
+
};
|
|
735
|
+
setSelection = (selection: IRange) => {
|
|
736
|
+
this.monacoEditor?.setSelection(this.toMonacoRange(selection));
|
|
737
|
+
};
|
|
738
|
+
getSelections = () => {
|
|
739
|
+
const selections: IRange[] = [];
|
|
740
|
+
this.monacoEditor?.getSelections()?.map((selection: any) =>
|
|
741
|
+
selections.push({
|
|
742
|
+
start: {
|
|
743
|
+
line: selection.startLineNumber || 1,
|
|
744
|
+
column: selection.startColumn || 1,
|
|
745
|
+
} as IPosition,
|
|
746
|
+
end: {
|
|
747
|
+
line: selection.endLineNumber || 1,
|
|
748
|
+
column: selection.endColumn || 1,
|
|
749
|
+
} as IPosition,
|
|
750
|
+
}),
|
|
751
|
+
);
|
|
752
|
+
return selections;
|
|
753
|
+
};
|
|
754
|
+
setSelections = (selections: IRange[]) => {
|
|
755
|
+
this.monacoEditor?.setSelections(
|
|
756
|
+
selections.map<Selection>(
|
|
757
|
+
(item) => new Selection(item.start.line, item.start.column, item.end.line, item.end.column),
|
|
758
|
+
),
|
|
759
|
+
);
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
revealSelection = (selection: IRange) => {
|
|
763
|
+
this.monacoEditor?.revealRange(this.toMonacoRange(selection));
|
|
764
|
+
};
|
|
765
|
+
highlightMatches = (matches: SearchMatch[], currentIndex: number | undefined) => {
|
|
766
|
+
let currentMatch: SearchMatch | undefined;
|
|
767
|
+
const _matches: monacoTypes.IModelDeltaDecoration[] = matches
|
|
768
|
+
.map((item, index) => {
|
|
769
|
+
if (index === currentIndex) {
|
|
770
|
+
currentMatch = item;
|
|
771
|
+
return {
|
|
772
|
+
range: item,
|
|
773
|
+
options: {
|
|
774
|
+
className: 'currentFindMatch', // 当前高亮
|
|
775
|
+
description: '',
|
|
776
|
+
},
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
return {
|
|
780
|
+
range: item,
|
|
781
|
+
options: {
|
|
782
|
+
className: 'findMatch', // 匹配高亮
|
|
783
|
+
description: '',
|
|
784
|
+
},
|
|
785
|
+
};
|
|
786
|
+
})
|
|
787
|
+
.map((item) => ({
|
|
788
|
+
...item,
|
|
789
|
+
range: this.toMonacoMatch(item.range).range,
|
|
790
|
+
}));
|
|
791
|
+
this.oldDeltaDecorations = this.monacoEditor?.deltaDecorations(this.oldDeltaDecorations, _matches) || [];
|
|
792
|
+
if (currentMatch) {
|
|
793
|
+
const start = this.getPositionAt(currentMatch.position);
|
|
794
|
+
const end = this.getPositionAt(currentMatch.position + currentMatch.text.length);
|
|
795
|
+
if (start && end) {
|
|
796
|
+
this.revealSelection({ end, start });
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
format = () => {
|
|
802
|
+
this.monacoEditor?.trigger('libro-format', 'editor.action.formatDocument', '');
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
protected _isDisposed = false;
|
|
806
|
+
/**
|
|
807
|
+
* Tests whether the editor is disposed.
|
|
808
|
+
*/
|
|
809
|
+
get disposed(): boolean {
|
|
810
|
+
return this._isDisposed;
|
|
811
|
+
}
|
|
812
|
+
dispose = () => {
|
|
813
|
+
if (this.disposed) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
this.disposeResizeObserver();
|
|
817
|
+
this.toDispose.dispose();
|
|
818
|
+
this._isDisposed = true;
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
disposeResizeObserver = () => {
|
|
822
|
+
if (this.intersectionObserver) {
|
|
823
|
+
getOrigin(this.intersectionObserver).disconnect();
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
}
|