@difizen/libro-codemirror 0.1.13 → 0.1.15
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/es/editor-contribution.d.ts +1 -0
- package/es/editor-contribution.d.ts.map +1 -1
- package/es/editor-contribution.js +2 -1
- package/es/editor.d.ts +7 -2
- package/es/editor.d.ts.map +1 -1
- package/es/editor.js +33 -16
- package/es/factory.d.ts +2 -1
- package/es/factory.d.ts.map +1 -1
- package/es/factory.js +14 -2
- package/package.json +8 -8
- package/src/editor-contribution.ts +2 -1
- package/src/editor.ts +22 -3
- package/src/factory.ts +23 -2
|
@@ -3,6 +3,7 @@ import { CodeEditorContribution } from '@difizen/libro-code-editor';
|
|
|
3
3
|
export declare class CodeMirrorEditorContribution implements CodeEditorContribution {
|
|
4
4
|
canHandle(mime: string): number;
|
|
5
5
|
factory: CodeEditorFactory;
|
|
6
|
+
stateFactory: import("@difizen/libro-code-editor").EditorStateFactory;
|
|
6
7
|
defaultConfig: Required<import("./config.js").CodeMirrorConfig>;
|
|
7
8
|
}
|
|
8
9
|
//# sourceMappingURL=editor-contribution.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-contribution.d.ts","sourceRoot":"","sources":["../src/editor-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAMpE,qBACa,4BAA6B,YAAW,sBAAsB;IAEzE,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI/B,OAAO,EAAE,iBAAiB,CAA2B;IACrD,aAAa,mDAA2B;CACzC"}
|
|
1
|
+
{"version":3,"file":"editor-contribution.d.ts","sourceRoot":"","sources":["../src/editor-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAMpE,qBACa,4BAA6B,YAAW,sBAAsB;IAEzE,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI/B,OAAO,EAAE,iBAAiB,CAA2B;IACrD,YAAY,0DAAgB;IAC5B,aAAa,mDAA2B;CACzC"}
|
|
@@ -8,13 +8,14 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
import { CodeEditorContribution } from '@difizen/libro-code-editor';
|
|
9
9
|
import { singleton } from '@difizen/mana-app';
|
|
10
10
|
import { codeMirrorDefaultConfig } from "./editor.js";
|
|
11
|
-
import { codeMirrorEditorFactory } from "./factory.js";
|
|
11
|
+
import { codeMirrorEditorFactory, stateFactory } from "./factory.js";
|
|
12
12
|
export var CodeMirrorEditorContribution = (_dec = singleton({
|
|
13
13
|
contrib: [CodeEditorContribution]
|
|
14
14
|
}), _dec(_class = /*#__PURE__*/function () {
|
|
15
15
|
function CodeMirrorEditorContribution() {
|
|
16
16
|
_classCallCheck(this, CodeMirrorEditorContribution);
|
|
17
17
|
this.factory = codeMirrorEditorFactory;
|
|
18
|
+
this.stateFactory = stateFactory;
|
|
18
19
|
this.defaultConfig = codeMirrorDefaultConfig;
|
|
19
20
|
}
|
|
20
21
|
_createClass(CodeMirrorEditorContribution, [{
|
package/es/editor.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import type { ChangeSet, Extension, Range, StateCommand, StateEffectType, Text }
|
|
|
2
2
|
import { EditorState, StateField } from '@codemirror/state';
|
|
3
3
|
import type { Command, DecorationSet, ViewUpdate } from '@codemirror/view';
|
|
4
4
|
import { Decoration, EditorView } from '@codemirror/view';
|
|
5
|
-
import type { ICoordinate, IEditor, IEditorConfig, IEditorOptions, IEditorSelectionStyle, IModel, IPosition, IRange, ITextSelection, IToken, KeydownHandler, SearchMatch } from '@difizen/libro-code-editor';
|
|
5
|
+
import type { EditorState as LibroEditorState, ICoordinate, IEditor, IEditorConfig, IEditorOptions, IEditorSelectionStyle, IModel, IPosition, IRange, ITextSelection, IToken, KeydownHandler, SearchMatch } from '@difizen/libro-code-editor';
|
|
6
6
|
import type { LSPProvider } from '@difizen/libro-lsp';
|
|
7
|
-
import { Disposable, Emitter } from '@difizen/mana-app';
|
|
7
|
+
import { Deferred, Disposable, Emitter } from '@difizen/mana-app';
|
|
8
8
|
import type { CodeMirrorConfig } from './config.js';
|
|
9
9
|
import { EditorConfiguration } from './config.js';
|
|
10
10
|
/**
|
|
@@ -15,6 +15,8 @@ import { EditorConfiguration } from './config.js';
|
|
|
15
15
|
*/
|
|
16
16
|
export declare const codeMirrorDefaultConfig: Required<CodeMirrorConfig>;
|
|
17
17
|
export declare class CodeMirrorEditor implements IEditor {
|
|
18
|
+
protected editorReadyDeferred: Deferred<void>;
|
|
19
|
+
editorReady: Promise<void>;
|
|
18
20
|
protected highlightEffect: StateEffectType<{
|
|
19
21
|
matches: SearchMatch[];
|
|
20
22
|
currentIndex: number | undefined;
|
|
@@ -22,10 +24,12 @@ export declare class CodeMirrorEditor implements IEditor {
|
|
|
22
24
|
protected highlightMark: Decoration;
|
|
23
25
|
protected selectedMatchMark: Decoration;
|
|
24
26
|
protected highlightField: StateField<DecorationSet>;
|
|
27
|
+
protected editorState: LibroEditorState;
|
|
25
28
|
/**
|
|
26
29
|
* Construct a CodeMirror editor.
|
|
27
30
|
*/
|
|
28
31
|
constructor(options: IOptions);
|
|
32
|
+
getState(): LibroEditorState;
|
|
29
33
|
/**
|
|
30
34
|
* Initialize the editor binding.
|
|
31
35
|
*/
|
|
@@ -373,6 +377,7 @@ export interface IOptions extends IEditorOptions {
|
|
|
373
377
|
* The configuration options for the editor.
|
|
374
378
|
*/
|
|
375
379
|
config?: Partial<IConfig>;
|
|
380
|
+
state?: LibroEditorState;
|
|
376
381
|
}
|
|
377
382
|
export declare function createEditor(host: HTMLElement, config: IConfig, value: string, editorConfig: EditorConfiguration, additionalExtensions: Extension[]): EditorView;
|
|
378
383
|
export interface ISelectionText {
|
package/es/editor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,KAAK,EACL,YAAY,EACZ,eAAe,EACf,IAAI,EACL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,WAAW,EAGX,UAAU,EACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EACV,WAAW,EACX,OAAO,EACP,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,MAAM,EACN,SAAS,EACT,MAAM,EACN,cAAc,EACd,MAAM,EACN,cAAc,EACd,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,KAAK,EACL,YAAY,EACZ,eAAe,EACf,IAAI,EACL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,WAAW,EAGX,UAAU,EACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EACV,WAAW,IAAI,gBAAgB,EAC/B,WAAW,EACX,OAAO,E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K,SAAM;IACrB,SAAS,CAAC,WAAW,UAAS;IAC9B,SAAS,CAAC,WAAW,EAAE,SAAS,GAAG,IAAI,CAAQ;IAG/C,SAAS,CAAC,aAAa,EAAE,mBAAmB,CAAC;IAC7C,SAAS,CAAC,QAAQ,EAAE,eAAe,CAAC,oBAAoB,CAAC,CAAC;IAC1D,SAAS,CAAC,WAAW,EAAE,eAAe,CAAC,oBAAoB,CAAC,CAAC;IAC7D,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;CACjD;AAED,MAAM,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAEvC,MAAM,WAAW,QAAS,SAAQ,cAAc;IAC9C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,KAAK,CAAC,EAAE,gBAAgB,CAAC;CAC1B;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,mBAAmB,EACjC,oBAAoB,EAAE,SAAS,EAAE,GAChC,UAAU,CAiBZ;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AACD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,cAAc,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;CAClC"}
|
package/es/editor.js
CHANGED
|
@@ -20,10 +20,11 @@ import { EditorSelection, EditorState, Prec, StateEffect, StateField } from '@co
|
|
|
20
20
|
import { Decoration, EditorView } from '@codemirror/view';
|
|
21
21
|
import { defaultConfig, defaultSelectionStyle } from '@difizen/libro-code-editor';
|
|
22
22
|
import { findFirstArrayIndex, removeAllWhereFromArray } from '@difizen/libro-common';
|
|
23
|
-
import { Disposable, Emitter } from '@difizen/mana-app';
|
|
23
|
+
import { Deferred, Disposable, Emitter } from '@difizen/mana-app';
|
|
24
24
|
import { getOrigin, watch } from '@difizen/mana-app';
|
|
25
25
|
import { v4 } from 'uuid';
|
|
26
26
|
import { EditorConfiguration } from "./config.js";
|
|
27
|
+
import { stateFactory } from "./factory.js";
|
|
27
28
|
import { ensure } from "./mode.js";
|
|
28
29
|
import { monitorPlugin } from "./monitor.js";
|
|
29
30
|
|
|
@@ -127,8 +128,11 @@ export var CodeMirrorEditor = /*#__PURE__*/function () {
|
|
|
127
128
|
* Construct a CodeMirror editor.
|
|
128
129
|
*/
|
|
129
130
|
function CodeMirrorEditor(options) {
|
|
130
|
-
var _this = this
|
|
131
|
+
var _this = this,
|
|
132
|
+
_options$state;
|
|
131
133
|
_classCallCheck(this, CodeMirrorEditor);
|
|
134
|
+
this.editorReadyDeferred = new Deferred();
|
|
135
|
+
this.editorReady = this.editorReadyDeferred.promise;
|
|
132
136
|
/**
|
|
133
137
|
* A signal emitted when either the top or bottom edge is requested.
|
|
134
138
|
*/
|
|
@@ -165,6 +169,10 @@ export var CodeMirrorEditor = /*#__PURE__*/function () {
|
|
|
165
169
|
host.addEventListener('blur', this, true);
|
|
166
170
|
host.addEventListener('scroll', this, true);
|
|
167
171
|
this._uuid = options.uuid || v4();
|
|
172
|
+
this.editorState = (_options$state = options.state) !== null && _options$state !== void 0 ? _options$state : stateFactory({
|
|
173
|
+
uuid: options.uuid,
|
|
174
|
+
model: options.model
|
|
175
|
+
});
|
|
168
176
|
|
|
169
177
|
// State and effects for handling the selection marks
|
|
170
178
|
this._addMark = StateEffect.define();
|
|
@@ -326,6 +334,7 @@ export var CodeMirrorEditor = /*#__PURE__*/function () {
|
|
|
326
334
|
this._editor = createEditor(host, fullConfig, this.model.value, this._editorConfig, [this._markField, Prec.high(domEventHandlers), updateListener, monitorPlugin({
|
|
327
335
|
onTooltipChange: this.handleTooltipChange
|
|
328
336
|
})]);
|
|
337
|
+
this.editorReadyDeferred.resolve();
|
|
329
338
|
|
|
330
339
|
// every time the model is switched, we need to re-initialize the editor binding
|
|
331
340
|
// this.model.sharedModelSwitched.connect(this._initializeEditorBinding, this);
|
|
@@ -345,19 +354,27 @@ export var CodeMirrorEditor = /*#__PURE__*/function () {
|
|
|
345
354
|
|
|
346
355
|
watch(model, 'mimeType', this._onMimeTypeChanged);
|
|
347
356
|
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Initialize the editor binding.
|
|
351
|
-
*/
|
|
352
|
-
// protected _initializeEditorBinding(): void {
|
|
353
|
-
// const sharedModel = this.model.sharedModel as models.IYText;
|
|
354
|
-
// this._yeditorBinding = {
|
|
355
|
-
// text: sharedModel.ysource,
|
|
356
|
-
// awareness: sharedModel.awareness,
|
|
357
|
-
// undoManager: sharedModel.undoManager,
|
|
358
|
-
// };
|
|
359
|
-
// }
|
|
360
357
|
_createClass(CodeMirrorEditor, [{
|
|
358
|
+
key: "getState",
|
|
359
|
+
value: function getState() {
|
|
360
|
+
return _objectSpread(_objectSpread({}, this.editorState), {}, {
|
|
361
|
+
cursorPosition: this.getCursorPosition(),
|
|
362
|
+
selections: this.getSelections()
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Initialize the editor binding.
|
|
368
|
+
*/
|
|
369
|
+
// protected _initializeEditorBinding(): void {
|
|
370
|
+
// const sharedModel = this.model.sharedModel as models.IYText;
|
|
371
|
+
// this._yeditorBinding = {
|
|
372
|
+
// text: sharedModel.ysource,
|
|
373
|
+
// awareness: sharedModel.awareness,
|
|
374
|
+
// undoManager: sharedModel.undoManager,
|
|
375
|
+
// };
|
|
376
|
+
// }
|
|
377
|
+
}, {
|
|
361
378
|
key: "uuid",
|
|
362
379
|
get:
|
|
363
380
|
/**
|
|
@@ -577,7 +594,7 @@ export var CodeMirrorEditor = /*#__PURE__*/function () {
|
|
|
577
594
|
}, {
|
|
578
595
|
key: "focus",
|
|
579
596
|
value: function focus() {
|
|
580
|
-
this._editor.focus();
|
|
597
|
+
getOrigin(this._editor).focus();
|
|
581
598
|
}
|
|
582
599
|
|
|
583
600
|
/**
|
|
@@ -586,7 +603,7 @@ export var CodeMirrorEditor = /*#__PURE__*/function () {
|
|
|
586
603
|
}, {
|
|
587
604
|
key: "hasFocus",
|
|
588
605
|
value: function hasFocus() {
|
|
589
|
-
return this._editor.hasFocus;
|
|
606
|
+
return getOrigin(this._editor).hasFocus;
|
|
590
607
|
}
|
|
591
608
|
|
|
592
609
|
/**
|
package/es/factory.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { CodeEditorFactory } from '@difizen/libro-code-editor';
|
|
1
|
+
import type { CodeEditorFactory, EditorStateFactory } from '@difizen/libro-code-editor';
|
|
2
2
|
export declare const codeMirrorEditorFactory: CodeEditorFactory;
|
|
3
|
+
export declare const stateFactory: EditorStateFactory;
|
|
3
4
|
//# sourceMappingURL=factory.d.ts.map
|
package/es/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EAEjB,kBAAkB,EAEnB,MAAM,4BAA4B,CAAC;AAIpC,eAAO,MAAM,uBAAuB,EAAE,iBASrC,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,kBAU1B,CAAC"}
|
package/es/factory.js
CHANGED
|
@@ -5,8 +5,20 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import { codeMirrorDefaultConfig, CodeMirrorEditor } from "./editor.js";
|
|
8
|
-
export var codeMirrorEditorFactory = function codeMirrorEditorFactory(options) {
|
|
8
|
+
export var codeMirrorEditorFactory = function codeMirrorEditorFactory(options, state) {
|
|
9
9
|
return new CodeMirrorEditor(_objectSpread(_objectSpread({}, options), {}, {
|
|
10
|
-
config: _objectSpread(_objectSpread({}, codeMirrorDefaultConfig), options.config)
|
|
10
|
+
config: _objectSpread(_objectSpread({}, codeMirrorDefaultConfig), options.config),
|
|
11
|
+
state: state
|
|
11
12
|
}));
|
|
13
|
+
};
|
|
14
|
+
export var stateFactory = function stateFactory() {
|
|
15
|
+
return {
|
|
16
|
+
toJSON: function toJSON() {
|
|
17
|
+
return {};
|
|
18
|
+
},
|
|
19
|
+
dispose: function dispose() {
|
|
20
|
+
//
|
|
21
|
+
},
|
|
22
|
+
state: {}
|
|
23
|
+
};
|
|
12
24
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-codemirror",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"@codemirror/lang-markdown": "^6.0.5",
|
|
40
40
|
"@codemirror/lang-python": "^6.0.1",
|
|
41
41
|
"@codemirror/lang-sql": "^6.3.0",
|
|
42
|
-
"@codemirror/language": "^6.
|
|
42
|
+
"@codemirror/language": "^6.10.0",
|
|
43
43
|
"@codemirror/lint": "^6.0.0",
|
|
44
44
|
"@codemirror/search": "^6.0.0",
|
|
45
|
-
"@codemirror/state": "^6.
|
|
46
|
-
"@codemirror/view": "^6.
|
|
47
|
-
"@difizen/libro-code-editor": "^0.1.
|
|
48
|
-
"@difizen/libro-common": "^0.1.
|
|
49
|
-
"@difizen/libro-
|
|
50
|
-
"@difizen/libro-
|
|
45
|
+
"@codemirror/state": "^6.4.0",
|
|
46
|
+
"@codemirror/view": "^6.23.0",
|
|
47
|
+
"@difizen/libro-code-editor": "^0.1.15",
|
|
48
|
+
"@difizen/libro-common": "^0.1.15",
|
|
49
|
+
"@difizen/libro-lsp": "^0.1.15",
|
|
50
|
+
"@difizen/libro-rendermime": "^0.1.15",
|
|
51
51
|
"@difizen/mana-app": "latest",
|
|
52
52
|
"@lezer/common": "^1.1.0",
|
|
53
53
|
"@lezer/highlight": "^1.1.4",
|
|
@@ -3,7 +3,7 @@ import { CodeEditorContribution } from '@difizen/libro-code-editor';
|
|
|
3
3
|
import { singleton } from '@difizen/mana-app';
|
|
4
4
|
|
|
5
5
|
import { codeMirrorDefaultConfig } from './editor.js';
|
|
6
|
-
import { codeMirrorEditorFactory } from './factory.js';
|
|
6
|
+
import { codeMirrorEditorFactory, stateFactory } from './factory.js';
|
|
7
7
|
|
|
8
8
|
@singleton({ contrib: [CodeEditorContribution] })
|
|
9
9
|
export class CodeMirrorEditorContribution implements CodeEditorContribution {
|
|
@@ -13,5 +13,6 @@ export class CodeMirrorEditorContribution implements CodeEditorContribution {
|
|
|
13
13
|
return 50;
|
|
14
14
|
}
|
|
15
15
|
factory: CodeEditorFactory = codeMirrorEditorFactory;
|
|
16
|
+
stateFactory = stateFactory;
|
|
16
17
|
defaultConfig = codeMirrorDefaultConfig;
|
|
17
18
|
}
|
package/src/editor.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type { Command, DecorationSet, ViewUpdate } from '@codemirror/view';
|
|
|
19
19
|
import { Decoration, EditorView } from '@codemirror/view';
|
|
20
20
|
import { defaultConfig, defaultSelectionStyle } from '@difizen/libro-code-editor';
|
|
21
21
|
import type {
|
|
22
|
+
EditorState as LibroEditorState,
|
|
22
23
|
ICoordinate,
|
|
23
24
|
IEditor,
|
|
24
25
|
IEditorConfig,
|
|
@@ -34,13 +35,14 @@ import type {
|
|
|
34
35
|
} from '@difizen/libro-code-editor';
|
|
35
36
|
import { findFirstArrayIndex, removeAllWhereFromArray } from '@difizen/libro-common';
|
|
36
37
|
import type { LSPProvider } from '@difizen/libro-lsp';
|
|
37
|
-
import { Disposable, Emitter } from '@difizen/mana-app';
|
|
38
|
+
import { Deferred, Disposable, Emitter } from '@difizen/mana-app';
|
|
38
39
|
import { getOrigin, watch } from '@difizen/mana-app';
|
|
39
40
|
import type { SyntaxNodeRef } from '@lezer/common';
|
|
40
41
|
import { v4 } from 'uuid';
|
|
41
42
|
|
|
42
43
|
import type { CodeMirrorConfig } from './config.js';
|
|
43
44
|
import { EditorConfiguration } from './config.js';
|
|
45
|
+
import { stateFactory } from './factory.js';
|
|
44
46
|
import { ensure } from './mode.js';
|
|
45
47
|
import { monitorPlugin } from './monitor.js';
|
|
46
48
|
|
|
@@ -137,6 +139,8 @@ export const codeMirrorDefaultConfig: Required<CodeMirrorConfig> = {
|
|
|
137
139
|
};
|
|
138
140
|
|
|
139
141
|
export class CodeMirrorEditor implements IEditor {
|
|
142
|
+
protected editorReadyDeferred = new Deferred<void>();
|
|
143
|
+
editorReady = this.editorReadyDeferred.promise;
|
|
140
144
|
// highlight
|
|
141
145
|
protected highlightEffect: StateEffectType<{
|
|
142
146
|
matches: SearchMatch[];
|
|
@@ -146,6 +150,8 @@ export class CodeMirrorEditor implements IEditor {
|
|
|
146
150
|
protected selectedMatchMark: Decoration;
|
|
147
151
|
protected highlightField: StateField<DecorationSet>;
|
|
148
152
|
|
|
153
|
+
protected editorState: LibroEditorState;
|
|
154
|
+
|
|
149
155
|
/**
|
|
150
156
|
* Construct a CodeMirror editor.
|
|
151
157
|
*/
|
|
@@ -160,6 +166,8 @@ export class CodeMirrorEditor implements IEditor {
|
|
|
160
166
|
host.addEventListener('scroll', this, true);
|
|
161
167
|
|
|
162
168
|
this._uuid = options.uuid || v4();
|
|
169
|
+
this.editorState =
|
|
170
|
+
options.state ?? stateFactory({ uuid: options.uuid, model: options.model });
|
|
163
171
|
|
|
164
172
|
// State and effects for handling the selection marks
|
|
165
173
|
this._addMark = StateEffect.define<ICollabSelectionText>();
|
|
@@ -314,6 +322,8 @@ export class CodeMirrorEditor implements IEditor {
|
|
|
314
322
|
],
|
|
315
323
|
);
|
|
316
324
|
|
|
325
|
+
this.editorReadyDeferred.resolve();
|
|
326
|
+
|
|
317
327
|
// every time the model is switched, we need to re-initialize the editor binding
|
|
318
328
|
// this.model.sharedModelSwitched.connect(this._initializeEditorBinding, this);
|
|
319
329
|
|
|
@@ -333,6 +343,14 @@ export class CodeMirrorEditor implements IEditor {
|
|
|
333
343
|
watch(model, 'mimeType', this._onMimeTypeChanged);
|
|
334
344
|
}
|
|
335
345
|
|
|
346
|
+
getState(): LibroEditorState {
|
|
347
|
+
return {
|
|
348
|
+
...this.editorState,
|
|
349
|
+
cursorPosition: this.getCursorPosition(),
|
|
350
|
+
selections: this.getSelections(),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
336
354
|
/**
|
|
337
355
|
* Initialize the editor binding.
|
|
338
356
|
*/
|
|
@@ -545,14 +563,14 @@ export class CodeMirrorEditor implements IEditor {
|
|
|
545
563
|
* Brings browser focus to this editor text.
|
|
546
564
|
*/
|
|
547
565
|
focus(): void {
|
|
548
|
-
this._editor.focus();
|
|
566
|
+
getOrigin(this._editor).focus();
|
|
549
567
|
}
|
|
550
568
|
|
|
551
569
|
/**
|
|
552
570
|
* Test whether the editor has keyboard focus.
|
|
553
571
|
*/
|
|
554
572
|
hasFocus(): boolean {
|
|
555
|
-
return this._editor.hasFocus;
|
|
573
|
+
return getOrigin(this._editor).hasFocus;
|
|
556
574
|
}
|
|
557
575
|
|
|
558
576
|
/**
|
|
@@ -1219,6 +1237,7 @@ export interface IOptions extends IEditorOptions {
|
|
|
1219
1237
|
* The configuration options for the editor.
|
|
1220
1238
|
*/
|
|
1221
1239
|
config?: Partial<IConfig>;
|
|
1240
|
+
state?: LibroEditorState;
|
|
1222
1241
|
}
|
|
1223
1242
|
|
|
1224
1243
|
export function createEditor(
|
package/src/factory.ts
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
CodeEditorFactory,
|
|
3
|
+
EditorState,
|
|
4
|
+
EditorStateFactory,
|
|
5
|
+
IEditorOptions,
|
|
6
|
+
} from '@difizen/libro-code-editor';
|
|
2
7
|
|
|
3
8
|
import { codeMirrorDefaultConfig, CodeMirrorEditor } from './editor.js';
|
|
4
9
|
|
|
5
|
-
export const codeMirrorEditorFactory: CodeEditorFactory = (
|
|
10
|
+
export const codeMirrorEditorFactory: CodeEditorFactory = (
|
|
11
|
+
options: IEditorOptions,
|
|
12
|
+
state?: EditorState,
|
|
13
|
+
) => {
|
|
6
14
|
return new CodeMirrorEditor({
|
|
7
15
|
...options,
|
|
8
16
|
config: { ...codeMirrorDefaultConfig, ...options.config },
|
|
17
|
+
state,
|
|
9
18
|
});
|
|
10
19
|
};
|
|
20
|
+
|
|
21
|
+
export const stateFactory: EditorStateFactory = () => {
|
|
22
|
+
return {
|
|
23
|
+
toJSON: () => {
|
|
24
|
+
return {};
|
|
25
|
+
},
|
|
26
|
+
dispose: () => {
|
|
27
|
+
//
|
|
28
|
+
},
|
|
29
|
+
state: {},
|
|
30
|
+
};
|
|
31
|
+
};
|