@jupyterlab/codemirror 4.4.0-alpha.2 → 4.4.0-beta.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/lib/commands.js.map +1 -1
- package/lib/editor.d.ts +4 -0
- package/lib/editor.js +13 -1
- package/lib/editor.js.map +1 -1
- package/lib/extension.js +13 -0
- package/lib/extension.js.map +1 -1
- package/lib/extensions/customStyle.js.map +1 -1
- package/lib/extensions/ipython-md.js +2 -2
- package/lib/extensions/ipython-md.js.map +1 -1
- package/lib/extensions/rulers.js.map +1 -1
- package/lib/extensions/ybinding.js +8 -17
- package/lib/extensions/ybinding.js.map +1 -1
- package/lib/extensions/yundomanager.d.ts +31 -0
- package/lib/extensions/yundomanager.js +80 -0
- package/lib/extensions/yundomanager.js.map +1 -0
- package/lib/language.js.map +1 -1
- package/lib/mimetype.js.map +1 -1
- package/lib/pythonBuiltin.js.map +1 -1
- package/lib/searchprovider.js.map +1 -1
- package/lib/theme.js +0 -3
- package/lib/theme.js.map +1 -1
- package/lib/token.d.ts +7 -0
- package/lib/token.js.map +1 -1
- package/package.json +9 -9
- package/src/editor.ts +17 -1
- package/src/extension.ts +13 -1
- package/src/extensions/ybinding.ts +15 -18
- package/src/extensions/yundomanager.ts +115 -0
- package/src/theme.ts +0 -4
- package/src/token.ts +8 -0
- package/style/base.css +4 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Jupyter Development Team.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*
|
|
5
|
+
* Vendored from https://github.com/yjs/y-codemirror.next
|
|
6
|
+
* licensed under MIT License by Kevin Jahns.
|
|
7
|
+
*
|
|
8
|
+
* Ideally we would depend on the y-codemirror.next, but it is impractical
|
|
9
|
+
* until https://github.com/yjs/y-codemirror.next/issues/27 is resolved.
|
|
10
|
+
*
|
|
11
|
+
* Modifications compared to upstream:
|
|
12
|
+
* - removed spurious mutex (https://github.com/yjs/y-codemirror.next/issues/15)
|
|
13
|
+
* - added TypeScript types
|
|
14
|
+
* - simplified `YUndoManagerConfig` by removing public methods
|
|
15
|
+
* - moved `_onStackItemAdded`, `_onStackItemPopped` and `_storeSelection` definitions out of constructor
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
EditorView,
|
|
19
|
+
PluginValue,
|
|
20
|
+
ViewPlugin,
|
|
21
|
+
ViewUpdate
|
|
22
|
+
} from '@codemirror/view';
|
|
23
|
+
import { Facet } from '@codemirror/state';
|
|
24
|
+
import { YRange, ySyncAnnotation, YSyncConfig, ySyncFacet } from './ybinding';
|
|
25
|
+
import type { UndoManager } from 'yjs';
|
|
26
|
+
|
|
27
|
+
interface IStackItem {
|
|
28
|
+
meta: Map<any, any>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class YUndoManagerConfig {
|
|
32
|
+
constructor(undoManager: UndoManager) {
|
|
33
|
+
this.undoManager = undoManager;
|
|
34
|
+
}
|
|
35
|
+
public undoManager: UndoManager;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const yUndoManagerFacet = Facet.define<
|
|
39
|
+
YUndoManagerConfig,
|
|
40
|
+
YUndoManagerConfig
|
|
41
|
+
>({
|
|
42
|
+
combine(inputs) {
|
|
43
|
+
return inputs[inputs.length - 1];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
class YUndoManagerPluginValue implements PluginValue {
|
|
48
|
+
constructor(view: EditorView) {
|
|
49
|
+
this._view = view;
|
|
50
|
+
this._conf = view.state.facet(yUndoManagerFacet);
|
|
51
|
+
this._undoManager = this._conf.undoManager;
|
|
52
|
+
this._syncConf = view.state.facet(ySyncFacet);
|
|
53
|
+
this._beforeChangeSelection = null;
|
|
54
|
+
this._undoManager.on('stack-item-added', this._onStackItemAdded);
|
|
55
|
+
this._undoManager.on('stack-item-popped', this._onStackItemPopped);
|
|
56
|
+
this._undoManager.addTrackedOrigin(this._syncConf);
|
|
57
|
+
}
|
|
58
|
+
_onStackItemAdded = ({
|
|
59
|
+
stackItem,
|
|
60
|
+
changedParentTypes
|
|
61
|
+
}: {
|
|
62
|
+
stackItem: IStackItem;
|
|
63
|
+
changedParentTypes: Map<any, any>;
|
|
64
|
+
}) => {
|
|
65
|
+
// only store metadata if this type was affected
|
|
66
|
+
if (
|
|
67
|
+
changedParentTypes.has(this._syncConf.ytext) &&
|
|
68
|
+
this._beforeChangeSelection &&
|
|
69
|
+
!stackItem.meta.has(this)
|
|
70
|
+
) {
|
|
71
|
+
// do not overwrite previous stored selection
|
|
72
|
+
stackItem.meta.set(this, this._beforeChangeSelection);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
_onStackItemPopped = ({ stackItem }: { stackItem: IStackItem }) => {
|
|
76
|
+
const sel = stackItem.meta.get(this);
|
|
77
|
+
if (sel) {
|
|
78
|
+
const selection = this._syncConf.fromYRange(sel);
|
|
79
|
+
this._view.dispatch(
|
|
80
|
+
this._view.state.update({
|
|
81
|
+
selection,
|
|
82
|
+
effects: [EditorView.scrollIntoView(selection)]
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
this._storeSelection();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
_storeSelection = () => {
|
|
89
|
+
// store the selection before the change is applied so we can restore it with the undo manager.
|
|
90
|
+
this._beforeChangeSelection = this._syncConf.toYRange(
|
|
91
|
+
this._view.state.selection.main
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
update(update: ViewUpdate) {
|
|
95
|
+
if (
|
|
96
|
+
update.selectionSet &&
|
|
97
|
+
(update.transactions.length === 0 ||
|
|
98
|
+
update.transactions[0].annotation(ySyncAnnotation) !== this._syncConf)
|
|
99
|
+
) {
|
|
100
|
+
// This only works when YUndoManagerPlugin is included before the sync plugin
|
|
101
|
+
this._storeSelection();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
destroy() {
|
|
105
|
+
this._undoManager.off('stack-item-added', this._onStackItemAdded);
|
|
106
|
+
this._undoManager.off('stack-item-popped', this._onStackItemPopped);
|
|
107
|
+
this._undoManager.removeTrackedOrigin(this._syncConf);
|
|
108
|
+
}
|
|
109
|
+
private _undoManager: UndoManager;
|
|
110
|
+
private _view: EditorView;
|
|
111
|
+
private _beforeChangeSelection: null | YRange;
|
|
112
|
+
private _conf: YUndoManagerConfig;
|
|
113
|
+
private _syncConf: YSyncConfig;
|
|
114
|
+
}
|
|
115
|
+
export const yUndoManager = ViewPlugin.fromClass(YUndoManagerPluginValue);
|
package/src/theme.ts
CHANGED
package/src/token.ts
CHANGED
|
@@ -91,6 +91,14 @@ export interface IExtensionsHandler extends IDisposable {
|
|
|
91
91
|
*/
|
|
92
92
|
setOptions(options: Record<string, any>): void;
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Set a base config options for the editor.
|
|
96
|
+
*
|
|
97
|
+
* You will need to reconfigure the editor extensions by listening
|
|
98
|
+
* to `IExtensionsHandler.configChanged`.
|
|
99
|
+
*/
|
|
100
|
+
setBaseOptions(options: Record<string, any>): void;
|
|
101
|
+
|
|
94
102
|
/**
|
|
95
103
|
* Returns the list of initial extensions of an editor.
|
|
96
104
|
*
|