@atlaskit/editor-plugin-code-block-advanced 2.2.8 → 2.2.10
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/CHANGELOG.md +18 -0
- package/dist/cjs/nodeviews/codeBlockAdvanced.js +34 -31
- package/dist/cjs/nodeviews/codemirrorSync/updateCMSelection.js +8 -10
- package/dist/cjs/nodeviews/extensions/manageSelectionMarker.js +1 -0
- package/dist/cjs/nodeviews/languages/loader.js +61 -29
- package/dist/cjs/ui/syntaxHighlightingTheme.js +8 -2
- package/dist/es2019/nodeviews/codeBlockAdvanced.js +21 -21
- package/dist/es2019/nodeviews/codemirrorSync/updateCMSelection.js +7 -9
- package/dist/es2019/nodeviews/extensions/manageSelectionMarker.js +1 -0
- package/dist/es2019/nodeviews/languages/loader.js +8 -5
- package/dist/es2019/ui/syntaxHighlightingTheme.js +8 -2
- package/dist/esm/nodeviews/codeBlockAdvanced.js +35 -32
- package/dist/esm/nodeviews/codemirrorSync/updateCMSelection.js +7 -9
- package/dist/esm/nodeviews/extensions/manageSelectionMarker.js +1 -0
- package/dist/esm/nodeviews/languages/loader.js +61 -29
- package/dist/esm/ui/syntaxHighlightingTheme.js +8 -2
- package/dist/types/nodeviews/codeBlockAdvanced.d.ts +5 -3
- package/dist/types/nodeviews/codemirrorSync/updateCMSelection.d.ts +3 -3
- package/dist/types/nodeviews/extensions/keymap/index.d.ts +1 -1
- package/dist/types/nodeviews/extensions/manageSelectionMarker.d.ts +3 -2
- package/dist/types/nodeviews/languages/loader.d.ts +1 -1
- package/dist/types/nodeviews/lazyCodeBlockAdvanced.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/codeBlockAdvanced.d.ts +5 -3
- package/dist/types-ts4.5/nodeviews/codemirrorSync/updateCMSelection.d.ts +3 -3
- package/dist/types-ts4.5/nodeviews/extensions/keymap/index.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/extensions/manageSelectionMarker.d.ts +3 -2
- package/dist/types-ts4.5/nodeviews/languages/loader.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/lazyCodeBlockAdvanced.d.ts +1 -1
- package/package.json +4 -4
- package/src/nodeviews/codeBlockAdvanced.ts +31 -28
- package/src/nodeviews/codemirrorSync/updateCMSelection.ts +8 -14
- package/src/nodeviews/extensions/keymap/index.ts +2 -2
- package/src/nodeviews/extensions/manageSelectionMarker.ts +3 -2
- package/src/nodeviews/languages/loader.ts +18 -17
- package/src/nodeviews/lazyCodeBlockAdvanced.ts +1 -1
- package/src/ui/syntaxHighlightingTheme.ts +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block-advanced
|
|
2
2
|
|
|
3
|
+
## 2.2.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#156937](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/156937)
|
|
8
|
+
[`0a144ecb9fd2b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0a144ecb9fd2b) -
|
|
9
|
+
[ux] Improve the syntax highlighting for diff language.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 2.2.9
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#156363](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/156363)
|
|
17
|
+
[`fa74bacdec758`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fa74bacdec758) -
|
|
18
|
+
Reduce number of codemirror transactions fired for performance.
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 2.2.8
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -62,7 +62,9 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
62
62
|
});
|
|
63
63
|
this.cm = new _view.EditorView({
|
|
64
64
|
doc: this.node.textContent,
|
|
65
|
-
extensions: [].concat((0, _toConsumableArray2.default)(config.extensions), [this.lineWrappingCompartment.of([]), this.languageCompartment.of([]), this.pmDecorationsCompartment.of([]
|
|
65
|
+
extensions: [].concat((0, _toConsumableArray2.default)(config.extensions), [this.lineWrappingCompartment.of((0, _codeBlock.isCodeBlockWordWrapEnabled)(node) ? _view.EditorView.lineWrapping : []), this.languageCompartment.of([]), this.pmDecorationsCompartment.of(this.pmFacet.compute([], function () {
|
|
66
|
+
return innerDecorations;
|
|
67
|
+
})), (0, _keymap.keymapExtension)({
|
|
66
68
|
view: view,
|
|
67
69
|
getPos: getPos,
|
|
68
70
|
getNode: getNode,
|
|
@@ -96,8 +98,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
96
98
|
// inner editor
|
|
97
99
|
this.updating = false;
|
|
98
100
|
this.updateLanguage();
|
|
99
|
-
this.
|
|
100
|
-
this.updateProseMirrorDecorations(innerDecorations);
|
|
101
|
+
this.wordWrappingEnabled = (0, _codeBlock.isCodeBlockWordWrapEnabled)(node);
|
|
101
102
|
}
|
|
102
103
|
return (0, _createClass2.default)(CodeBlockAdvancedNodeView, [{
|
|
103
104
|
key: "destroy",
|
|
@@ -167,26 +168,21 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
}, {
|
|
170
|
-
key: "
|
|
171
|
-
value: function
|
|
171
|
+
key: "getWordWrapEffects",
|
|
172
|
+
value: function getWordWrapEffects(node) {
|
|
172
173
|
if (this.wordWrappingEnabled !== (0, _codeBlock.isCodeBlockWordWrapEnabled)(node)) {
|
|
173
|
-
this.updating = true;
|
|
174
|
-
this.cm.dispatch({
|
|
175
|
-
effects: [this.lineWrappingCompartment.reconfigure((0, _codeBlock.isCodeBlockWordWrapEnabled)(node) ? _view.EditorView.lineWrapping : [])]
|
|
176
|
-
});
|
|
177
|
-
this.updating = false;
|
|
178
174
|
this.wordWrappingEnabled = !this.wordWrappingEnabled;
|
|
175
|
+
return this.lineWrappingCompartment.reconfigure((0, _codeBlock.isCodeBlockWordWrapEnabled)(node) ? _view.EditorView.lineWrapping : []);
|
|
179
176
|
}
|
|
177
|
+
return undefined;
|
|
180
178
|
}
|
|
181
179
|
}, {
|
|
182
180
|
key: "update",
|
|
183
181
|
value: function update(node, _, innerDecorations) {
|
|
184
|
-
var _this2 = this;
|
|
185
182
|
this.maybeTryingToReachNodeSelection = false;
|
|
186
183
|
if (node.type !== this.node.type) {
|
|
187
184
|
return false;
|
|
188
185
|
}
|
|
189
|
-
this.updateWordWrap(node);
|
|
190
186
|
this.node = node;
|
|
191
187
|
if (this.updating) {
|
|
192
188
|
return true;
|
|
@@ -194,12 +190,21 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
194
190
|
this.updateLanguage();
|
|
195
191
|
var newText = node.textContent,
|
|
196
192
|
curText = this.cm.state.doc.toString();
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
193
|
+
|
|
194
|
+
// Updates bundled for performance (to avoid multiple-dispatches)
|
|
195
|
+
var changes = (0, _updateCMSelection.getCMSelectionChanges)(curText, newText);
|
|
196
|
+
var wordWrapEffect = this.getWordWrapEffects(node);
|
|
197
|
+
var prosemirrorDecorationsEffect = this.getProseMirrorDecorationEffects(innerDecorations);
|
|
198
|
+
if (changes || wordWrapEffect || prosemirrorDecorationsEffect) {
|
|
199
|
+
this.updating = true;
|
|
200
|
+
this.cm.dispatch({
|
|
201
|
+
effects: [wordWrapEffect, prosemirrorDecorationsEffect].filter(function (effect) {
|
|
202
|
+
return !!effect;
|
|
203
|
+
}),
|
|
204
|
+
changes: changes
|
|
205
|
+
});
|
|
206
|
+
this.updating = false;
|
|
207
|
+
}
|
|
203
208
|
return true;
|
|
204
209
|
}
|
|
205
210
|
|
|
@@ -207,18 +212,16 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
207
212
|
* Updates a facet which stores information on the prosemirror decorations
|
|
208
213
|
*
|
|
209
214
|
* This then gets translated to codemirror decorations in `prosemirrorDecorationPlugin`
|
|
215
|
+
* @param decorationSource
|
|
216
|
+
* @example
|
|
210
217
|
*/
|
|
211
218
|
}, {
|
|
212
|
-
key: "
|
|
213
|
-
value: function
|
|
214
|
-
this.updating = true;
|
|
219
|
+
key: "getProseMirrorDecorationEffects",
|
|
220
|
+
value: function getProseMirrorDecorationEffects(decorationSource) {
|
|
215
221
|
var computedFacet = this.pmFacet.compute([], function () {
|
|
216
222
|
return decorationSource;
|
|
217
223
|
});
|
|
218
|
-
this.
|
|
219
|
-
effects: this.pmDecorationsCompartment.reconfigure(computedFacet)
|
|
220
|
-
});
|
|
221
|
-
this.updating = false;
|
|
224
|
+
return this.pmDecorationsCompartment.reconfigure(computedFacet);
|
|
222
225
|
}
|
|
223
226
|
}, {
|
|
224
227
|
key: "clearProseMirrorDecorations",
|
|
@@ -235,7 +238,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
235
238
|
}, {
|
|
236
239
|
key: "stopEvent",
|
|
237
240
|
value: function stopEvent(e) {
|
|
238
|
-
var
|
|
241
|
+
var _this2 = this,
|
|
239
242
|
_this$getPos5;
|
|
240
243
|
if (e instanceof MouseEvent && e.type === 'mousedown') {
|
|
241
244
|
// !Warning: Side effect!
|
|
@@ -246,13 +249,13 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
246
249
|
setTimeout(function () {
|
|
247
250
|
// Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
|
|
248
251
|
// cause funky behaviour
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
_this2.updating = true;
|
|
253
|
+
_this2.cm.dispatch({
|
|
251
254
|
selection: _state.EditorSelection.create([_state.EditorSelection.cursor(0)], 0)
|
|
252
255
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
+
_this2.updating = false;
|
|
257
|
+
_this2.selectCodeBlockNode(undefined);
|
|
258
|
+
_this2.view.focus();
|
|
256
259
|
}, 20);
|
|
257
260
|
}
|
|
258
261
|
// If we have selected the node we should not stop these events
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.getCMSelectionChanges = void 0;
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
9
|
* Compares the updated text with the current to determine the transaction to fire
|
|
@@ -11,9 +11,9 @@ exports.updateCMSelection = void 0;
|
|
|
11
11
|
*
|
|
12
12
|
* @param curText string - the current CodeMirror text
|
|
13
13
|
* @param newText string - the new CodeMirror text
|
|
14
|
-
* @
|
|
14
|
+
* @returns The changes or undefined if no change
|
|
15
15
|
*/
|
|
16
|
-
var
|
|
16
|
+
var getCMSelectionChanges = exports.getCMSelectionChanges = function getCMSelectionChanges(curText, newText) {
|
|
17
17
|
if (newText !== curText) {
|
|
18
18
|
var start = 0,
|
|
19
19
|
curEnd = curText.length,
|
|
@@ -25,12 +25,10 @@ var updateCMSelection = exports.updateCMSelection = function updateCMSelection(c
|
|
|
25
25
|
curEnd--;
|
|
26
26
|
newEnd--;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
});
|
|
28
|
+
return {
|
|
29
|
+
from: start,
|
|
30
|
+
to: curEnd,
|
|
31
|
+
insert: newText.slice(start, newEnd)
|
|
32
|
+
};
|
|
35
33
|
}
|
|
36
34
|
};
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.LanguageLoader = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -23,35 +25,65 @@ var LanguageLoader = exports.LanguageLoader = /*#__PURE__*/function () {
|
|
|
23
25
|
}
|
|
24
26
|
return (0, _createClass2.default)(LanguageLoader, [{
|
|
25
27
|
key: "updateLanguage",
|
|
26
|
-
value: function
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
value: function () {
|
|
29
|
+
var _updateLanguage = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(languageName) {
|
|
30
|
+
var _this = this;
|
|
31
|
+
var language, configureEmpty, lang, styling;
|
|
32
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
33
|
+
while (1) switch (_context.prev = _context.next) {
|
|
34
|
+
case 0:
|
|
35
|
+
if (!(languageName === this.languageName)) {
|
|
36
|
+
_context.next = 2;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
return _context.abrupt("return");
|
|
40
|
+
case 2:
|
|
41
|
+
language = (0, _languageMap.mapLanguageToCodeMirror)(languageName);
|
|
42
|
+
configureEmpty = function configureEmpty() {
|
|
43
|
+
if (_this.languageName) {
|
|
44
|
+
_this.updateLanguageCompartment([]);
|
|
45
|
+
}
|
|
46
|
+
_this.languageName = '';
|
|
47
|
+
};
|
|
48
|
+
if (language) {
|
|
49
|
+
_context.next = 7;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
configureEmpty();
|
|
53
|
+
return _context.abrupt("return");
|
|
54
|
+
case 7:
|
|
55
|
+
_context.prev = 7;
|
|
56
|
+
_context.next = 10;
|
|
57
|
+
return language.load();
|
|
58
|
+
case 10:
|
|
59
|
+
lang = _context.sent;
|
|
60
|
+
if (lang) {
|
|
61
|
+
styling = (0, _syntaxHighlightingTheme.languageStyling)(lang.language);
|
|
62
|
+
if (styling) {
|
|
63
|
+
this.updateLanguageCompartment([lang, (0, _language.syntaxHighlighting)(styling)]);
|
|
64
|
+
} else {
|
|
65
|
+
this.updateLanguageCompartment(lang);
|
|
66
|
+
}
|
|
67
|
+
this.languageName = languageName;
|
|
68
|
+
} else {
|
|
69
|
+
configureEmpty();
|
|
70
|
+
}
|
|
71
|
+
_context.next = 17;
|
|
72
|
+
break;
|
|
73
|
+
case 14:
|
|
74
|
+
_context.prev = 14;
|
|
75
|
+
_context.t0 = _context["catch"](7);
|
|
76
|
+
configureEmpty();
|
|
77
|
+
case 17:
|
|
78
|
+
case "end":
|
|
79
|
+
return _context.stop();
|
|
47
80
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
81
|
+
}, _callee, this, [[7, 14]]);
|
|
82
|
+
}));
|
|
83
|
+
function updateLanguage(_x) {
|
|
84
|
+
return _updateLanguage.apply(this, arguments);
|
|
85
|
+
}
|
|
86
|
+
return updateLanguage;
|
|
87
|
+
}()
|
|
56
88
|
}]);
|
|
57
89
|
}();
|
|
@@ -40,11 +40,17 @@ var highlightStyle = exports.highlightStyle = _language.HighlightStyle.define([{
|
|
|
40
40
|
tag: [_highlight.tags.atom, _highlight.tags.bool, _highlight.tags.url, _highlight.tags.contentSeparator, _highlight.tags.labelName],
|
|
41
41
|
color: "var(--ds-text-accent-blue, #0055CC)"
|
|
42
42
|
}, {
|
|
43
|
-
tag: [_highlight.tags.literal
|
|
43
|
+
tag: [_highlight.tags.literal],
|
|
44
44
|
color: "var(--ds-text-accent-blue, #0055CC)"
|
|
45
45
|
}, {
|
|
46
|
-
tag:
|
|
46
|
+
tag: _highlight.tags.inserted,
|
|
47
47
|
color: "var(--ds-text-accent-green, #216E4E)"
|
|
48
|
+
}, {
|
|
49
|
+
tag: [_highlight.tags.string],
|
|
50
|
+
color: "var(--ds-text-accent-green, #216E4E)"
|
|
51
|
+
}, {
|
|
52
|
+
tag: [_highlight.tags.deleted],
|
|
53
|
+
color: "var(--ds-text-accent-red, #AE2E24)"
|
|
48
54
|
}, {
|
|
49
55
|
tag: [_highlight.tags.special(_highlight.tags.string)],
|
|
50
56
|
color: "var(--ds-text-accent-green, #216E4E)"
|
|
@@ -10,7 +10,7 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
|
10
10
|
import { highlightStyle } from '../ui/syntaxHighlightingTheme';
|
|
11
11
|
import { cmTheme } from '../ui/theme';
|
|
12
12
|
import { syncCMWithPM } from './codemirrorSync/syncCMWithPM';
|
|
13
|
-
import {
|
|
13
|
+
import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
|
|
14
14
|
import { keymapExtension } from './extensions/keymap';
|
|
15
15
|
import { manageSelectionMarker } from './extensions/manageSelectionMarker';
|
|
16
16
|
import { prosemirrorDecorationPlugin } from './extensions/prosemirrorDecorations';
|
|
@@ -44,7 +44,7 @@ class CodeBlockAdvancedNodeView {
|
|
|
44
44
|
});
|
|
45
45
|
this.cm = new CodeMirror({
|
|
46
46
|
doc: this.node.textContent,
|
|
47
|
-
extensions: [...config.extensions, this.lineWrappingCompartment.of([]), this.languageCompartment.of([]), this.pmDecorationsCompartment.of([]), keymapExtension({
|
|
47
|
+
extensions: [...config.extensions, this.lineWrappingCompartment.of(isCodeBlockWordWrapEnabled(node) ? CodeMirror.lineWrapping : []), this.languageCompartment.of([]), this.pmDecorationsCompartment.of(this.pmFacet.compute([], () => innerDecorations)), keymapExtension({
|
|
48
48
|
view,
|
|
49
49
|
getPos,
|
|
50
50
|
getNode,
|
|
@@ -76,8 +76,7 @@ class CodeBlockAdvancedNodeView {
|
|
|
76
76
|
// inner editor
|
|
77
77
|
this.updating = false;
|
|
78
78
|
this.updateLanguage();
|
|
79
|
-
this.
|
|
80
|
-
this.updateProseMirrorDecorations(innerDecorations);
|
|
79
|
+
this.wordWrappingEnabled = isCodeBlockWordWrapEnabled(node);
|
|
81
80
|
}
|
|
82
81
|
destroy() {
|
|
83
82
|
var _this$cleanupDisabled;
|
|
@@ -134,22 +133,18 @@ class CodeBlockAdvancedNodeView {
|
|
|
134
133
|
this.view.dispatch(tr);
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
|
-
|
|
136
|
+
getWordWrapEffects(node) {
|
|
138
137
|
if (this.wordWrappingEnabled !== isCodeBlockWordWrapEnabled(node)) {
|
|
139
|
-
this.updating = true;
|
|
140
|
-
this.cm.dispatch({
|
|
141
|
-
effects: [this.lineWrappingCompartment.reconfigure(isCodeBlockWordWrapEnabled(node) ? CodeMirror.lineWrapping : [])]
|
|
142
|
-
});
|
|
143
|
-
this.updating = false;
|
|
144
138
|
this.wordWrappingEnabled = !this.wordWrappingEnabled;
|
|
139
|
+
return this.lineWrappingCompartment.reconfigure(isCodeBlockWordWrapEnabled(node) ? CodeMirror.lineWrapping : []);
|
|
145
140
|
}
|
|
141
|
+
return undefined;
|
|
146
142
|
}
|
|
147
143
|
update(node, _, innerDecorations) {
|
|
148
144
|
this.maybeTryingToReachNodeSelection = false;
|
|
149
145
|
if (node.type !== this.node.type) {
|
|
150
146
|
return false;
|
|
151
147
|
}
|
|
152
|
-
this.updateWordWrap(node);
|
|
153
148
|
this.node = node;
|
|
154
149
|
if (this.updating) {
|
|
155
150
|
return true;
|
|
@@ -157,12 +152,19 @@ class CodeBlockAdvancedNodeView {
|
|
|
157
152
|
this.updateLanguage();
|
|
158
153
|
const newText = node.textContent,
|
|
159
154
|
curText = this.cm.state.doc.toString();
|
|
160
|
-
|
|
155
|
+
|
|
156
|
+
// Updates bundled for performance (to avoid multiple-dispatches)
|
|
157
|
+
const changes = getCMSelectionChanges(curText, newText);
|
|
158
|
+
const wordWrapEffect = this.getWordWrapEffects(node);
|
|
159
|
+
const prosemirrorDecorationsEffect = this.getProseMirrorDecorationEffects(innerDecorations);
|
|
160
|
+
if (changes || wordWrapEffect || prosemirrorDecorationsEffect) {
|
|
161
161
|
this.updating = true;
|
|
162
|
-
this.cm.dispatch(
|
|
162
|
+
this.cm.dispatch({
|
|
163
|
+
effects: [wordWrapEffect, prosemirrorDecorationsEffect].filter(effect => !!effect),
|
|
164
|
+
changes
|
|
165
|
+
});
|
|
163
166
|
this.updating = false;
|
|
164
|
-
}
|
|
165
|
-
this.updateProseMirrorDecorations(innerDecorations);
|
|
167
|
+
}
|
|
166
168
|
return true;
|
|
167
169
|
}
|
|
168
170
|
|
|
@@ -170,14 +172,12 @@ class CodeBlockAdvancedNodeView {
|
|
|
170
172
|
* Updates a facet which stores information on the prosemirror decorations
|
|
171
173
|
*
|
|
172
174
|
* This then gets translated to codemirror decorations in `prosemirrorDecorationPlugin`
|
|
175
|
+
* @param decorationSource
|
|
176
|
+
* @example
|
|
173
177
|
*/
|
|
174
|
-
|
|
175
|
-
this.updating = true;
|
|
178
|
+
getProseMirrorDecorationEffects(decorationSource) {
|
|
176
179
|
const computedFacet = this.pmFacet.compute([], () => decorationSource);
|
|
177
|
-
this.
|
|
178
|
-
effects: this.pmDecorationsCompartment.reconfigure(computedFacet)
|
|
179
|
-
});
|
|
180
|
-
this.updating = false;
|
|
180
|
+
return this.pmDecorationsCompartment.reconfigure(computedFacet);
|
|
181
181
|
}
|
|
182
182
|
clearProseMirrorDecorations() {
|
|
183
183
|
this.updating = true;
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @param curText string - the current CodeMirror text
|
|
7
7
|
* @param newText string - the new CodeMirror text
|
|
8
|
-
* @
|
|
8
|
+
* @returns The changes or undefined if no change
|
|
9
9
|
*/
|
|
10
|
-
export const
|
|
10
|
+
export const getCMSelectionChanges = (curText, newText) => {
|
|
11
11
|
if (newText !== curText) {
|
|
12
12
|
let start = 0,
|
|
13
13
|
curEnd = curText.length,
|
|
@@ -19,12 +19,10 @@ export const updateCMSelection = (curText, newText, updateCallback) => {
|
|
|
19
19
|
curEnd--;
|
|
20
20
|
newEnd--;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
});
|
|
22
|
+
return {
|
|
23
|
+
from: start,
|
|
24
|
+
to: curEnd,
|
|
25
|
+
insert: newText.slice(start, newEnd)
|
|
26
|
+
};
|
|
29
27
|
}
|
|
30
28
|
};
|
|
@@ -12,20 +12,23 @@ export class LanguageLoader {
|
|
|
12
12
|
_defineProperty(this, "languageName", '');
|
|
13
13
|
this.updateLanguageCompartment = updateLanguageCompartment;
|
|
14
14
|
}
|
|
15
|
-
updateLanguage(languageName) {
|
|
15
|
+
async updateLanguage(languageName) {
|
|
16
16
|
if (languageName === this.languageName) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
const language = mapLanguageToCodeMirror(languageName);
|
|
20
20
|
const configureEmpty = () => {
|
|
21
|
-
this.
|
|
21
|
+
if (this.languageName) {
|
|
22
|
+
this.updateLanguageCompartment([]);
|
|
23
|
+
}
|
|
22
24
|
this.languageName = '';
|
|
23
25
|
};
|
|
24
26
|
if (!language) {
|
|
25
27
|
configureEmpty();
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
28
|
-
|
|
30
|
+
try {
|
|
31
|
+
const lang = await language.load();
|
|
29
32
|
if (lang) {
|
|
30
33
|
const styling = languageStyling(lang.language);
|
|
31
34
|
if (styling) {
|
|
@@ -37,8 +40,8 @@ export class LanguageLoader {
|
|
|
37
40
|
} else {
|
|
38
41
|
configureEmpty();
|
|
39
42
|
}
|
|
40
|
-
}
|
|
43
|
+
} catch (e) {
|
|
41
44
|
configureEmpty();
|
|
42
|
-
}
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -34,11 +34,17 @@ export const highlightStyle = HighlightStyle.define([{
|
|
|
34
34
|
tag: [tags.atom, tags.bool, tags.url, tags.contentSeparator, tags.labelName],
|
|
35
35
|
color: "var(--ds-text-accent-blue, #0055CC)"
|
|
36
36
|
}, {
|
|
37
|
-
tag: [tags.literal
|
|
37
|
+
tag: [tags.literal],
|
|
38
38
|
color: "var(--ds-text-accent-blue, #0055CC)"
|
|
39
39
|
}, {
|
|
40
|
-
tag:
|
|
40
|
+
tag: tags.inserted,
|
|
41
41
|
color: "var(--ds-text-accent-green, #216E4E)"
|
|
42
|
+
}, {
|
|
43
|
+
tag: [tags.string],
|
|
44
|
+
color: "var(--ds-text-accent-green, #216E4E)"
|
|
45
|
+
}, {
|
|
46
|
+
tag: [tags.deleted],
|
|
47
|
+
color: "var(--ds-text-accent-red, #AE2E24)"
|
|
42
48
|
}, {
|
|
43
49
|
tag: [tags.special(tags.string)],
|
|
44
50
|
color: "var(--ds-text-accent-green, #216E4E)"
|
|
@@ -13,7 +13,7 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
|
13
13
|
import { highlightStyle } from '../ui/syntaxHighlightingTheme';
|
|
14
14
|
import { cmTheme } from '../ui/theme';
|
|
15
15
|
import { syncCMWithPM } from './codemirrorSync/syncCMWithPM';
|
|
16
|
-
import {
|
|
16
|
+
import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
|
|
17
17
|
import { keymapExtension } from './extensions/keymap';
|
|
18
18
|
import { manageSelectionMarker } from './extensions/manageSelectionMarker';
|
|
19
19
|
import { prosemirrorDecorationPlugin } from './extensions/prosemirrorDecorations';
|
|
@@ -55,7 +55,9 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
55
55
|
});
|
|
56
56
|
this.cm = new CodeMirror({
|
|
57
57
|
doc: this.node.textContent,
|
|
58
|
-
extensions: [].concat(_toConsumableArray(config.extensions), [this.lineWrappingCompartment.of([]), this.languageCompartment.of([]), this.pmDecorationsCompartment.of([]
|
|
58
|
+
extensions: [].concat(_toConsumableArray(config.extensions), [this.lineWrappingCompartment.of(isCodeBlockWordWrapEnabled(node) ? CodeMirror.lineWrapping : []), this.languageCompartment.of([]), this.pmDecorationsCompartment.of(this.pmFacet.compute([], function () {
|
|
59
|
+
return innerDecorations;
|
|
60
|
+
})), keymapExtension({
|
|
59
61
|
view: view,
|
|
60
62
|
getPos: getPos,
|
|
61
63
|
getNode: getNode,
|
|
@@ -89,8 +91,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
89
91
|
// inner editor
|
|
90
92
|
this.updating = false;
|
|
91
93
|
this.updateLanguage();
|
|
92
|
-
this.
|
|
93
|
-
this.updateProseMirrorDecorations(innerDecorations);
|
|
94
|
+
this.wordWrappingEnabled = isCodeBlockWordWrapEnabled(node);
|
|
94
95
|
}
|
|
95
96
|
return _createClass(CodeBlockAdvancedNodeView, [{
|
|
96
97
|
key: "destroy",
|
|
@@ -160,26 +161,21 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
}, {
|
|
163
|
-
key: "
|
|
164
|
-
value: function
|
|
164
|
+
key: "getWordWrapEffects",
|
|
165
|
+
value: function getWordWrapEffects(node) {
|
|
165
166
|
if (this.wordWrappingEnabled !== isCodeBlockWordWrapEnabled(node)) {
|
|
166
|
-
this.updating = true;
|
|
167
|
-
this.cm.dispatch({
|
|
168
|
-
effects: [this.lineWrappingCompartment.reconfigure(isCodeBlockWordWrapEnabled(node) ? CodeMirror.lineWrapping : [])]
|
|
169
|
-
});
|
|
170
|
-
this.updating = false;
|
|
171
167
|
this.wordWrappingEnabled = !this.wordWrappingEnabled;
|
|
168
|
+
return this.lineWrappingCompartment.reconfigure(isCodeBlockWordWrapEnabled(node) ? CodeMirror.lineWrapping : []);
|
|
172
169
|
}
|
|
170
|
+
return undefined;
|
|
173
171
|
}
|
|
174
172
|
}, {
|
|
175
173
|
key: "update",
|
|
176
174
|
value: function update(node, _, innerDecorations) {
|
|
177
|
-
var _this2 = this;
|
|
178
175
|
this.maybeTryingToReachNodeSelection = false;
|
|
179
176
|
if (node.type !== this.node.type) {
|
|
180
177
|
return false;
|
|
181
178
|
}
|
|
182
|
-
this.updateWordWrap(node);
|
|
183
179
|
this.node = node;
|
|
184
180
|
if (this.updating) {
|
|
185
181
|
return true;
|
|
@@ -187,12 +183,21 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
187
183
|
this.updateLanguage();
|
|
188
184
|
var newText = node.textContent,
|
|
189
185
|
curText = this.cm.state.doc.toString();
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
186
|
+
|
|
187
|
+
// Updates bundled for performance (to avoid multiple-dispatches)
|
|
188
|
+
var changes = getCMSelectionChanges(curText, newText);
|
|
189
|
+
var wordWrapEffect = this.getWordWrapEffects(node);
|
|
190
|
+
var prosemirrorDecorationsEffect = this.getProseMirrorDecorationEffects(innerDecorations);
|
|
191
|
+
if (changes || wordWrapEffect || prosemirrorDecorationsEffect) {
|
|
192
|
+
this.updating = true;
|
|
193
|
+
this.cm.dispatch({
|
|
194
|
+
effects: [wordWrapEffect, prosemirrorDecorationsEffect].filter(function (effect) {
|
|
195
|
+
return !!effect;
|
|
196
|
+
}),
|
|
197
|
+
changes: changes
|
|
198
|
+
});
|
|
199
|
+
this.updating = false;
|
|
200
|
+
}
|
|
196
201
|
return true;
|
|
197
202
|
}
|
|
198
203
|
|
|
@@ -200,18 +205,16 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
200
205
|
* Updates a facet which stores information on the prosemirror decorations
|
|
201
206
|
*
|
|
202
207
|
* This then gets translated to codemirror decorations in `prosemirrorDecorationPlugin`
|
|
208
|
+
* @param decorationSource
|
|
209
|
+
* @example
|
|
203
210
|
*/
|
|
204
211
|
}, {
|
|
205
|
-
key: "
|
|
206
|
-
value: function
|
|
207
|
-
this.updating = true;
|
|
212
|
+
key: "getProseMirrorDecorationEffects",
|
|
213
|
+
value: function getProseMirrorDecorationEffects(decorationSource) {
|
|
208
214
|
var computedFacet = this.pmFacet.compute([], function () {
|
|
209
215
|
return decorationSource;
|
|
210
216
|
});
|
|
211
|
-
this.
|
|
212
|
-
effects: this.pmDecorationsCompartment.reconfigure(computedFacet)
|
|
213
|
-
});
|
|
214
|
-
this.updating = false;
|
|
217
|
+
return this.pmDecorationsCompartment.reconfigure(computedFacet);
|
|
215
218
|
}
|
|
216
219
|
}, {
|
|
217
220
|
key: "clearProseMirrorDecorations",
|
|
@@ -228,7 +231,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
228
231
|
}, {
|
|
229
232
|
key: "stopEvent",
|
|
230
233
|
value: function stopEvent(e) {
|
|
231
|
-
var
|
|
234
|
+
var _this2 = this,
|
|
232
235
|
_this$getPos5;
|
|
233
236
|
if (e instanceof MouseEvent && e.type === 'mousedown') {
|
|
234
237
|
// !Warning: Side effect!
|
|
@@ -239,13 +242,13 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
239
242
|
setTimeout(function () {
|
|
240
243
|
// Ensure the CM selection is reset - if we have a ranged selection when we do node selection can
|
|
241
244
|
// cause funky behaviour
|
|
242
|
-
|
|
243
|
-
|
|
245
|
+
_this2.updating = true;
|
|
246
|
+
_this2.cm.dispatch({
|
|
244
247
|
selection: EditorSelection.create([EditorSelection.cursor(0)], 0)
|
|
245
248
|
});
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
+
_this2.updating = false;
|
|
250
|
+
_this2.selectCodeBlockNode(undefined);
|
|
251
|
+
_this2.view.focus();
|
|
249
252
|
}, 20);
|
|
250
253
|
}
|
|
251
254
|
// If we have selected the node we should not stop these events
|