@atlaskit/editor-plugin-find-replace 2.10.6 → 3.0.1
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 +49 -0
- package/dist/cjs/pm-plugins/commands.js +4 -3
- package/dist/cjs/pm-plugins/plugin-factory.js +3 -1
- package/dist/cjs/pm-plugins/utils/index.js +19 -1
- package/dist/es2019/pm-plugins/commands.js +5 -4
- package/dist/es2019/pm-plugins/plugin-factory.js +4 -2
- package/dist/es2019/pm-plugins/utils/index.js +14 -0
- package/dist/esm/pm-plugins/commands.js +5 -4
- package/dist/esm/pm-plugins/plugin-factory.js +4 -2
- package/dist/esm/pm-plugins/utils/index.js +16 -0
- package/dist/types/pm-plugins/utils/index.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/utils/index.d.ts +1 -0
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-find-replace
|
|
2
2
|
|
|
3
|
+
## 3.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#180340](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/180340)
|
|
8
|
+
[`3cf803e05d3b9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3cf803e05d3b9) -
|
|
9
|
+
[ux] ED-28366 set active match to closest match to selection rather than first following selection
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 3.0.0
|
|
13
|
+
|
|
14
|
+
### Major Changes
|
|
15
|
+
|
|
16
|
+
- [#181024](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/181024)
|
|
17
|
+
[`8e80c487ca307`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8e80c487ca307) - ##
|
|
18
|
+
Make `@atlaskit/editor-common` a peer dependency
|
|
19
|
+
|
|
20
|
+
**WHAT:** `@atlaskit/editor-common` has been moved from `dependencies` to `peerDependencies` in
|
|
21
|
+
all editor plugin packages.
|
|
22
|
+
|
|
23
|
+
**WHY:** This change ensures that only a single version of `@atlaskit/editor-common` is used in
|
|
24
|
+
consuming applications, preventing issues caused by multiple versions of singleton libraries (such
|
|
25
|
+
as context mismatches or duplicated state). This is especially important for packages that rely on
|
|
26
|
+
shared context or singletons.
|
|
27
|
+
|
|
28
|
+
**HOW TO ADJUST:**
|
|
29
|
+
|
|
30
|
+
- Consumers must now explicitly install `@atlaskit/editor-common` in their own project if they use
|
|
31
|
+
any of these editor plugins.
|
|
32
|
+
- Ensure the version you install matches the version required by the plugins.
|
|
33
|
+
- You can use the
|
|
34
|
+
[`check-peer-dependencies`](https://www.npmjs.com/package/check-peer-dependencies) package to
|
|
35
|
+
verify that all required peer dependencies are installed and compatible.
|
|
36
|
+
- Example install command:
|
|
37
|
+
```
|
|
38
|
+
npm install @atlaskit/editor-common
|
|
39
|
+
```
|
|
40
|
+
or
|
|
41
|
+
```
|
|
42
|
+
yarn add @atlaskit/editor-common
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Note:** This is a breaking change. If `@atlaskit/editor-common` is not installed at the
|
|
46
|
+
application level, you may see errors or unexpected behavior.
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies
|
|
51
|
+
|
|
3
52
|
## 2.10.6
|
|
4
53
|
|
|
5
54
|
### Patch Changes
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.toggleMatchCase = exports.replaceAll = exports.replace = exports.removeDecorations = exports.findPrevious = exports.findNext = exports.find = exports.cancelSearch = exports.blur = exports.addDecorations = exports.activate = void 0;
|
|
8
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
9
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
10
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
10
11
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
11
12
|
var _actions = require("./actions");
|
|
12
13
|
var _pluginFactory = require("./plugin-factory");
|
|
@@ -34,7 +35,7 @@ var activate = exports.activate = function activate() {
|
|
|
34
35
|
getIntl: getIntl,
|
|
35
36
|
api: api
|
|
36
37
|
});
|
|
37
|
-
index = (0, _utils.findSearchIndex)(selection.from, matches);
|
|
38
|
+
index = (0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true) && (0, _platformFeatureFlags.fg)('platform_editor_find_and_replace_improvements_1') ? (0, _utils.findClosestMatch)(selection.from, matches) : (0, _utils.findSearchIndex)(selection.from, matches);
|
|
38
39
|
}
|
|
39
40
|
return {
|
|
40
41
|
type: _actions.FindReplaceActionTypes.ACTIVATE,
|
|
@@ -58,7 +59,7 @@ var find = exports.find = function find(editorView, containerElement, keyword) {
|
|
|
58
59
|
getIntl: getIntl,
|
|
59
60
|
api: api
|
|
60
61
|
}) : [];
|
|
61
|
-
var index = (0, _utils.findSearchIndex)(selection.from, matches);
|
|
62
|
+
var index = (0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true) && (0, _platformFeatureFlags.fg)('platform_editor_find_and_replace_improvements_1') ? (0, _utils.findClosestMatch)(selection.from, matches) : (0, _utils.findSearchIndex)(selection.from, matches);
|
|
62
63
|
|
|
63
64
|
// we can't just apply all the decorations to highlight the search results at once
|
|
64
65
|
// as if there are a lot ProseMirror cries :'(
|
|
@@ -87,7 +88,7 @@ var find = exports.find = function find(editorView, containerElement, keyword) {
|
|
|
87
88
|
api: api
|
|
88
89
|
}) : [];
|
|
89
90
|
if (matches.length > 0) {
|
|
90
|
-
var index = (0, _utils.findSearchIndex)(selection.from, matches);
|
|
91
|
+
var index = (0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true) && (0, _platformFeatureFlags.fg)('platform_editor_find_and_replace_improvements_1') ? (0, _utils.findClosestMatch)(selection.from, matches) : (0, _utils.findSearchIndex)(selection.from, matches);
|
|
91
92
|
return tr.setSelection((0, _utils.getSelectionForMatch)(tr.selection, tr.doc, index, matches));
|
|
92
93
|
}
|
|
93
94
|
return tr;
|
|
@@ -9,6 +9,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
10
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
11
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
12
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
12
14
|
var _main = require("./main");
|
|
13
15
|
var _pluginKey = require("./plugin-key");
|
|
14
16
|
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
@@ -101,7 +103,7 @@ var handleDocChanged = function handleDocChanged(tr, pluginState) {
|
|
|
101
103
|
});
|
|
102
104
|
}
|
|
103
105
|
if (newIndex === undefined || newIndex === -1) {
|
|
104
|
-
newIndex = (0, _utils2.findSearchIndex)(tr.selection.from, newMatches);
|
|
106
|
+
newIndex = (0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true) && (0, _platformFeatureFlags.fg)('platform_editor_find_and_replace_improvements_1') ? (0, _utils2.findClosestMatch)(tr.selection.from, newMatches) : (0, _utils2.findSearchIndex)(tr.selection.from, newMatches);
|
|
105
107
|
}
|
|
106
108
|
var newSelectedMatch = newMatches[newIndex];
|
|
107
109
|
decorationSet = (0, _utils2.removeMatchesFromSet)(decorationSet, [selectedMatch, newSelectedMatch], tr.doc);
|
|
@@ -4,7 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.createDecorations = exports.createDecoration = void 0;
|
|
8
|
+
exports.findClosestMatch = findClosestMatch;
|
|
9
|
+
exports.findLostAdjacentDecorations = exports.findIndexBeforePosition = exports.findDecorationFromMatch = void 0;
|
|
8
10
|
exports.findMatches = findMatches;
|
|
9
11
|
exports.findSearchIndex = findSearchIndex;
|
|
10
12
|
exports.getSelectedText = getSelectedText;
|
|
@@ -247,6 +249,22 @@ function findMatches(_ref2) {
|
|
|
247
249
|
}
|
|
248
250
|
return matches;
|
|
249
251
|
}
|
|
252
|
+
function findClosestMatch(selectionPos, matches) {
|
|
253
|
+
var forwardMatchIndex = Math.max(matches.findIndex(function (match) {
|
|
254
|
+
return match.start >= selectionPos;
|
|
255
|
+
}), 0);
|
|
256
|
+
if (forwardMatchIndex === 0) {
|
|
257
|
+
return forwardMatchIndex;
|
|
258
|
+
}
|
|
259
|
+
var backwardMatchIndex = forwardMatchIndex - 1;
|
|
260
|
+
var forwardMatchPos = matches[forwardMatchIndex].start;
|
|
261
|
+
var backwardMatchPos = matches[backwardMatchIndex].end;
|
|
262
|
+
if (forwardMatchPos - selectionPos < selectionPos - backwardMatchPos) {
|
|
263
|
+
return forwardMatchIndex;
|
|
264
|
+
} else {
|
|
265
|
+
return backwardMatchIndex;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
250
268
|
|
|
251
269
|
/**
|
|
252
270
|
* Finds index of first item in matches array that comes after user's cursor pos.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
5
|
import { FindReplaceActionTypes } from './actions';
|
|
5
6
|
import { createCommand, getPluginState } from './plugin-factory';
|
|
6
|
-
import { createDecoration, findDecorationFromMatch, findMatches, findSearchIndex, getSelectedText, getSelectionForMatch, nextIndex, prevIndex, removeDecorationsFromSet, removeMatchesFromSet } from './utils';
|
|
7
|
+
import { createDecoration, findClosestMatch, findDecorationFromMatch, findMatches, findSearchIndex, getSelectedText, getSelectionForMatch, nextIndex, prevIndex, removeDecorationsFromSet, removeMatchesFromSet } from './utils';
|
|
7
8
|
import batchDecorations from './utils/batch-decorations';
|
|
8
9
|
import { withScrollIntoView } from './utils/commands';
|
|
9
10
|
export const activate = () => createCommand(state => {
|
|
@@ -29,7 +30,7 @@ export const activate = () => createCommand(state => {
|
|
|
29
30
|
getIntl,
|
|
30
31
|
api
|
|
31
32
|
});
|
|
32
|
-
index = findSearchIndex(selection.from, matches);
|
|
33
|
+
index = expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) && fg('platform_editor_find_and_replace_improvements_1') ? findClosestMatch(selection.from, matches) : findSearchIndex(selection.from, matches);
|
|
33
34
|
}
|
|
34
35
|
return {
|
|
35
36
|
type: FindReplaceActionTypes.ACTIVATE,
|
|
@@ -54,7 +55,7 @@ export const find = (editorView, containerElement, keyword) => withScrollIntoVie
|
|
|
54
55
|
getIntl,
|
|
55
56
|
api
|
|
56
57
|
}) : [];
|
|
57
|
-
const index = findSearchIndex(selection.from, matches);
|
|
58
|
+
const index = expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) && fg('platform_editor_find_and_replace_improvements_1') ? findClosestMatch(selection.from, matches) : findSearchIndex(selection.from, matches);
|
|
58
59
|
|
|
59
60
|
// we can't just apply all the decorations to highlight the search results at once
|
|
60
61
|
// as if there are a lot ProseMirror cries :'(
|
|
@@ -82,7 +83,7 @@ export const find = (editorView, containerElement, keyword) => withScrollIntoVie
|
|
|
82
83
|
api
|
|
83
84
|
}) : [];
|
|
84
85
|
if (matches.length > 0) {
|
|
85
|
-
const index = findSearchIndex(selection.from, matches);
|
|
86
|
+
const index = expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) && fg('platform_editor_find_and_replace_improvements_1') ? findClosestMatch(selection.from, matches) : findSearchIndex(selection.from, matches);
|
|
86
87
|
return tr.setSelection(getSelectionForMatch(tr.selection, tr.doc, index, matches));
|
|
87
88
|
}
|
|
88
89
|
return tr;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { pluginFactory, stepHasSlice } from '@atlaskit/editor-common/utils';
|
|
2
2
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
3
5
|
import { initialState } from './main';
|
|
4
6
|
import { findReplacePluginKey } from './plugin-key';
|
|
5
7
|
import reducer from './reducer';
|
|
6
|
-
import { createDecorations, findDecorationFromMatch, findMatches, findSearchIndex, isMatchAffectedByStep, removeDecorationsFromSet, removeMatchesFromSet } from './utils';
|
|
8
|
+
import { createDecorations, findClosestMatch, findDecorationFromMatch, findMatches, findSearchIndex, isMatchAffectedByStep, removeDecorationsFromSet, removeMatchesFromSet } from './utils';
|
|
7
9
|
import { findUniqueItemsIn } from './utils/array'; // TODO: ED-26959 - move into index export
|
|
8
10
|
|
|
9
11
|
const handleDocChanged = (tr, pluginState) => {
|
|
@@ -81,7 +83,7 @@ const handleDocChanged = (tr, pluginState) => {
|
|
|
81
83
|
newIndex = newMatches.findIndex(match => match.start === selectedMatch.start);
|
|
82
84
|
}
|
|
83
85
|
if (newIndex === undefined || newIndex === -1) {
|
|
84
|
-
newIndex = findSearchIndex(tr.selection.from, newMatches);
|
|
86
|
+
newIndex = expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) && fg('platform_editor_find_and_replace_improvements_1') ? findClosestMatch(tr.selection.from, newMatches) : findSearchIndex(tr.selection.from, newMatches);
|
|
85
87
|
}
|
|
86
88
|
const newSelectedMatch = newMatches[newIndex];
|
|
87
89
|
decorationSet = removeMatchesFromSet(decorationSet, [selectedMatch, newSelectedMatch], tr.doc);
|
|
@@ -246,6 +246,20 @@ export function findMatches({
|
|
|
246
246
|
}
|
|
247
247
|
return matches;
|
|
248
248
|
}
|
|
249
|
+
export function findClosestMatch(selectionPos, matches) {
|
|
250
|
+
const forwardMatchIndex = Math.max(matches.findIndex(match => match.start >= selectionPos), 0);
|
|
251
|
+
if (forwardMatchIndex === 0) {
|
|
252
|
+
return forwardMatchIndex;
|
|
253
|
+
}
|
|
254
|
+
const backwardMatchIndex = forwardMatchIndex - 1;
|
|
255
|
+
const forwardMatchPos = matches[forwardMatchIndex].start;
|
|
256
|
+
const backwardMatchPos = matches[backwardMatchIndex].end;
|
|
257
|
+
if (forwardMatchPos - selectionPos < selectionPos - backwardMatchPos) {
|
|
258
|
+
return forwardMatchIndex;
|
|
259
|
+
} else {
|
|
260
|
+
return backwardMatchIndex;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
249
263
|
|
|
250
264
|
/**
|
|
251
265
|
* Finds index of first item in matches array that comes after user's cursor pos.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
5
|
import { FindReplaceActionTypes } from './actions';
|
|
5
6
|
import { createCommand, getPluginState } from './plugin-factory';
|
|
6
|
-
import { createDecoration, findDecorationFromMatch, findMatches, findSearchIndex, getSelectedText, getSelectionForMatch, nextIndex, prevIndex, removeDecorationsFromSet, removeMatchesFromSet } from './utils';
|
|
7
|
+
import { createDecoration, findClosestMatch, findDecorationFromMatch, findMatches, findSearchIndex, getSelectedText, getSelectionForMatch, nextIndex, prevIndex, removeDecorationsFromSet, removeMatchesFromSet } from './utils';
|
|
7
8
|
import batchDecorations from './utils/batch-decorations';
|
|
8
9
|
import { withScrollIntoView } from './utils/commands';
|
|
9
10
|
export var activate = function activate() {
|
|
@@ -27,7 +28,7 @@ export var activate = function activate() {
|
|
|
27
28
|
getIntl: getIntl,
|
|
28
29
|
api: api
|
|
29
30
|
});
|
|
30
|
-
index = findSearchIndex(selection.from, matches);
|
|
31
|
+
index = expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) && fg('platform_editor_find_and_replace_improvements_1') ? findClosestMatch(selection.from, matches) : findSearchIndex(selection.from, matches);
|
|
31
32
|
}
|
|
32
33
|
return {
|
|
33
34
|
type: FindReplaceActionTypes.ACTIVATE,
|
|
@@ -51,7 +52,7 @@ export var find = function find(editorView, containerElement, keyword) {
|
|
|
51
52
|
getIntl: getIntl,
|
|
52
53
|
api: api
|
|
53
54
|
}) : [];
|
|
54
|
-
var index = findSearchIndex(selection.from, matches);
|
|
55
|
+
var index = expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) && fg('platform_editor_find_and_replace_improvements_1') ? findClosestMatch(selection.from, matches) : findSearchIndex(selection.from, matches);
|
|
55
56
|
|
|
56
57
|
// we can't just apply all the decorations to highlight the search results at once
|
|
57
58
|
// as if there are a lot ProseMirror cries :'(
|
|
@@ -80,7 +81,7 @@ export var find = function find(editorView, containerElement, keyword) {
|
|
|
80
81
|
api: api
|
|
81
82
|
}) : [];
|
|
82
83
|
if (matches.length > 0) {
|
|
83
|
-
var index = findSearchIndex(selection.from, matches);
|
|
84
|
+
var index = expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) && fg('platform_editor_find_and_replace_improvements_1') ? findClosestMatch(selection.from, matches) : findSearchIndex(selection.from, matches);
|
|
84
85
|
return tr.setSelection(getSelectionForMatch(tr.selection, tr.doc, index, matches));
|
|
85
86
|
}
|
|
86
87
|
return tr;
|
|
@@ -4,10 +4,12 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
5
|
import { pluginFactory, stepHasSlice } from '@atlaskit/editor-common/utils';
|
|
6
6
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
8
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
7
9
|
import { initialState } from './main';
|
|
8
10
|
import { findReplacePluginKey } from './plugin-key';
|
|
9
11
|
import reducer from './reducer';
|
|
10
|
-
import { createDecorations, findDecorationFromMatch, findMatches, findSearchIndex, isMatchAffectedByStep, removeDecorationsFromSet, removeMatchesFromSet } from './utils';
|
|
12
|
+
import { createDecorations, findClosestMatch, findDecorationFromMatch, findMatches, findSearchIndex, isMatchAffectedByStep, removeDecorationsFromSet, removeMatchesFromSet } from './utils';
|
|
11
13
|
import { findUniqueItemsIn } from './utils/array'; // TODO: ED-26959 - move into index export
|
|
12
14
|
|
|
13
15
|
var handleDocChanged = function handleDocChanged(tr, pluginState) {
|
|
@@ -93,7 +95,7 @@ var handleDocChanged = function handleDocChanged(tr, pluginState) {
|
|
|
93
95
|
});
|
|
94
96
|
}
|
|
95
97
|
if (newIndex === undefined || newIndex === -1) {
|
|
96
|
-
newIndex = findSearchIndex(tr.selection.from, newMatches);
|
|
98
|
+
newIndex = expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) && fg('platform_editor_find_and_replace_improvements_1') ? findClosestMatch(tr.selection.from, newMatches) : findSearchIndex(tr.selection.from, newMatches);
|
|
97
99
|
}
|
|
98
100
|
var newSelectedMatch = newMatches[newIndex];
|
|
99
101
|
decorationSet = removeMatchesFromSet(decorationSet, [selectedMatch, newSelectedMatch], tr.doc);
|
|
@@ -236,6 +236,22 @@ export function findMatches(_ref2) {
|
|
|
236
236
|
}
|
|
237
237
|
return matches;
|
|
238
238
|
}
|
|
239
|
+
export function findClosestMatch(selectionPos, matches) {
|
|
240
|
+
var forwardMatchIndex = Math.max(matches.findIndex(function (match) {
|
|
241
|
+
return match.start >= selectionPos;
|
|
242
|
+
}), 0);
|
|
243
|
+
if (forwardMatchIndex === 0) {
|
|
244
|
+
return forwardMatchIndex;
|
|
245
|
+
}
|
|
246
|
+
var backwardMatchIndex = forwardMatchIndex - 1;
|
|
247
|
+
var forwardMatchPos = matches[forwardMatchIndex].start;
|
|
248
|
+
var backwardMatchPos = matches[backwardMatchIndex].end;
|
|
249
|
+
if (forwardMatchPos - selectionPos < selectionPos - backwardMatchPos) {
|
|
250
|
+
return forwardMatchIndex;
|
|
251
|
+
} else {
|
|
252
|
+
return backwardMatchIndex;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
239
255
|
|
|
240
256
|
/**
|
|
241
257
|
* Finds index of first item in matches array that comes after user's cursor pos.
|
|
@@ -20,6 +20,7 @@ type FindMatchesType = {
|
|
|
20
20
|
api?: ExtractInjectionAPI<FindReplacePlugin>;
|
|
21
21
|
};
|
|
22
22
|
export declare function findMatches({ content, searchText, shouldMatchCase, contentIndex, getIntl, api, }: FindMatchesType): Match[];
|
|
23
|
+
export declare function findClosestMatch(selectionPos: number, matches: Match[]): number;
|
|
23
24
|
/**
|
|
24
25
|
* Finds index of first item in matches array that comes after user's cursor pos.
|
|
25
26
|
* If `backward` is `true`, finds index of first item that comes before instead.
|
|
@@ -20,6 +20,7 @@ type FindMatchesType = {
|
|
|
20
20
|
api?: ExtractInjectionAPI<FindReplacePlugin>;
|
|
21
21
|
};
|
|
22
22
|
export declare function findMatches({ content, searchText, shouldMatchCase, contentIndex, getIntl, api, }: FindMatchesType): Match[];
|
|
23
|
+
export declare function findClosestMatch(selectionPos: number, matches: Match[]): number;
|
|
23
24
|
/**
|
|
24
25
|
* Finds index of first item in matches array that comes after user's cursor pos.
|
|
25
26
|
* If `backward` is `true`, finds index of first item that comes before instead.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-find-replace",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "find replace plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,22 +33,21 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@atlaskit/button": "^23.2.0",
|
|
36
|
-
"@atlaskit/editor-
|
|
37
|
-
"@atlaskit/editor-plugin-
|
|
38
|
-
"@atlaskit/editor-plugin-
|
|
39
|
-
"@atlaskit/editor-plugin-
|
|
40
|
-
"@atlaskit/editor-plugin-primary-toolbar": "^3.2.0",
|
|
36
|
+
"@atlaskit/editor-plugin-analytics": "^3.0.0",
|
|
37
|
+
"@atlaskit/editor-plugin-card": "^7.0.0",
|
|
38
|
+
"@atlaskit/editor-plugin-mentions": "^5.1.0",
|
|
39
|
+
"@atlaskit/editor-plugin-primary-toolbar": "^4.0.0",
|
|
41
40
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
42
41
|
"@atlaskit/editor-shared-styles": "^3.4.0",
|
|
43
42
|
"@atlaskit/form": "^12.0.0",
|
|
44
|
-
"@atlaskit/icon": "^27.
|
|
43
|
+
"@atlaskit/icon": "^27.3.0",
|
|
45
44
|
"@atlaskit/icon-lab": "^5.1.0",
|
|
46
45
|
"@atlaskit/mention": "^24.2.0",
|
|
47
46
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
48
47
|
"@atlaskit/primitives": "^14.10.0",
|
|
49
48
|
"@atlaskit/textfield": "^8.0.0",
|
|
50
49
|
"@atlaskit/theme": "^18.0.0",
|
|
51
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
50
|
+
"@atlaskit/tmp-editor-statsig": "^9.0.0",
|
|
52
51
|
"@atlaskit/tokens": "^5.4.0",
|
|
53
52
|
"@atlaskit/tooltip": "^20.3.0",
|
|
54
53
|
"@babel/runtime": "^7.0.0",
|
|
@@ -59,8 +58,8 @@
|
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|
|
61
60
|
"@af/visual-regression": "workspace:^",
|
|
62
|
-
"@atlaskit/editor-plugin-block-type": "^
|
|
63
|
-
"@atlaskit/editor-plugin-text-formatting": "^
|
|
61
|
+
"@atlaskit/editor-plugin-block-type": "^6.0.0",
|
|
62
|
+
"@atlaskit/editor-plugin-text-formatting": "^3.0.0",
|
|
64
63
|
"@testing-library/react": "^13.4.0",
|
|
65
64
|
"@testing-library/user-event": "^14.4.3",
|
|
66
65
|
"mockdate": "^3.0.5",
|
|
@@ -68,6 +67,7 @@
|
|
|
68
67
|
"react-dom": "^18.2.0"
|
|
69
68
|
},
|
|
70
69
|
"peerDependencies": {
|
|
70
|
+
"@atlaskit/editor-common": "^107.7.0",
|
|
71
71
|
"react": "^18.2.0",
|
|
72
72
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
73
73
|
},
|