@atlaskit/editor-plugin-code-block-advanced 12.1.2 → 12.2.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/CHANGELOG.md +19 -0
- package/dist/cjs/nodeviews/codeBlockAdvanced.js +1 -4
- package/dist/cjs/nodeviews/codemirrorSync/syncCMWithPM.js +8 -17
- package/dist/cjs/nodeviews/codemirrorSync/updateCMSelection.js +15 -32
- package/dist/es2019/nodeviews/codeBlockAdvanced.js +1 -4
- package/dist/es2019/nodeviews/codemirrorSync/syncCMWithPM.js +8 -17
- package/dist/es2019/nodeviews/codemirrorSync/updateCMSelection.js +15 -32
- package/dist/esm/nodeviews/codeBlockAdvanced.js +1 -4
- package/dist/esm/nodeviews/codemirrorSync/syncCMWithPM.js +8 -17
- package/dist/esm/nodeviews/codemirrorSync/updateCMSelection.js +15 -32
- package/package.json +13 -13
- package/src/nodeviews/codeBlockAdvanced.ts +0 -5
- package/src/nodeviews/codemirrorSync/syncCMWithPM.ts +8 -17
- package/src/nodeviews/codemirrorSync/updateCMSelection.ts +32 -53
- package/dist/cjs/nodeviews/extensions/lineSeparator.js +0 -14
- package/dist/es2019/nodeviews/extensions/lineSeparator.js +0 -8
- package/dist/esm/nodeviews/extensions/lineSeparator.js +0 -8
- package/dist/types/nodeviews/extensions/lineSeparator.d.ts +0 -6
- package/src/nodeviews/extensions/lineSeparator.ts +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block-advanced
|
|
2
2
|
|
|
3
|
+
## 12.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`51c33ef5349b6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/51c33ef5349b6) -
|
|
8
|
+
Enable compatibility with React 19.2.0
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 12.1.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [`d19e8a0a9bc84`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d19e8a0a9bc84) -
|
|
19
|
+
Clean up experiment `platform_editor_fix_advanced_codeblocks_crlf_patch`
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
|
|
3
22
|
## 12.1.2
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -32,7 +32,6 @@ var _updateCMSelection = require("./codemirrorSync/updateCMSelection");
|
|
|
32
32
|
var _firstCodeBlockInDocument = require("./extensions/firstCodeBlockInDocument");
|
|
33
33
|
var _foldGutter = require("./extensions/foldGutter");
|
|
34
34
|
var _keymap = require("./extensions/keymap");
|
|
35
|
-
var _lineSeparator = require("./extensions/lineSeparator");
|
|
36
35
|
var _manageSelectionMarker = require("./extensions/manageSelectionMarker");
|
|
37
36
|
var _prosemirrorDecorations = require("./extensions/prosemirrorDecorations");
|
|
38
37
|
var _tripleClickExtension = require("./extensions/tripleClickExtension");
|
|
@@ -164,9 +163,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
164
163
|
return _this.node;
|
|
165
164
|
},
|
|
166
165
|
onFoldToggled: this.fireCodeFoldingAnalytics
|
|
167
|
-
})] : []
|
|
168
|
-
// With platform_editor_fix_advanced_codeblocks_crlf_patch the lineSeparatorExtension is not needed
|
|
169
|
-
(0, _expValEquals.expValEquals)('platform_editor_fix_advanced_codeblocks_crlf_patch', 'isEnabled', true) ? [] : [(0, _lineSeparator.lineSeparatorExtension)()]])
|
|
166
|
+
})] : []])
|
|
170
167
|
});
|
|
171
168
|
if (contentFormatSharedState) {
|
|
172
169
|
this.unsubscribeContentFormat = contentFormatSharedState.onChange(function (_ref) {
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.syncCMWithPM = void 0;
|
|
7
7
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
-
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
9
8
|
/**
|
|
10
9
|
* Returns the extra offset to add when mapping a CodeMirror position to ProseMirror
|
|
11
10
|
* when the content may contain \r\n (CRLF). Each \r\n in the text before the given
|
|
@@ -45,23 +44,15 @@ var syncCMWithPM = exports.syncCMWithPM = function syncCMWithPM(_ref) {
|
|
|
45
44
|
if (update.docChanged || pmSel.from !== selFrom || pmSel.to !== selTo) {
|
|
46
45
|
var tr = view.state.tr;
|
|
47
46
|
update.changes.iterChanges(function (fromA, toA, fromB, toB, text) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
tr.replaceWith(pmFrom, pmTo, view.state.schema.text(text.toString()));
|
|
56
|
-
} else {
|
|
57
|
-
tr.delete(pmFrom, pmTo);
|
|
58
|
-
}
|
|
47
|
+
var adjFrom = crlfAdjustment(codeBlockText, fromA);
|
|
48
|
+
// If the from and to are the same, we don't need to run adjustment again
|
|
49
|
+
var adjTo = fromA === toA ? adjFrom : crlfAdjustment(codeBlockText, toA);
|
|
50
|
+
var pmFrom = offset + fromA + adjFrom;
|
|
51
|
+
var pmTo = offset + toA + adjTo;
|
|
52
|
+
if (text.length) {
|
|
53
|
+
tr.replaceWith(pmFrom, pmTo, view.state.schema.text(text.toString()));
|
|
59
54
|
} else {
|
|
60
|
-
|
|
61
|
-
tr.replaceWith(offset + fromA, offset + toA, view.state.schema.text(text.toString()));
|
|
62
|
-
} else {
|
|
63
|
-
tr.delete(offset + fromA, offset + toA);
|
|
64
|
-
}
|
|
55
|
+
tr.delete(pmFrom, pmTo);
|
|
65
56
|
}
|
|
66
57
|
offset += toB - fromB - (toA - fromA);
|
|
67
58
|
});
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getCMSelectionChanges = void 0;
|
|
7
|
-
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
8
7
|
/**
|
|
9
8
|
*
|
|
10
9
|
* Compares the updated text with the current to determine the transaction to fire
|
|
@@ -27,42 +26,26 @@ var getCMSelectionChanges = exports.getCMSelectionChanges = function getCMSelect
|
|
|
27
26
|
if (newText !== curText) {
|
|
28
27
|
var curStart = 0,
|
|
29
28
|
newStart = 0;
|
|
30
|
-
var
|
|
31
|
-
curEnd = curText.length,
|
|
29
|
+
var curEnd = curText.length,
|
|
32
30
|
newEnd = newText.length;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (newText.charCodeAt(newStart) === R_LINE_FEED && curText.charCodeAt(curStart) === N_LINE_FEED && newText.charCodeAt(newStart + 1) === N_LINE_FEED) {
|
|
36
|
-
newStart++;
|
|
37
|
-
}
|
|
38
|
-
curStart++;
|
|
31
|
+
while (curStart < curEnd && (curText.charCodeAt(curStart) === newText.charCodeAt(newStart) || newText.charCodeAt(newStart) === R_LINE_FEED && curText.charCodeAt(curStart) === N_LINE_FEED)) {
|
|
32
|
+
if (newText.charCodeAt(newStart) === R_LINE_FEED && curText.charCodeAt(curStart) === N_LINE_FEED && newText.charCodeAt(newStart + 1) === N_LINE_FEED) {
|
|
39
33
|
newStart++;
|
|
40
34
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
newEnd--;
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
from: curStart,
|
|
50
|
-
to: curEnd,
|
|
51
|
-
insert: newText.slice(newStart, newEnd)
|
|
52
|
-
};
|
|
53
|
-
} else {
|
|
54
|
-
while (start < curEnd && curText.charCodeAt(start) === newText.charCodeAt(start)) {
|
|
55
|
-
++start;
|
|
56
|
-
}
|
|
57
|
-
while (curEnd > start && newEnd > start && curText.charCodeAt(curEnd - 1) === newText.charCodeAt(newEnd - 1)) {
|
|
58
|
-
curEnd--;
|
|
35
|
+
curStart++;
|
|
36
|
+
newStart++;
|
|
37
|
+
}
|
|
38
|
+
while (curEnd > curStart && newEnd > newStart && (curText.charCodeAt(curEnd - 1) === newText.charCodeAt(newEnd - 1) || newText.charCodeAt(newEnd - 1) === N_LINE_FEED && curText.charCodeAt(curEnd - 1) === N_LINE_FEED)) {
|
|
39
|
+
if (newText.charCodeAt(newEnd - 1) === N_LINE_FEED && curText.charCodeAt(curEnd - 1) === N_LINE_FEED && newText.charCodeAt(newEnd - 2) === R_LINE_FEED) {
|
|
59
40
|
newEnd--;
|
|
60
41
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
to: curEnd,
|
|
64
|
-
insert: newText.slice(start, newEnd)
|
|
65
|
-
};
|
|
42
|
+
curEnd--;
|
|
43
|
+
newEnd--;
|
|
66
44
|
}
|
|
45
|
+
return {
|
|
46
|
+
from: curStart,
|
|
47
|
+
to: curEnd,
|
|
48
|
+
insert: newText.slice(newStart, newEnd)
|
|
49
|
+
};
|
|
67
50
|
}
|
|
68
51
|
};
|
|
@@ -22,7 +22,6 @@ import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
|
|
|
22
22
|
import { firstCodeBlockInDocument } from './extensions/firstCodeBlockInDocument';
|
|
23
23
|
import { foldGutterExtension, getCodeBlockFoldStateEffects } from './extensions/foldGutter';
|
|
24
24
|
import { keymapExtension } from './extensions/keymap';
|
|
25
|
-
import { lineSeparatorExtension } from './extensions/lineSeparator';
|
|
26
25
|
import { manageSelectionMarker } from './extensions/manageSelectionMarker';
|
|
27
26
|
import { prosemirrorDecorationPlugin } from './extensions/prosemirrorDecorations';
|
|
28
27
|
import { tripleClickSelectAllExtension } from './extensions/tripleClickExtension';
|
|
@@ -142,9 +141,7 @@ class CodeBlockAdvancedNodeView {
|
|
|
142
141
|
selectNode: this.selectCodeBlockNodeAndFocus,
|
|
143
142
|
getNode: () => this.node,
|
|
144
143
|
onFoldToggled: this.fireCodeFoldingAnalytics
|
|
145
|
-
})] : []
|
|
146
|
-
// With platform_editor_fix_advanced_codeblocks_crlf_patch the lineSeparatorExtension is not needed
|
|
147
|
-
expValEquals('platform_editor_fix_advanced_codeblocks_crlf_patch', 'isEnabled', true) ? [] : [lineSeparatorExtension()]]
|
|
144
|
+
})] : []]
|
|
148
145
|
});
|
|
149
146
|
if (contentFormatSharedState) {
|
|
150
147
|
this.unsubscribeContentFormat = contentFormatSharedState.onChange(({
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
3
2
|
/**
|
|
4
3
|
* Returns the extra offset to add when mapping a CodeMirror position to ProseMirror
|
|
5
4
|
* when the content may contain \r\n (CRLF). Each \r\n in the text before the given
|
|
@@ -42,23 +41,15 @@ export const syncCMWithPM = ({
|
|
|
42
41
|
if (update.docChanged || pmSel.from !== selFrom || pmSel.to !== selTo) {
|
|
43
42
|
const tr = view.state.tr;
|
|
44
43
|
update.changes.iterChanges((fromA, toA, fromB, toB, text) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
tr.replaceWith(pmFrom, pmTo, view.state.schema.text(text.toString()));
|
|
53
|
-
} else {
|
|
54
|
-
tr.delete(pmFrom, pmTo);
|
|
55
|
-
}
|
|
44
|
+
const adjFrom = crlfAdjustment(codeBlockText, fromA);
|
|
45
|
+
// If the from and to are the same, we don't need to run adjustment again
|
|
46
|
+
const adjTo = fromA === toA ? adjFrom : crlfAdjustment(codeBlockText, toA);
|
|
47
|
+
const pmFrom = offset + fromA + adjFrom;
|
|
48
|
+
const pmTo = offset + toA + adjTo;
|
|
49
|
+
if (text.length) {
|
|
50
|
+
tr.replaceWith(pmFrom, pmTo, view.state.schema.text(text.toString()));
|
|
56
51
|
} else {
|
|
57
|
-
|
|
58
|
-
tr.replaceWith(offset + fromA, offset + toA, view.state.schema.text(text.toString()));
|
|
59
|
-
} else {
|
|
60
|
-
tr.delete(offset + fromA, offset + toA);
|
|
61
|
-
}
|
|
52
|
+
tr.delete(pmFrom, pmTo);
|
|
62
53
|
}
|
|
63
54
|
offset += toB - fromB - (toA - fromA);
|
|
64
55
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
2
1
|
/**
|
|
3
2
|
*
|
|
4
3
|
* Compares the updated text with the current to determine the transaction to fire
|
|
@@ -21,42 +20,26 @@ export const getCMSelectionChanges = (curText, newText) => {
|
|
|
21
20
|
if (newText !== curText) {
|
|
22
21
|
let curStart = 0,
|
|
23
22
|
newStart = 0;
|
|
24
|
-
let
|
|
25
|
-
curEnd = curText.length,
|
|
23
|
+
let curEnd = curText.length,
|
|
26
24
|
newEnd = newText.length;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (newText.charCodeAt(newStart) === R_LINE_FEED && curText.charCodeAt(curStart) === N_LINE_FEED && newText.charCodeAt(newStart + 1) === N_LINE_FEED) {
|
|
30
|
-
newStart++;
|
|
31
|
-
}
|
|
32
|
-
curStart++;
|
|
25
|
+
while (curStart < curEnd && (curText.charCodeAt(curStart) === newText.charCodeAt(newStart) || newText.charCodeAt(newStart) === R_LINE_FEED && curText.charCodeAt(curStart) === N_LINE_FEED)) {
|
|
26
|
+
if (newText.charCodeAt(newStart) === R_LINE_FEED && curText.charCodeAt(curStart) === N_LINE_FEED && newText.charCodeAt(newStart + 1) === N_LINE_FEED) {
|
|
33
27
|
newStart++;
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
newEnd--;
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
from: curStart,
|
|
44
|
-
to: curEnd,
|
|
45
|
-
insert: newText.slice(newStart, newEnd)
|
|
46
|
-
};
|
|
47
|
-
} else {
|
|
48
|
-
while (start < curEnd && curText.charCodeAt(start) === newText.charCodeAt(start)) {
|
|
49
|
-
++start;
|
|
50
|
-
}
|
|
51
|
-
while (curEnd > start && newEnd > start && curText.charCodeAt(curEnd - 1) === newText.charCodeAt(newEnd - 1)) {
|
|
52
|
-
curEnd--;
|
|
29
|
+
curStart++;
|
|
30
|
+
newStart++;
|
|
31
|
+
}
|
|
32
|
+
while (curEnd > curStart && newEnd > newStart && (curText.charCodeAt(curEnd - 1) === newText.charCodeAt(newEnd - 1) || newText.charCodeAt(newEnd - 1) === N_LINE_FEED && curText.charCodeAt(curEnd - 1) === N_LINE_FEED)) {
|
|
33
|
+
if (newText.charCodeAt(newEnd - 1) === N_LINE_FEED && curText.charCodeAt(curEnd - 1) === N_LINE_FEED && newText.charCodeAt(newEnd - 2) === R_LINE_FEED) {
|
|
53
34
|
newEnd--;
|
|
54
35
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
to: curEnd,
|
|
58
|
-
insert: newText.slice(start, newEnd)
|
|
59
|
-
};
|
|
36
|
+
curEnd--;
|
|
37
|
+
newEnd--;
|
|
60
38
|
}
|
|
39
|
+
return {
|
|
40
|
+
from: curStart,
|
|
41
|
+
to: curEnd,
|
|
42
|
+
insert: newText.slice(newStart, newEnd)
|
|
43
|
+
};
|
|
61
44
|
}
|
|
62
45
|
};
|
|
@@ -27,7 +27,6 @@ import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
|
|
|
27
27
|
import { firstCodeBlockInDocument } from './extensions/firstCodeBlockInDocument';
|
|
28
28
|
import { foldGutterExtension, getCodeBlockFoldStateEffects } from './extensions/foldGutter';
|
|
29
29
|
import { keymapExtension } from './extensions/keymap';
|
|
30
|
-
import { lineSeparatorExtension } from './extensions/lineSeparator';
|
|
31
30
|
import { manageSelectionMarker } from './extensions/manageSelectionMarker';
|
|
32
31
|
import { prosemirrorDecorationPlugin } from './extensions/prosemirrorDecorations';
|
|
33
32
|
import { tripleClickSelectAllExtension } from './extensions/tripleClickExtension';
|
|
@@ -157,9 +156,7 @@ var CodeBlockAdvancedNodeView = /*#__PURE__*/function () {
|
|
|
157
156
|
return _this.node;
|
|
158
157
|
},
|
|
159
158
|
onFoldToggled: this.fireCodeFoldingAnalytics
|
|
160
|
-
})] : []
|
|
161
|
-
// With platform_editor_fix_advanced_codeblocks_crlf_patch the lineSeparatorExtension is not needed
|
|
162
|
-
expValEquals('platform_editor_fix_advanced_codeblocks_crlf_patch', 'isEnabled', true) ? [] : [lineSeparatorExtension()]])
|
|
159
|
+
})] : []])
|
|
163
160
|
});
|
|
164
161
|
if (contentFormatSharedState) {
|
|
165
162
|
this.unsubscribeContentFormat = contentFormatSharedState.onChange(function (_ref) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
3
2
|
/**
|
|
4
3
|
* Returns the extra offset to add when mapping a CodeMirror position to ProseMirror
|
|
5
4
|
* when the content may contain \r\n (CRLF). Each \r\n in the text before the given
|
|
@@ -39,23 +38,15 @@ export var syncCMWithPM = function syncCMWithPM(_ref) {
|
|
|
39
38
|
if (update.docChanged || pmSel.from !== selFrom || pmSel.to !== selTo) {
|
|
40
39
|
var tr = view.state.tr;
|
|
41
40
|
update.changes.iterChanges(function (fromA, toA, fromB, toB, text) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
tr.replaceWith(pmFrom, pmTo, view.state.schema.text(text.toString()));
|
|
50
|
-
} else {
|
|
51
|
-
tr.delete(pmFrom, pmTo);
|
|
52
|
-
}
|
|
41
|
+
var adjFrom = crlfAdjustment(codeBlockText, fromA);
|
|
42
|
+
// If the from and to are the same, we don't need to run adjustment again
|
|
43
|
+
var adjTo = fromA === toA ? adjFrom : crlfAdjustment(codeBlockText, toA);
|
|
44
|
+
var pmFrom = offset + fromA + adjFrom;
|
|
45
|
+
var pmTo = offset + toA + adjTo;
|
|
46
|
+
if (text.length) {
|
|
47
|
+
tr.replaceWith(pmFrom, pmTo, view.state.schema.text(text.toString()));
|
|
53
48
|
} else {
|
|
54
|
-
|
|
55
|
-
tr.replaceWith(offset + fromA, offset + toA, view.state.schema.text(text.toString()));
|
|
56
|
-
} else {
|
|
57
|
-
tr.delete(offset + fromA, offset + toA);
|
|
58
|
-
}
|
|
49
|
+
tr.delete(pmFrom, pmTo);
|
|
59
50
|
}
|
|
60
51
|
offset += toB - fromB - (toA - fromA);
|
|
61
52
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
2
1
|
/**
|
|
3
2
|
*
|
|
4
3
|
* Compares the updated text with the current to determine the transaction to fire
|
|
@@ -21,42 +20,26 @@ export var getCMSelectionChanges = function getCMSelectionChanges(curText, newTe
|
|
|
21
20
|
if (newText !== curText) {
|
|
22
21
|
var curStart = 0,
|
|
23
22
|
newStart = 0;
|
|
24
|
-
var
|
|
25
|
-
curEnd = curText.length,
|
|
23
|
+
var curEnd = curText.length,
|
|
26
24
|
newEnd = newText.length;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (newText.charCodeAt(newStart) === R_LINE_FEED && curText.charCodeAt(curStart) === N_LINE_FEED && newText.charCodeAt(newStart + 1) === N_LINE_FEED) {
|
|
30
|
-
newStart++;
|
|
31
|
-
}
|
|
32
|
-
curStart++;
|
|
25
|
+
while (curStart < curEnd && (curText.charCodeAt(curStart) === newText.charCodeAt(newStart) || newText.charCodeAt(newStart) === R_LINE_FEED && curText.charCodeAt(curStart) === N_LINE_FEED)) {
|
|
26
|
+
if (newText.charCodeAt(newStart) === R_LINE_FEED && curText.charCodeAt(curStart) === N_LINE_FEED && newText.charCodeAt(newStart + 1) === N_LINE_FEED) {
|
|
33
27
|
newStart++;
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
newEnd--;
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
from: curStart,
|
|
44
|
-
to: curEnd,
|
|
45
|
-
insert: newText.slice(newStart, newEnd)
|
|
46
|
-
};
|
|
47
|
-
} else {
|
|
48
|
-
while (start < curEnd && curText.charCodeAt(start) === newText.charCodeAt(start)) {
|
|
49
|
-
++start;
|
|
50
|
-
}
|
|
51
|
-
while (curEnd > start && newEnd > start && curText.charCodeAt(curEnd - 1) === newText.charCodeAt(newEnd - 1)) {
|
|
52
|
-
curEnd--;
|
|
29
|
+
curStart++;
|
|
30
|
+
newStart++;
|
|
31
|
+
}
|
|
32
|
+
while (curEnd > curStart && newEnd > newStart && (curText.charCodeAt(curEnd - 1) === newText.charCodeAt(newEnd - 1) || newText.charCodeAt(newEnd - 1) === N_LINE_FEED && curText.charCodeAt(curEnd - 1) === N_LINE_FEED)) {
|
|
33
|
+
if (newText.charCodeAt(newEnd - 1) === N_LINE_FEED && curText.charCodeAt(curEnd - 1) === N_LINE_FEED && newText.charCodeAt(newEnd - 2) === R_LINE_FEED) {
|
|
53
34
|
newEnd--;
|
|
54
35
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
to: curEnd,
|
|
58
|
-
insert: newText.slice(start, newEnd)
|
|
59
|
-
};
|
|
36
|
+
curEnd--;
|
|
37
|
+
newEnd--;
|
|
60
38
|
}
|
|
39
|
+
return {
|
|
40
|
+
from: curStart,
|
|
41
|
+
to: curEnd,
|
|
42
|
+
insert: newText.slice(newStart, newEnd)
|
|
43
|
+
};
|
|
61
44
|
}
|
|
62
45
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block-advanced",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "CodeBlockAdvanced plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"atlaskit:src": "src/index.ts",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@atlaskit/adf-schema": "^56.
|
|
23
|
+
"@atlaskit/adf-schema": "^56.2.0",
|
|
24
24
|
"@atlaskit/code": "^18.2.0",
|
|
25
|
-
"@atlaskit/editor-plugin-analytics": "^12.
|
|
26
|
-
"@atlaskit/editor-plugin-code-block": "^14.
|
|
27
|
-
"@atlaskit/editor-plugin-editor-disabled": "^12.
|
|
28
|
-
"@atlaskit/editor-plugin-find-replace": "^12.
|
|
29
|
-
"@atlaskit/editor-plugin-selection": "^12.
|
|
30
|
-
"@atlaskit/editor-plugin-selection-marker": "^12.
|
|
25
|
+
"@atlaskit/editor-plugin-analytics": "^12.1.0",
|
|
26
|
+
"@atlaskit/editor-plugin-code-block": "^14.3.0",
|
|
27
|
+
"@atlaskit/editor-plugin-editor-disabled": "^12.1.0",
|
|
28
|
+
"@atlaskit/editor-plugin-find-replace": "^12.1.0",
|
|
29
|
+
"@atlaskit/editor-plugin-selection": "^12.1.0",
|
|
30
|
+
"@atlaskit/editor-plugin-selection-marker": "^12.1.0",
|
|
31
31
|
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
32
32
|
"@atlaskit/platform-feature-flags": "^2.1.0",
|
|
33
|
-
"@atlaskit/prosemirror-history": "^1.
|
|
34
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
33
|
+
"@atlaskit/prosemirror-history": "^1.1.0",
|
|
34
|
+
"@atlaskit/tmp-editor-statsig": "^135.7.0",
|
|
35
35
|
"@atlaskit/tokens": "^16.3.0",
|
|
36
36
|
"@babel/runtime": "^7.0.0",
|
|
37
37
|
"@codemirror/autocomplete": "6.18.4",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"codemirror-lang-mermaid": "0.4.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@atlaskit/editor-common": "^116.
|
|
54
|
-
"react": "^18.2.0",
|
|
53
|
+
"@atlaskit/editor-common": "^116.45.0",
|
|
54
|
+
"react": "^18.2.0 || ^19.2.0",
|
|
55
55
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
56
56
|
},
|
|
57
57
|
"techstack": {
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
|
-
"react": "^
|
|
108
|
+
"react": "^19.2.0",
|
|
109
109
|
"react-intl": "^7.0.0"
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -50,7 +50,6 @@ import { getCMSelectionChanges } from './codemirrorSync/updateCMSelection';
|
|
|
50
50
|
import { firstCodeBlockInDocument } from './extensions/firstCodeBlockInDocument';
|
|
51
51
|
import { foldGutterExtension, getCodeBlockFoldStateEffects } from './extensions/foldGutter';
|
|
52
52
|
import { keymapExtension } from './extensions/keymap';
|
|
53
|
-
import { lineSeparatorExtension } from './extensions/lineSeparator';
|
|
54
53
|
import { manageSelectionMarker } from './extensions/manageSelectionMarker';
|
|
55
54
|
import { prosemirrorDecorationPlugin } from './extensions/prosemirrorDecorations';
|
|
56
55
|
import { tripleClickSelectAllExtension } from './extensions/tripleClickExtension';
|
|
@@ -200,10 +199,6 @@ class CodeBlockAdvancedNodeView implements NodeView {
|
|
|
200
199
|
}),
|
|
201
200
|
]
|
|
202
201
|
: [],
|
|
203
|
-
// With platform_editor_fix_advanced_codeblocks_crlf_patch the lineSeparatorExtension is not needed
|
|
204
|
-
expValEquals('platform_editor_fix_advanced_codeblocks_crlf_patch', 'isEnabled', true)
|
|
205
|
-
? []
|
|
206
|
-
: [lineSeparatorExtension()],
|
|
207
202
|
],
|
|
208
203
|
});
|
|
209
204
|
|
|
@@ -2,7 +2,6 @@ import type { ViewUpdate } from '@codemirror/view';
|
|
|
2
2
|
|
|
3
3
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
6
5
|
|
|
7
6
|
interface Props {
|
|
8
7
|
offset: number;
|
|
@@ -46,23 +45,15 @@ export const syncCMWithPM = ({ view, update, offset }: Props): void => {
|
|
|
46
45
|
if (update.docChanged || pmSel.from !== selFrom || pmSel.to !== selTo) {
|
|
47
46
|
const tr = view.state.tr;
|
|
48
47
|
update.changes.iterChanges((fromA, toA, fromB, toB, text) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
tr.replaceWith(pmFrom, pmTo, view.state.schema.text(text.toString()));
|
|
57
|
-
} else {
|
|
58
|
-
tr.delete(pmFrom, pmTo);
|
|
59
|
-
}
|
|
48
|
+
const adjFrom = crlfAdjustment(codeBlockText, fromA);
|
|
49
|
+
// If the from and to are the same, we don't need to run adjustment again
|
|
50
|
+
const adjTo = fromA === toA ? adjFrom : crlfAdjustment(codeBlockText, toA);
|
|
51
|
+
const pmFrom = offset + fromA + adjFrom;
|
|
52
|
+
const pmTo = offset + toA + adjTo;
|
|
53
|
+
if (text.length) {
|
|
54
|
+
tr.replaceWith(pmFrom, pmTo, view.state.schema.text(text.toString()));
|
|
60
55
|
} else {
|
|
61
|
-
|
|
62
|
-
tr.replaceWith(offset + fromA, offset + toA, view.state.schema.text(text.toString()));
|
|
63
|
-
} else {
|
|
64
|
-
tr.delete(offset + fromA, offset + toA);
|
|
65
|
-
}
|
|
56
|
+
tr.delete(pmFrom, pmTo);
|
|
66
57
|
}
|
|
67
58
|
offset += toB - fromB - (toA - fromA);
|
|
68
59
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ChangeSpec } from '@codemirror/state';
|
|
2
2
|
|
|
3
|
-
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
3
|
/**
|
|
5
4
|
*
|
|
6
5
|
* Compares the updated text with the current to determine the transaction to fire
|
|
@@ -23,66 +22,46 @@ export const getCMSelectionChanges = (curText: string, newText: string): ChangeS
|
|
|
23
22
|
if (newText !== curText) {
|
|
24
23
|
let curStart = 0,
|
|
25
24
|
newStart = 0;
|
|
26
|
-
let
|
|
27
|
-
curEnd = curText.length,
|
|
25
|
+
let curEnd = curText.length,
|
|
28
26
|
newEnd = newText.length;
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
(
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
while (
|
|
29
|
+
curStart < curEnd &&
|
|
30
|
+
(curText.charCodeAt(curStart) === newText.charCodeAt(newStart) ||
|
|
31
|
+
(newText.charCodeAt(newStart) === R_LINE_FEED &&
|
|
32
|
+
curText.charCodeAt(curStart) === N_LINE_FEED))
|
|
33
|
+
) {
|
|
34
|
+
if (
|
|
35
|
+
newText.charCodeAt(newStart) === R_LINE_FEED &&
|
|
36
|
+
curText.charCodeAt(curStart) === N_LINE_FEED &&
|
|
37
|
+
newText.charCodeAt(newStart + 1) === N_LINE_FEED
|
|
36
38
|
) {
|
|
37
|
-
if (
|
|
38
|
-
newText.charCodeAt(newStart) === R_LINE_FEED &&
|
|
39
|
-
curText.charCodeAt(curStart) === N_LINE_FEED &&
|
|
40
|
-
newText.charCodeAt(newStart + 1) === N_LINE_FEED
|
|
41
|
-
) {
|
|
42
|
-
newStart++;
|
|
43
|
-
}
|
|
44
|
-
curStart++;
|
|
45
39
|
newStart++;
|
|
46
40
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
curEnd--;
|
|
62
|
-
newEnd--;
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
from: curStart,
|
|
66
|
-
to: curEnd,
|
|
67
|
-
insert: newText.slice(newStart, newEnd),
|
|
68
|
-
};
|
|
69
|
-
} else {
|
|
70
|
-
while (start < curEnd && curText.charCodeAt(start) === newText.charCodeAt(start)) {
|
|
71
|
-
++start;
|
|
72
|
-
}
|
|
73
|
-
while (
|
|
74
|
-
curEnd > start &&
|
|
75
|
-
newEnd > start &&
|
|
76
|
-
curText.charCodeAt(curEnd - 1) === newText.charCodeAt(newEnd - 1)
|
|
41
|
+
curStart++;
|
|
42
|
+
newStart++;
|
|
43
|
+
}
|
|
44
|
+
while (
|
|
45
|
+
curEnd > curStart &&
|
|
46
|
+
newEnd > newStart &&
|
|
47
|
+
(curText.charCodeAt(curEnd - 1) === newText.charCodeAt(newEnd - 1) ||
|
|
48
|
+
(newText.charCodeAt(newEnd - 1) === N_LINE_FEED &&
|
|
49
|
+
curText.charCodeAt(curEnd - 1) === N_LINE_FEED))
|
|
50
|
+
) {
|
|
51
|
+
if (
|
|
52
|
+
newText.charCodeAt(newEnd - 1) === N_LINE_FEED &&
|
|
53
|
+
curText.charCodeAt(curEnd - 1) === N_LINE_FEED &&
|
|
54
|
+
newText.charCodeAt(newEnd - 2) === R_LINE_FEED
|
|
77
55
|
) {
|
|
78
|
-
curEnd--;
|
|
79
56
|
newEnd--;
|
|
80
57
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
to: curEnd,
|
|
84
|
-
insert: newText.slice(start, newEnd),
|
|
85
|
-
};
|
|
58
|
+
curEnd--;
|
|
59
|
+
newEnd--;
|
|
86
60
|
}
|
|
61
|
+
return {
|
|
62
|
+
from: curStart,
|
|
63
|
+
to: curEnd,
|
|
64
|
+
insert: newText.slice(newStart, newEnd),
|
|
65
|
+
};
|
|
87
66
|
}
|
|
88
67
|
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.lineSeparatorExtension = void 0;
|
|
7
|
-
var _state = require("@codemirror/state");
|
|
8
|
-
/**
|
|
9
|
-
* To avoid issues with CRLF (\r\n) syncing with ProseMirror,
|
|
10
|
-
* we only consider \n for line separators.
|
|
11
|
-
*/
|
|
12
|
-
var lineSeparatorExtension = exports.lineSeparatorExtension = function lineSeparatorExtension() {
|
|
13
|
-
return _state.EditorState.lineSeparator.of('\n');
|
|
14
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { EditorState as CodeMirrorState } from '@codemirror/state';
|
|
2
|
-
/**
|
|
3
|
-
* To avoid issues with CRLF (\r\n) syncing with ProseMirror,
|
|
4
|
-
* we only consider \n for line separators.
|
|
5
|
-
*/
|
|
6
|
-
export const lineSeparatorExtension = () => {
|
|
7
|
-
return CodeMirrorState.lineSeparator.of('\n');
|
|
8
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { EditorState as CodeMirrorState } from '@codemirror/state';
|
|
2
|
-
/**
|
|
3
|
-
* To avoid issues with CRLF (\r\n) syncing with ProseMirror,
|
|
4
|
-
* we only consider \n for line separators.
|
|
5
|
-
*/
|
|
6
|
-
export var lineSeparatorExtension = function lineSeparatorExtension() {
|
|
7
|
-
return CodeMirrorState.lineSeparator.of('\n');
|
|
8
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { EditorState as CodeMirrorState } from '@codemirror/state';
|
|
2
|
-
import type { Extension } from '@codemirror/state';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* To avoid issues with CRLF (\r\n) syncing with ProseMirror,
|
|
6
|
-
* we only consider \n for line separators.
|
|
7
|
-
*/
|
|
8
|
-
export const lineSeparatorExtension = (): Extension => {
|
|
9
|
-
return CodeMirrorState.lineSeparator.of('\n');
|
|
10
|
-
};
|