jodit 3.15.2 → 3.16.2
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/.idea/workspace.xml +301 -299
- package/CHANGELOG.MD +88 -7
- package/CONTRIBUTING.md +97 -0
- package/README.md +7 -7
- package/build/jodit.css +38 -32
- package/build/jodit.es2018.css +37 -31
- package/build/jodit.es2018.en.css +37 -31
- package/build/jodit.es2018.en.js +1981 -1393
- package/build/jodit.es2018.en.min.css +1 -1
- package/build/jodit.es2018.en.min.js +1 -1
- package/build/jodit.es2018.js +2053 -1447
- package/build/jodit.es2018.min.css +1 -1
- package/build/jodit.es2018.min.js +1 -1
- package/build/jodit.js +3475 -2625
- package/build/jodit.min.css +2 -2
- package/build/jodit.min.js +1 -1
- package/build/vdom.css +1 -1
- package/build/vdom.js +32 -20
- package/package.json +13 -13
- package/src/README.md +1 -1
- package/src/config.ts +69 -36
- package/src/core/async/async.ts +46 -24
- package/src/core/constants.ts +1 -0
- package/src/core/decorators/README.md +35 -0
- package/src/core/decorators/cache/cache.ts +1 -1
- package/src/core/decorators/debounce/debounce.ts +20 -9
- package/src/core/decorators/idle/README.md +14 -0
- package/src/core/decorators/idle/idle.ts +1 -1
- package/src/core/decorators/watch/watch.ts +8 -7
- package/src/core/dom/README.md +42 -0
- package/src/core/dom/dom.ts +37 -23
- package/src/core/dom/index.ts +1 -0
- package/src/core/dom/lazy-walker.ts +133 -0
- package/src/core/event-emitter/event-emitter.ts +8 -8
- package/src/core/event-emitter/eventify.ts +73 -0
- package/src/core/event-emitter/index.ts +1 -0
- package/src/core/helpers/html/apply-styles.ts +1 -1
- package/src/core/helpers/html/strip-tags.ts +3 -2
- package/src/core/helpers/string/fuzzy-search-index.ts +58 -0
- package/src/core/helpers/string/i18n.ts +1 -1
- package/src/core/helpers/string/index.ts +3 -2
- package/src/core/helpers/utils/append-script.ts +1 -1
- package/src/core/helpers/utils/css.ts +1 -1
- package/src/core/helpers/utils/selector.ts +1 -1
- package/src/core/helpers/utils/utils.ts +3 -3
- package/src/core/plugin/plugin-system.ts +14 -8
- package/src/core/request/ajax.ts +3 -3
- package/src/core/selection/select.ts +10 -10
- package/src/core/selection/style/api/toggle/toggle-css.ts +5 -2
- package/src/core/selection/style/api/wrap-unwrapped-text.ts +1 -1
- package/src/core/selection/style/apply-style.ts +4 -4
- package/src/core/storage/engines/local-storage-provider.ts +20 -19
- package/src/core/ui/button/button/button.ts +5 -5
- package/src/core/ui/element.ts +2 -2
- package/src/core/ui/form/inputs/input/input.ts +1 -1
- package/src/core/ui/form/inputs/select/select.ts +1 -1
- package/src/core/ui/group/list.ts +2 -2
- package/src/core/vdom/render/index.ts +12 -8
- package/src/core/vdom/v-dom-jodit.ts +1 -1
- package/src/core/view/view.ts +1 -1
- package/src/index.ts +3 -3
- package/src/jodit.ts +72 -55
- package/src/langs/README.md +1 -1
- package/src/langs/ar.js +2 -1
- package/src/langs/cs_cz.js +2 -1
- package/src/langs/de.js +2 -1
- package/src/langs/es.js +2 -1
- package/src/langs/fa.js +2 -1
- package/src/langs/fr.js +2 -1
- package/src/langs/he.js +2 -1
- package/src/langs/hu.js +2 -1
- package/src/langs/id.js +2 -1
- package/src/langs/index.ts +1 -1
- package/src/langs/it.js +2 -1
- package/src/langs/ja.js +2 -1
- package/src/langs/ko.js +2 -1
- package/src/langs/nl.js +2 -1
- package/src/langs/pl.js +2 -1
- package/src/langs/pt_br.js +2 -1
- package/src/langs/ru.js +2 -1
- package/src/langs/tr.js +2 -1
- package/src/langs/zh_cn.js +2 -1
- package/src/langs/zh_tw.js +2 -1
- package/src/modules/dialog/dialog.ts +6 -6
- package/src/modules/dialog/prompt.ts +1 -1
- package/src/modules/file-browser/README.md +2 -2
- package/src/modules/file-browser/builders/context-menu.ts +12 -13
- package/src/modules/file-browser/fetch/load-tree.ts +1 -1
- package/src/modules/file-browser/file-browser.ts +10 -7
- package/src/modules/history/README.md +5 -0
- package/src/modules/{observer → history}/command.ts +5 -5
- package/src/modules/{observer/observer.ts → history/history.ts} +97 -55
- package/src/modules/{observer → history}/snapshot.ts +3 -4
- package/src/modules/{observer → history}/stack.ts +4 -4
- package/src/modules/image-editor/image-editor.ts +8 -8
- package/src/modules/image-editor/templates/form.ts +2 -2
- package/src/modules/index.ts +3 -3
- package/src/modules/status-bar/status-bar.ts +4 -0
- package/src/modules/table/table.ts +2 -2
- package/src/modules/toolbar/button/button.ts +2 -2
- package/src/modules/toolbar/collection/collection.ts +1 -1
- package/src/modules/uploader/helpers/process-old-browser-drag.ts +1 -1
- package/src/modules/uploader/helpers/send-files.ts +1 -1
- package/src/modules/uploader/helpers/send.ts +1 -1
- package/src/modules/uploader/uploader.ts +3 -3
- package/src/modules/widget/color-picker/color-picker.ts +2 -3
- package/src/modules/widget/tabs/tabs.ts +17 -12
- package/src/plugins/add-new-line/add-new-line.ts +8 -8
- package/src/plugins/class-span/class-span.ts +1 -1
- package/src/plugins/clipboard/copy-format.ts +1 -1
- package/src/plugins/clipboard/drag-and-drop-element.ts +4 -2
- package/src/plugins/clipboard/paste/config.ts +19 -3
- package/src/plugins/clipboard/paste/helpers.ts +17 -50
- package/src/plugins/clipboard/paste/interface.ts +6 -0
- package/src/plugins/clipboard/paste/paste.ts +22 -8
- package/src/plugins/clipboard/paste-from-word/config.ts +17 -0
- package/src/plugins/clipboard/paste-from-word/paste-from-word.ts +15 -6
- package/src/plugins/clipboard/paste-storage/paste-storage.ts +6 -6
- package/src/plugins/color/color.ts +2 -2
- package/src/plugins/error-messages/error-messages.ts +2 -2
- package/src/plugins/fix/clean-html/README.md +26 -0
- package/src/plugins/fix/{clean-html.ts → clean-html/clean-html.ts} +59 -142
- package/src/plugins/fix/clean-html/config.ts +106 -0
- package/src/plugins/fix/index.ts +12 -0
- package/src/plugins/fix/wrap-nodes/README.md +27 -0
- package/src/plugins/fix/wrap-nodes/config.ts +24 -0
- package/src/plugins/fix/{wrap-text-nodes.ts → wrap-nodes/wrap-nodes.ts} +9 -4
- package/src/plugins/focus/focus.ts +1 -1
- package/src/plugins/format-block/format-block.ts +1 -1
- package/src/plugins/fullsize/fullsize.ts +4 -4
- package/src/plugins/iframe/iframe.ts +3 -3
- package/src/plugins/image/image-properties/image-properties.ts +12 -13
- package/src/plugins/indent/indent.ts +1 -1
- package/src/plugins/index.ts +2 -2
- package/src/plugins/inline-popup/config/items/a.ts +2 -2
- package/src/plugins/inline-popup/config/items/cells.ts +11 -11
- package/src/plugins/inline-popup/config/items/iframe.ts +1 -1
- package/src/plugins/inline-popup/config/items/img.ts +7 -7
- package/src/plugins/inline-popup/inline-popup.ts +5 -5
- package/src/plugins/keyboard/backspace/backspace.ts +1 -1
- package/src/plugins/keyboard/backspace/cases/check-join-neighbors.ts +1 -1
- package/src/plugins/keyboard/helpers.ts +1 -1
- package/src/plugins/keyboard/hotkeys.ts +1 -1
- package/src/plugins/limit/limit.ts +3 -3
- package/src/plugins/line-height/line-height.ts +1 -1
- package/src/plugins/link/link.ts +8 -8
- package/src/plugins/link/template.ts +2 -2
- package/src/plugins/media/file.ts +1 -1
- package/src/plugins/media/media.ts +1 -1
- package/src/plugins/media/video/config.ts +1 -1
- package/src/plugins/mobile/config.ts +1 -1
- package/src/plugins/mobile/mobile.ts +1 -1
- package/src/plugins/ordered-list/config.ts +61 -0
- package/src/plugins/ordered-list/ordered-list.ts +3 -153
- package/src/plugins/placeholder/placeholder.ts +3 -3
- package/src/plugins/print/helpers.ts +14 -7
- package/src/plugins/print/index.ts +1 -1
- package/src/plugins/print/{preview.less → preview/preview.less} +1 -1
- package/src/plugins/print/{preview.ts → preview/preview.ts} +9 -8
- package/src/plugins/print/print.ts +19 -10
- package/src/plugins/redo-undo/redo-undo.ts +3 -3
- package/src/plugins/resizer/resizer.ts +11 -11
- package/src/plugins/search/README.md +38 -0
- package/src/plugins/search/config.ts +82 -0
- package/src/plugins/search/helpers/index.ts +12 -0
- package/src/plugins/search/helpers/sentence-finder.ts +103 -0
- package/src/plugins/search/helpers/wrap-ranges-texts-in-tmp-span.ts +120 -0
- package/src/plugins/search/search.ts +269 -615
- package/src/plugins/search/ui/search.less +159 -0
- package/src/plugins/search/ui/search.ts +256 -0
- package/src/plugins/select/select.ts +1 -1
- package/src/plugins/size/config.ts +8 -8
- package/src/plugins/size/resize-handler.ts +3 -3
- package/src/plugins/size/size.ts +4 -4
- package/src/plugins/source/editor/engines/ace.ts +9 -9
- package/src/plugins/source/editor/engines/area.ts +3 -3
- package/src/plugins/source/source.ts +6 -6
- package/src/plugins/spellcheck/README.md +1 -0
- package/src/plugins/spellcheck/config.ts +34 -0
- package/src/plugins/spellcheck/spellcheck.svg +4 -0
- package/src/plugins/spellcheck/spellcheck.ts +48 -0
- package/src/plugins/sticky/sticky.ts +3 -3
- package/src/plugins/table/resize-cells.ts +11 -11
- package/src/plugins/table/select-cells.ts +2 -2
- package/src/plugins/tooltip/tooltip.ts +1 -1
- package/src/plugins/xpath/xpath.ts +8 -8
- package/src/polyfills.ts +5 -4
- package/src/styles/icons/README.md +2 -2
- package/src/types/async.d.ts +12 -2
- package/src/types/core.ts +1 -1
- package/src/types/events.d.ts +6 -2
- package/src/types/file-browser.d.ts +1 -2
- package/{types/types/observer.d.ts → src/types/history.d.ts} +11 -7
- package/src/types/index.d.ts +1 -1
- package/src/types/jodit.d.ts +12 -4
- package/src/types/toolbar.d.ts +5 -5
- package/src/types/types.d.ts +11 -4
- package/types/config.d.ts +68 -35
- package/types/core/async/async.d.ts +11 -4
- package/types/core/constants.d.ts +1 -0
- package/types/core/dom/dom.d.ts +3 -5
- package/types/core/dom/index.d.ts +1 -0
- package/types/core/dom/lazy-walker.d.ts +37 -0
- package/types/core/event-emitter/eventify.d.ts +39 -0
- package/types/core/event-emitter/index.d.ts +1 -0
- package/types/core/helpers/string/fuzzy-search-index.d.ts +10 -0
- package/types/core/helpers/string/i18n.d.ts +1 -1
- package/types/core/helpers/string/index.d.ts +3 -2
- package/types/core/helpers/utils/utils.d.ts +1 -1
- package/types/core/selection/select.d.ts +1 -1
- package/types/core/ui/button/button/button.d.ts +4 -4
- package/types/core/view/view.d.ts +1 -1
- package/types/jodit.d.ts +19 -6
- package/types/modules/{observer → history}/command.d.ts +4 -4
- package/types/modules/{observer/observer.d.ts → history/history.d.ts} +17 -9
- package/types/modules/{observer → history}/snapshot.d.ts +1 -1
- package/types/modules/{observer → history}/stack.d.ts +3 -3
- package/types/modules/image-editor/image-editor.d.ts +1 -1
- package/types/modules/index.d.ts +3 -3
- package/types/modules/toolbar/button/button.d.ts +2 -5
- package/types/modules/widget/tabs/tabs.d.ts +1 -1
- package/types/plugins/class-span/class-span.d.ts +1 -1
- package/types/plugins/clipboard/paste/config.d.ts +8 -0
- package/types/plugins/clipboard/paste/helpers.d.ts +2 -2
- package/types/plugins/clipboard/paste/interface.d.ts +5 -0
- package/types/plugins/clipboard/paste-from-word/config.d.ts +5 -0
- package/types/plugins/clipboard/paste-from-word/paste-from-word.d.ts +3 -2
- package/types/plugins/fix/clean-html/clean-html.d.ts +70 -0
- package/types/plugins/fix/{clean-html.d.ts → clean-html/config.d.ts} +2 -57
- package/types/plugins/fix/index.d.ts +10 -0
- package/types/plugins/fix/wrap-nodes/config.d.ts +16 -0
- package/types/plugins/fix/{wrap-text-nodes.d.ts → wrap-nodes/wrap-nodes.d.ts} +5 -2
- package/types/plugins/fullsize/fullsize.d.ts +2 -2
- package/types/plugins/index.d.ts +2 -2
- package/types/plugins/ordered-list/config.d.ts +6 -0
- package/types/plugins/ordered-list/ordered-list.d.ts +1 -1
- package/types/plugins/print/helpers.d.ts +2 -2
- package/types/plugins/print/index.d.ts +1 -1
- package/types/plugins/print/{preview.d.ts → preview/preview.d.ts} +1 -1
- package/types/plugins/search/config.d.ts +36 -0
- package/types/plugins/search/helpers/index.d.ts +10 -0
- package/types/plugins/search/helpers/sentence-finder.d.ts +21 -0
- package/types/plugins/search/helpers/wrap-ranges-texts-in-tmp-span.d.ts +14 -0
- package/types/plugins/search/search.d.ts +25 -39
- package/types/plugins/search/ui/search.d.ts +37 -0
- package/types/plugins/spellcheck/config.d.ts +15 -0
- package/types/plugins/spellcheck/spellcheck.d.ts +19 -0
- package/types/plugins/sticky/sticky.d.ts +2 -2
- package/types/types/async.d.ts +12 -2
- package/types/types/core.d.ts +1 -1
- package/types/types/core.ts +1 -1
- package/types/types/events.d.ts +6 -2
- package/types/types/file-browser.d.ts +1 -2
- package/{src/types/observer.d.ts → types/types/history.d.ts} +11 -7
- package/types/types/index.d.ts +1 -1
- package/types/types/jodit.d.ts +12 -4
- package/types/types/toolbar.d.ts +5 -5
- package/types/types/types.d.ts +11 -4
- package/src/modules/observer/README.md +0 -0
- package/src/plugins/search/search.less +0 -152
|
@@ -5,74 +5,34 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
+
* [[include:plugins/search/README.md]]
|
|
9
|
+
* @packageDocumentation
|
|
8
10
|
* @module plugins/search
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
|
-
import './search.less';
|
|
12
|
-
|
|
13
13
|
import type {
|
|
14
14
|
ISelectionRange,
|
|
15
|
-
MarkerInfo,
|
|
16
15
|
IJodit,
|
|
17
16
|
Nullable,
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
IPlugin,
|
|
18
|
+
IDictionary,
|
|
19
|
+
CanUndef,
|
|
20
|
+
RejectablePromise
|
|
20
21
|
} from 'jodit/types';
|
|
21
|
-
import {
|
|
22
|
-
import * as consts from 'jodit/core/constants';
|
|
23
|
-
import { MODE_WYSIWYG } from 'jodit/core/constants';
|
|
24
|
-
import { Dom } from 'jodit/core/dom';
|
|
22
|
+
import { Dom, LazyWalker } from 'jodit/core/dom';
|
|
25
23
|
import { Plugin } from 'jodit/core/plugin';
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
Config.prototype.useSearch = true;
|
|
42
|
-
|
|
43
|
-
Config.prototype.controls.find = {
|
|
44
|
-
tooltip: 'Find',
|
|
45
|
-
icon: 'search',
|
|
46
|
-
exec(jodit: IJodit, _, { control }) {
|
|
47
|
-
const value = control.args && control.args[0];
|
|
48
|
-
|
|
49
|
-
switch (value) {
|
|
50
|
-
case 'findPrevious':
|
|
51
|
-
jodit.e.fire('searchPrevious');
|
|
52
|
-
break;
|
|
53
|
-
|
|
54
|
-
case 'findNext':
|
|
55
|
-
jodit.e.fire('searchNext');
|
|
56
|
-
break;
|
|
57
|
-
|
|
58
|
-
case 'replace':
|
|
59
|
-
jodit.execCommand('openReplaceDialog');
|
|
60
|
-
break;
|
|
61
|
-
|
|
62
|
-
default:
|
|
63
|
-
jodit.execCommand('openSearchDialog');
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
list: {
|
|
68
|
-
search: 'Find',
|
|
69
|
-
findNext: 'Find Next',
|
|
70
|
-
findPrevious: 'Find Previous',
|
|
71
|
-
replace: 'Replace'
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
childTemplate: (_, k, v) => v
|
|
75
|
-
} as IControlType;
|
|
24
|
+
import { autobind, cache, watch } from 'jodit/core/decorators';
|
|
25
|
+
import {
|
|
26
|
+
clearSelectionWrappers,
|
|
27
|
+
clearSelectionWrappersFromHTML,
|
|
28
|
+
getSelectionWrappers,
|
|
29
|
+
SentenceFinder,
|
|
30
|
+
wrapRangesTextsInTmpSpan
|
|
31
|
+
} from 'jodit/plugins/search/helpers';
|
|
32
|
+
import { UISearch } from 'jodit/plugins/search/ui/search';
|
|
33
|
+
|
|
34
|
+
import './config';
|
|
35
|
+
import { scrollIntoViewIfNeeded } from 'jodit/core/helpers';
|
|
76
36
|
|
|
77
37
|
/**
|
|
78
38
|
* Search plugin. it is used for custom search in text
|
|
@@ -80,11 +40,11 @@ Config.prototype.controls.find = {
|
|
|
80
40
|
*
|
|
81
41
|
* @example
|
|
82
42
|
* ```typescript
|
|
83
|
-
* var jodit =
|
|
43
|
+
* var jodit = Jodit.make('#editor', {
|
|
84
44
|
* useSearch: false
|
|
85
45
|
* });
|
|
86
46
|
* // or
|
|
87
|
-
* var jodit =
|
|
47
|
+
* var jodit = Jodit.make('#editor', {
|
|
88
48
|
* disablePlugins: 'search'
|
|
89
49
|
* });
|
|
90
50
|
* ```
|
|
@@ -97,159 +57,27 @@ export class search extends Plugin {
|
|
|
97
57
|
}
|
|
98
58
|
];
|
|
99
59
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
start: boolean = true
|
|
104
|
-
): number | false {
|
|
105
|
-
return this.findSomePartOfString(needle, haystack, start, true) as
|
|
106
|
-
| number
|
|
107
|
-
| false;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static findSomePartOfString(
|
|
111
|
-
needle: string,
|
|
112
|
-
haystack: string,
|
|
113
|
-
start: boolean = true,
|
|
114
|
-
getIndex: boolean = false
|
|
115
|
-
): boolean | string | number {
|
|
116
|
-
needle = trim(
|
|
117
|
-
needle.toLowerCase().replace(consts.SPACE_REG_EXP(), ' ')
|
|
118
|
-
);
|
|
119
|
-
haystack = haystack.toLowerCase();
|
|
120
|
-
|
|
121
|
-
let i: number = start ? 0 : haystack.length - 1,
|
|
122
|
-
needleStart: number = start ? 0 : needle.length - 1,
|
|
123
|
-
tmpEqualLength: number = 0,
|
|
124
|
-
startAtIndex: number | null = null;
|
|
125
|
-
|
|
126
|
-
const inc = start ? 1 : -1,
|
|
127
|
-
tmp: string[] = [];
|
|
128
|
-
|
|
129
|
-
for (; haystack[i] !== undefined; i += inc) {
|
|
130
|
-
const some: boolean = needle[needleStart] === haystack[i];
|
|
131
|
-
if (
|
|
132
|
-
some ||
|
|
133
|
-
(startAtIndex != null &&
|
|
134
|
-
consts.SPACE_REG_EXP().test(haystack[i]))
|
|
135
|
-
) {
|
|
136
|
-
if (startAtIndex == null || !start) {
|
|
137
|
-
startAtIndex = i;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
tmp.push(haystack[i]);
|
|
141
|
-
|
|
142
|
-
if (some) {
|
|
143
|
-
tmpEqualLength += 1;
|
|
144
|
-
needleStart += inc;
|
|
145
|
-
}
|
|
146
|
-
} else {
|
|
147
|
-
startAtIndex = null;
|
|
148
|
-
tmp.length = 0;
|
|
149
|
-
tmpEqualLength = 0;
|
|
150
|
-
needleStart = start ? 0 : needle.length - 1;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (tmpEqualLength === needle.length) {
|
|
154
|
-
return getIndex ? (startAtIndex as number) : true;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (getIndex) {
|
|
159
|
-
return startAtIndex ?? false;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (tmp.length) {
|
|
163
|
-
return start ? tmp.join('') : tmp.reverse().join('');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return false;
|
|
60
|
+
@cache
|
|
61
|
+
private get ui(): UISearch {
|
|
62
|
+
return new UISearch(this.j);
|
|
167
63
|
}
|
|
168
64
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
<input data-ref="query" tabindex="0" placeholder="${this.j.i18n(
|
|
173
|
-
'Search for'
|
|
174
|
-
)}" type="text"/>
|
|
175
|
-
<input data-ref="replace" tabindex="0" placeholder="${this.j.i18n(
|
|
176
|
-
'Replace with'
|
|
177
|
-
)}" type="text"/>
|
|
178
|
-
</div>
|
|
179
|
-
<div class="jodit-search__counts">
|
|
180
|
-
<span data-ref="counter-box">0/0</span>
|
|
181
|
-
</div>
|
|
182
|
-
<div class="jodit-search__buttons">
|
|
183
|
-
<button data-ref="next" tabindex="0" type="button">${Icon.get(
|
|
184
|
-
'angle-down'
|
|
185
|
-
)}</button>
|
|
186
|
-
<button data-ref="prev" tabindex="0" type="button">${Icon.get(
|
|
187
|
-
'angle-up'
|
|
188
|
-
)}</button>
|
|
189
|
-
<button data-ref="cancel" tabindex="0" type="button">${Icon.get(
|
|
190
|
-
'cancel'
|
|
191
|
-
)}</button>
|
|
192
|
-
<button data-ref="replace-btn" tabindex="0" type="button" class="jodit-ui-button">${this.j.i18n(
|
|
193
|
-
'Replace'
|
|
194
|
-
)}</button>
|
|
195
|
-
</div>
|
|
196
|
-
</div>
|
|
197
|
-
</div>`;
|
|
198
|
-
|
|
199
|
-
private isOpened: boolean = false;
|
|
200
|
-
|
|
201
|
-
private selInfo: Nullable<MarkerInfo[]> = null;
|
|
202
|
-
private current: Nullable<Node> = null;
|
|
203
|
-
|
|
204
|
-
private eachMap = (
|
|
205
|
-
node: Node,
|
|
206
|
-
callback: (elm: Node) => boolean,
|
|
207
|
-
next: boolean
|
|
208
|
-
) => {
|
|
209
|
-
Dom.findWithCurrent(
|
|
210
|
-
node,
|
|
211
|
-
(child: Node | null): boolean => {
|
|
212
|
-
return Boolean(child && callback(child));
|
|
213
|
-
},
|
|
214
|
-
this.j.editor,
|
|
215
|
-
next ? 'nextSibling' : 'previousSibling',
|
|
216
|
-
next ? 'firstChild' : 'lastChild'
|
|
217
|
-
);
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
private updateCounters = () => {
|
|
221
|
-
if (!this.isOpened) {
|
|
65
|
+
@watch('ui:needUpdateCounters')
|
|
66
|
+
private async updateCounters(): Promise<void> {
|
|
67
|
+
if (!this.ui.isOpened) {
|
|
222
68
|
return;
|
|
223
69
|
}
|
|
224
70
|
|
|
225
|
-
this.
|
|
226
|
-
|
|
227
|
-
: 'none';
|
|
71
|
+
this.ui.count = await this.calcCounts(this.ui.query);
|
|
72
|
+
}
|
|
228
73
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
this.counterBox.textContent = counts.join('/');
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
private boundAlreadyWas(
|
|
239
|
-
current: ISelectionRange,
|
|
240
|
-
bounds: ISelectionRange[]
|
|
241
|
-
): boolean {
|
|
242
|
-
return bounds.some((bound: ISelectionRange) => {
|
|
243
|
-
return (
|
|
244
|
-
bound.startContainer === current.startContainer &&
|
|
245
|
-
bound.endContainer === current.endContainer &&
|
|
246
|
-
bound.startOffset === current.startOffset &&
|
|
247
|
-
bound.endOffset === current.endOffset
|
|
248
|
-
);
|
|
249
|
-
}, false);
|
|
74
|
+
@watch('ui:pressReplaceButton')
|
|
75
|
+
protected onPressReplaceButton(): void {
|
|
76
|
+
this.findAndReplace(this.ui.query);
|
|
77
|
+
this.updateCounters();
|
|
250
78
|
}
|
|
251
79
|
|
|
252
|
-
private tryScrollToElement(startContainer: Node) {
|
|
80
|
+
private tryScrollToElement(startContainer: Node): void {
|
|
253
81
|
// find scrollable element
|
|
254
82
|
let parentBox: HTMLElement | false = Dom.closest(
|
|
255
83
|
startContainer,
|
|
@@ -265,449 +93,302 @@ export class search extends Plugin {
|
|
|
265
93
|
) as HTMLElement | false;
|
|
266
94
|
}
|
|
267
95
|
|
|
268
|
-
parentBox &&
|
|
96
|
+
parentBox &&
|
|
97
|
+
parentBox !== this.j.editor &&
|
|
98
|
+
scrollIntoViewIfNeeded(parentBox, this.j.editor, this.j.ed);
|
|
269
99
|
}
|
|
270
100
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
closeButton!: HTMLButtonElement;
|
|
275
|
-
nextButton!: HTMLButtonElement;
|
|
276
|
-
prevButton!: HTMLButtonElement;
|
|
277
|
-
replaceButton!: HTMLButtonElement;
|
|
278
|
-
counterBox!: HTMLSpanElement;
|
|
279
|
-
|
|
280
|
-
calcCounts = (
|
|
281
|
-
query: string,
|
|
282
|
-
current: ISelectionRange | false = false
|
|
283
|
-
): [number, number] => {
|
|
284
|
-
const bounds: ISelectionRange[] = [];
|
|
285
|
-
|
|
286
|
-
let currentIndex: number = 0,
|
|
287
|
-
count: number = 0,
|
|
288
|
-
bound: ISelectionRange | false = false,
|
|
289
|
-
start: Node | null = this.j.editor.firstChild;
|
|
290
|
-
|
|
291
|
-
while (start && query.length) {
|
|
292
|
-
bound = this.find(
|
|
293
|
-
start,
|
|
294
|
-
query,
|
|
295
|
-
true,
|
|
296
|
-
0,
|
|
297
|
-
(bound as Range) || this.j.ed.createRange()
|
|
298
|
-
);
|
|
299
|
-
if (bound) {
|
|
300
|
-
if (this.boundAlreadyWas(bound, bounds)) {
|
|
301
|
-
break;
|
|
302
|
-
}
|
|
303
|
-
bounds.push(bound);
|
|
304
|
-
start = bound.startContainer;
|
|
305
|
-
count += 1;
|
|
306
|
-
if (current && this.boundAlreadyWas(current, [bound])) {
|
|
307
|
-
currentIndex = count;
|
|
308
|
-
}
|
|
309
|
-
} else {
|
|
310
|
-
start = null;
|
|
311
|
-
}
|
|
101
|
+
protected async calcCounts(query: string): Promise<number> {
|
|
102
|
+
if (this.walkerCount) {
|
|
103
|
+
this.walkerCount.break();
|
|
312
104
|
}
|
|
313
105
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
findAndReplace = (start: Node | null, query: string): boolean => {
|
|
318
|
-
const range = this.j.s.range,
|
|
319
|
-
bound: ISelectionRange | false = this.find(
|
|
320
|
-
start,
|
|
321
|
-
query,
|
|
322
|
-
true,
|
|
323
|
-
0,
|
|
324
|
-
range
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
if (bound && bound.startContainer && bound.endContainer) {
|
|
328
|
-
const rng = this.j.ed.createRange();
|
|
106
|
+
this.walkerCount = new LazyWalker(this.j.async, {
|
|
107
|
+
timeout: this.j.o.search.lazyIdleTimeout
|
|
108
|
+
});
|
|
329
109
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
bound.startContainer,
|
|
334
|
-
bound.startOffset as number
|
|
335
|
-
);
|
|
336
|
-
|
|
337
|
-
rng.setEnd(bound.endContainer, bound.endOffset as number);
|
|
338
|
-
rng.deleteContents();
|
|
339
|
-
|
|
340
|
-
const textNode: Node = this.j.createInside.text(
|
|
341
|
-
this.replaceInput.value
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
rng.insertNode(textNode);
|
|
345
|
-
this.j.s.select(textNode);
|
|
346
|
-
this.tryScrollToElement(textNode);
|
|
347
|
-
}
|
|
348
|
-
} catch {}
|
|
110
|
+
const result = await this.find(this.walkerCount, query);
|
|
111
|
+
return result.length;
|
|
112
|
+
}
|
|
349
113
|
|
|
350
|
-
|
|
114
|
+
@autobind
|
|
115
|
+
async findAndReplace(query: string): Promise<boolean> {
|
|
116
|
+
if (this.walker) {
|
|
117
|
+
this.walker.break();
|
|
351
118
|
}
|
|
352
119
|
|
|
353
|
-
|
|
354
|
-
|
|
120
|
+
this.walker = new LazyWalker(this.j.async, {
|
|
121
|
+
timeout: this.j.o.search.lazyIdleTimeout
|
|
122
|
+
});
|
|
355
123
|
|
|
356
|
-
findAndSelect = (
|
|
357
|
-
start: Node | null,
|
|
358
|
-
query: string,
|
|
359
|
-
next: boolean
|
|
360
|
-
): boolean => {
|
|
361
124
|
const range = this.j.s.range,
|
|
362
|
-
|
|
363
|
-
start,
|
|
364
|
-
query,
|
|
365
|
-
next,
|
|
366
|
-
0,
|
|
367
|
-
range
|
|
368
|
-
);
|
|
125
|
+
bounds = await this.find(this.walker, query);
|
|
369
126
|
|
|
370
|
-
|
|
371
|
-
const rng: Range = this.j.ed.createRange();
|
|
127
|
+
let currentIndex = this.findCurrentIndexInRanges(bounds, range);
|
|
372
128
|
|
|
129
|
+
if (currentIndex === -1) {
|
|
130
|
+
currentIndex = 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const bound = bounds[currentIndex];
|
|
134
|
+
|
|
135
|
+
if (bound) {
|
|
373
136
|
try {
|
|
374
|
-
rng.
|
|
375
|
-
rng.setEnd(bound.endContainer, bound.endOffset as number);
|
|
376
|
-
this.j.s.selectRange(rng);
|
|
377
|
-
} catch (e) {}
|
|
137
|
+
const rng = this.j.ed.createRange();
|
|
378
138
|
|
|
379
|
-
|
|
139
|
+
rng.setStart(bound.startContainer, bound.startOffset);
|
|
140
|
+
rng.setEnd(bound.endContainer, bound.endOffset);
|
|
141
|
+
rng.deleteContents();
|
|
142
|
+
|
|
143
|
+
const textNode = this.j.createInside.text(this.ui.replace);
|
|
144
|
+
|
|
145
|
+
rng.insertNode(textNode);
|
|
146
|
+
this.j.s.select(textNode);
|
|
147
|
+
this.tryScrollToElement(textNode);
|
|
148
|
+
this.cache = {};
|
|
149
|
+
this.j.synchronizeValues();
|
|
150
|
+
} catch {}
|
|
380
151
|
|
|
381
|
-
this.
|
|
382
|
-
this.updateCounters();
|
|
152
|
+
this.j.e.fire('afterFindAndReplace');
|
|
383
153
|
|
|
384
154
|
return true;
|
|
385
155
|
}
|
|
386
156
|
|
|
387
157
|
return false;
|
|
388
|
-
}
|
|
158
|
+
}
|
|
389
159
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
query: string,
|
|
393
|
-
next: boolean,
|
|
394
|
-
deep: number,
|
|
395
|
-
range: Range
|
|
396
|
-
): false | ISelectionRange => {
|
|
397
|
-
if (start && query.length) {
|
|
398
|
-
let sentence: string = '',
|
|
399
|
-
bound: ISelectionRange = {
|
|
400
|
-
startContainer: null,
|
|
401
|
-
startOffset: null,
|
|
402
|
-
endContainer: null,
|
|
403
|
-
endOffset: null
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
this.eachMap(
|
|
407
|
-
start,
|
|
408
|
-
(elm: Node): boolean => {
|
|
409
|
-
if (
|
|
410
|
-
Dom.isText(elm) &&
|
|
411
|
-
elm.nodeValue != null &&
|
|
412
|
-
elm.nodeValue.length
|
|
413
|
-
) {
|
|
414
|
-
let value: string = elm.nodeValue;
|
|
415
|
-
|
|
416
|
-
if (!next && elm === range.startContainer) {
|
|
417
|
-
value = !deep
|
|
418
|
-
? value.substr(0, range.startOffset)
|
|
419
|
-
: value.substr(range.endOffset);
|
|
420
|
-
} else if (next && elm === range.endContainer) {
|
|
421
|
-
value = !deep
|
|
422
|
-
? value.substr(range.endOffset)
|
|
423
|
-
: value.substr(0, range.startOffset);
|
|
424
|
-
}
|
|
160
|
+
private previousQuery: string = '';
|
|
161
|
+
private drawPromise: RejectablePromise<void> | null = null;
|
|
425
162
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
search.findSomePartOfString(
|
|
432
|
-
query,
|
|
433
|
-
tmpSentence,
|
|
434
|
-
next
|
|
435
|
-
) as boolean | string;
|
|
436
|
-
|
|
437
|
-
if (part !== false) {
|
|
438
|
-
let currentPart: string | boolean =
|
|
439
|
-
search.findSomePartOfString(
|
|
440
|
-
query,
|
|
441
|
-
value,
|
|
442
|
-
next
|
|
443
|
-
) as string | boolean;
|
|
444
|
-
|
|
445
|
-
if (currentPart === true) {
|
|
446
|
-
currentPart = trim(query);
|
|
447
|
-
} else if (currentPart === false) {
|
|
448
|
-
currentPart = search.findSomePartOfString(
|
|
449
|
-
value,
|
|
450
|
-
query,
|
|
451
|
-
next
|
|
452
|
-
) as string | true;
|
|
453
|
-
if (currentPart === true) {
|
|
454
|
-
currentPart = trim(value);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
let currentPartIndex: number =
|
|
459
|
-
search.getSomePartOfStringIndex(
|
|
460
|
-
query,
|
|
461
|
-
value,
|
|
462
|
-
next
|
|
463
|
-
) || 0;
|
|
464
|
-
|
|
465
|
-
if (
|
|
466
|
-
((next && !deep) || (!next && deep)) &&
|
|
467
|
-
elm.nodeValue.length - value.length > 0
|
|
468
|
-
) {
|
|
469
|
-
currentPartIndex +=
|
|
470
|
-
elm.nodeValue.length - value.length;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
if (bound.startContainer == null) {
|
|
474
|
-
bound.startContainer = elm;
|
|
475
|
-
bound.startOffset = currentPartIndex;
|
|
476
|
-
}
|
|
477
|
-
if (part !== true) {
|
|
478
|
-
sentence = tmpSentence;
|
|
479
|
-
} else {
|
|
480
|
-
bound.endContainer = elm;
|
|
481
|
-
bound.endOffset = currentPartIndex;
|
|
482
|
-
bound.endOffset += (
|
|
483
|
-
currentPart as string
|
|
484
|
-
).length;
|
|
485
|
-
|
|
486
|
-
return true;
|
|
487
|
-
}
|
|
488
|
-
} else {
|
|
489
|
-
sentence = '';
|
|
490
|
-
bound = {
|
|
491
|
-
startContainer: null,
|
|
492
|
-
startOffset: null,
|
|
493
|
-
endContainer: null,
|
|
494
|
-
endOffset: null
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
} else if (Dom.isBlock(elm) && sentence !== '') {
|
|
498
|
-
sentence = next ? sentence + ' ' : ' ' + sentence;
|
|
499
|
-
}
|
|
163
|
+
@autobind
|
|
164
|
+
async findAndSelect(query: string, next: boolean): Promise<boolean> {
|
|
165
|
+
if (this.walker) {
|
|
166
|
+
this.walker.break();
|
|
167
|
+
}
|
|
500
168
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
if (!deep) {
|
|
511
|
-
this.current = next
|
|
512
|
-
? (this.j.editor.firstChild as Node)
|
|
513
|
-
: (this.j.editor.lastChild as Node);
|
|
514
|
-
return this.find(this.current, query, next, deep + 1, range);
|
|
515
|
-
}
|
|
169
|
+
this.walker = new LazyWalker(this.j.async, {
|
|
170
|
+
timeout: this.j.defaultTimeout
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const bounds = await this.find(this.walker, query);
|
|
174
|
+
|
|
175
|
+
if (!bounds.length) {
|
|
176
|
+
return false;
|
|
516
177
|
}
|
|
517
178
|
|
|
518
|
-
|
|
519
|
-
|
|
179
|
+
if (
|
|
180
|
+
this.previousQuery !== query ||
|
|
181
|
+
!getSelectionWrappers(this.j.editor).length
|
|
182
|
+
) {
|
|
183
|
+
this.drawPromise?.rejectCallback();
|
|
184
|
+
this.j.async.cancelAnimationFrame(this.wrapFrameRequest);
|
|
185
|
+
clearSelectionWrappers(this.j.editor);
|
|
186
|
+
this.drawPromise = this.drawSelectionRanges(bounds);
|
|
187
|
+
}
|
|
520
188
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
189
|
+
this.previousQuery = query;
|
|
190
|
+
|
|
191
|
+
let currentIndex = this.ui.currentIndex - 1;
|
|
192
|
+
|
|
193
|
+
if (currentIndex === -1) {
|
|
194
|
+
currentIndex = 0;
|
|
195
|
+
} else if (next) {
|
|
196
|
+
currentIndex =
|
|
197
|
+
currentIndex === bounds.length - 1 ? 0 : currentIndex + 1;
|
|
198
|
+
} else {
|
|
199
|
+
currentIndex =
|
|
200
|
+
currentIndex === 0 ? bounds.length - 1 : currentIndex - 1;
|
|
525
201
|
}
|
|
526
202
|
|
|
527
|
-
this.
|
|
203
|
+
this.ui.currentIndex = currentIndex + 1;
|
|
528
204
|
|
|
529
|
-
|
|
205
|
+
const bound = bounds[currentIndex];
|
|
530
206
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
searchAndReplace
|
|
534
|
-
);
|
|
207
|
+
if (bound) {
|
|
208
|
+
const rng = this.j.ed.createRange();
|
|
535
209
|
|
|
536
|
-
|
|
210
|
+
try {
|
|
211
|
+
rng.setStart(bound.startContainer, bound.startOffset);
|
|
212
|
+
rng.setEnd(bound.endContainer, bound.endOffset);
|
|
213
|
+
this.j.s.selectRange(rng);
|
|
214
|
+
} catch (e) {}
|
|
537
215
|
|
|
538
|
-
|
|
216
|
+
this.tryScrollToElement(bound.startContainer);
|
|
539
217
|
|
|
540
|
-
|
|
541
|
-
this.
|
|
218
|
+
await this.updateCounters();
|
|
219
|
+
await this.drawPromise;
|
|
220
|
+
this.j.e.fire('afterFindAndSelect');
|
|
221
|
+
|
|
222
|
+
return true;
|
|
542
223
|
}
|
|
543
224
|
|
|
544
|
-
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
545
227
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
228
|
+
private findCurrentIndexInRanges(
|
|
229
|
+
bounds: ISelectionRange[],
|
|
230
|
+
range: Range
|
|
231
|
+
): number {
|
|
232
|
+
return bounds.findIndex(
|
|
233
|
+
bound =>
|
|
234
|
+
bound.startContainer === range.startContainer &&
|
|
235
|
+
bound.startOffset === range.startOffset &&
|
|
236
|
+
bound.endContainer === range.startContainer &&
|
|
237
|
+
bound.endOffset === range.endOffset
|
|
238
|
+
);
|
|
239
|
+
}
|
|
552
240
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
241
|
+
walker: Nullable<LazyWalker> = null;
|
|
242
|
+
walkerCount: Nullable<LazyWalker> = null;
|
|
243
|
+
|
|
244
|
+
private cache: IDictionary<CanUndef<Promise<ISelectionRange[]>>> = {};
|
|
245
|
+
|
|
246
|
+
private async isValidCache(
|
|
247
|
+
promise: Promise<ISelectionRange[]>
|
|
248
|
+
): Promise<boolean> {
|
|
249
|
+
const res = await promise;
|
|
250
|
+
return res.every(
|
|
251
|
+
r =>
|
|
252
|
+
r.startContainer.isConnected &&
|
|
253
|
+
r.startOffset <= (r.startContainer.nodeValue?.length ?? 0) &&
|
|
254
|
+
r.endContainer.isConnected &&
|
|
255
|
+
r.endOffset <= (r.endContainer.nodeValue?.length ?? 0)
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@autobind
|
|
260
|
+
private async find(
|
|
261
|
+
walker: LazyWalker,
|
|
262
|
+
query: string
|
|
263
|
+
): Promise<ISelectionRange[]> {
|
|
264
|
+
if (!query.length) {
|
|
265
|
+
return [];
|
|
556
266
|
}
|
|
557
267
|
|
|
558
|
-
this.
|
|
268
|
+
const cache = this.cache[query];
|
|
269
|
+
if (cache && (await this.isValidCache(cache))) {
|
|
270
|
+
return cache;
|
|
271
|
+
}
|
|
559
272
|
|
|
560
|
-
this.
|
|
561
|
-
this.isOpened = false;
|
|
562
|
-
};
|
|
273
|
+
const sentence = new SentenceFinder(this.j.o.search.fuzzySearch);
|
|
563
274
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
275
|
+
this.cache[query] = this.j.async.promise(resolve => {
|
|
276
|
+
walker
|
|
277
|
+
.on('break', (): void => {
|
|
278
|
+
resolve([]);
|
|
279
|
+
})
|
|
280
|
+
.on('visit', (elm: Node): boolean => {
|
|
281
|
+
if (Dom.isText(elm)) {
|
|
282
|
+
sentence.add(elm);
|
|
283
|
+
}
|
|
568
284
|
|
|
569
|
-
|
|
285
|
+
return false;
|
|
286
|
+
})
|
|
287
|
+
.on('end', (): void => {
|
|
288
|
+
resolve(sentence.ranges(query) ?? []);
|
|
289
|
+
})
|
|
290
|
+
.setWork(this.j.editor);
|
|
291
|
+
});
|
|
570
292
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
replace,
|
|
574
|
-
cancel,
|
|
575
|
-
next,
|
|
576
|
-
prev,
|
|
577
|
-
replaceBtn,
|
|
578
|
-
counterBox
|
|
579
|
-
} = refs(self.searchBox);
|
|
293
|
+
return this.cache[query] as Promise<ISelectionRange[]>;
|
|
294
|
+
}
|
|
580
295
|
|
|
581
|
-
|
|
296
|
+
private wrapFrameRequest: number = 0;
|
|
582
297
|
|
|
583
|
-
|
|
298
|
+
private drawSelectionRanges(
|
|
299
|
+
ranges: ISelectionRange[]
|
|
300
|
+
): RejectablePromise<void> {
|
|
301
|
+
const { async, createInside: ci, editor } = this.j;
|
|
584
302
|
|
|
585
|
-
|
|
303
|
+
async.cancelAnimationFrame(this.wrapFrameRequest);
|
|
586
304
|
|
|
587
|
-
|
|
305
|
+
const parts = [...ranges];
|
|
588
306
|
|
|
589
|
-
|
|
307
|
+
let sRange: CanUndef<ISelectionRange>,
|
|
308
|
+
total = 0;
|
|
590
309
|
|
|
591
|
-
|
|
310
|
+
return async.promise(resolve => {
|
|
311
|
+
const drawParts = (): void => {
|
|
312
|
+
do {
|
|
313
|
+
sRange = parts.shift();
|
|
592
314
|
|
|
593
|
-
|
|
315
|
+
if (sRange) {
|
|
316
|
+
wrapRangesTextsInTmpSpan(sRange, parts, ci, editor);
|
|
317
|
+
}
|
|
594
318
|
|
|
595
|
-
|
|
596
|
-
|
|
319
|
+
total += 1;
|
|
320
|
+
} while (sRange && total <= 5);
|
|
597
321
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
322
|
+
if (parts.length) {
|
|
323
|
+
this.wrapFrameRequest =
|
|
324
|
+
async.requestAnimationFrame(drawParts);
|
|
325
|
+
} else {
|
|
326
|
+
resolve();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
607
329
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
break;
|
|
330
|
+
drawParts();
|
|
331
|
+
});
|
|
332
|
+
}
|
|
612
333
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
? 'searchNext'
|
|
618
|
-
: 'searchPrevious'
|
|
619
|
-
);
|
|
334
|
+
@watch(':afterGetValueFromEditor')
|
|
335
|
+
protected onAfterGetValueFromEditor(data: { value: string }): void {
|
|
336
|
+
data.value = clearSelectionWrappersFromHTML(data.value);
|
|
337
|
+
}
|
|
620
338
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
626
|
-
);
|
|
627
|
-
};
|
|
628
|
-
onInit();
|
|
339
|
+
/** @override */
|
|
340
|
+
afterInit(editor: IJodit): void {
|
|
341
|
+
if (editor.o.useSearch) {
|
|
342
|
+
const self: search = this;
|
|
629
343
|
|
|
630
344
|
editor.e
|
|
631
|
-
.on('
|
|
632
|
-
|
|
633
|
-
.on(self.queryInput, 'mousedown', () => {
|
|
634
|
-
if (editor.s.isFocused()) {
|
|
635
|
-
editor.s.removeMarkers();
|
|
636
|
-
self.selInfo = editor.s.save();
|
|
637
|
-
}
|
|
345
|
+
.on('beforeSetMode.search', () => {
|
|
346
|
+
this.ui.close();
|
|
638
347
|
})
|
|
639
|
-
.on(
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
348
|
+
.on(this.ui, 'afterClose', () => {
|
|
349
|
+
clearSelectionWrappers(editor.editor);
|
|
350
|
+
this.ui.currentIndex = 0;
|
|
351
|
+
this.ui.count = 0;
|
|
352
|
+
this.cache = {};
|
|
353
|
+
})
|
|
354
|
+
.on('click', () => {
|
|
355
|
+
this.ui.currentIndex = 0;
|
|
356
|
+
clearSelectionWrappers(editor.editor);
|
|
357
|
+
})
|
|
358
|
+
.on('change.search', () => {
|
|
359
|
+
this.cache = {};
|
|
649
360
|
})
|
|
650
361
|
.on(
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
? 'searchNext'
|
|
657
|
-
: 'searchPrevious'
|
|
658
|
-
);
|
|
659
|
-
e.preventDefault();
|
|
660
|
-
e.stopImmediatePropagation();
|
|
661
|
-
}
|
|
662
|
-
)
|
|
663
|
-
.on(
|
|
664
|
-
this.queryInput,
|
|
665
|
-
'keydown',
|
|
666
|
-
this.j.async.debounce((e: KeyboardEvent) => {
|
|
667
|
-
switch (e.key) {
|
|
668
|
-
case consts.KEY_ENTER:
|
|
669
|
-
e.preventDefault();
|
|
670
|
-
e.stopImmediatePropagation();
|
|
671
|
-
if (editor.e.fire('searchNext')) {
|
|
672
|
-
this.close();
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
break;
|
|
676
|
-
|
|
677
|
-
default:
|
|
678
|
-
this.updateCounters();
|
|
679
|
-
break;
|
|
362
|
+
'keydown.search mousedown.search',
|
|
363
|
+
editor.async.debounce(() => {
|
|
364
|
+
if (this.ui.selInfo) {
|
|
365
|
+
editor.s.removeMarkers();
|
|
366
|
+
this.ui.selInfo = null;
|
|
680
367
|
}
|
|
681
|
-
|
|
368
|
+
|
|
369
|
+
if (this.ui.isOpened) {
|
|
370
|
+
this.updateCounters();
|
|
371
|
+
}
|
|
372
|
+
}, editor.defaultTimeout)
|
|
682
373
|
)
|
|
683
|
-
.on('beforeSetMode.search', () => {
|
|
684
|
-
this.close();
|
|
685
|
-
})
|
|
686
|
-
.on('keydown.search mousedown.search', () => {
|
|
687
|
-
if (this.selInfo) {
|
|
688
|
-
editor.s.removeMarkers();
|
|
689
|
-
this.selInfo = null;
|
|
690
|
-
}
|
|
691
|
-
if (this.isOpened) {
|
|
692
|
-
this.current = this.j.s.current();
|
|
693
|
-
this.updateCounters();
|
|
694
|
-
}
|
|
695
|
-
})
|
|
696
374
|
.on('searchNext.search searchPrevious.search', () => {
|
|
697
|
-
if (!
|
|
698
|
-
|
|
375
|
+
if (!this.ui.isOpened) {
|
|
376
|
+
this.ui.open();
|
|
699
377
|
}
|
|
700
378
|
|
|
701
|
-
return self
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
379
|
+
return self
|
|
380
|
+
.findAndSelect(
|
|
381
|
+
self.ui.query,
|
|
382
|
+
editor.e.current === 'searchNext'
|
|
383
|
+
)
|
|
384
|
+
.catch(() => {});
|
|
706
385
|
})
|
|
707
386
|
.on('search.search', (value: string, next: boolean = true) => {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
387
|
+
this.ui.currentIndex = 0;
|
|
388
|
+
return self
|
|
389
|
+
.findAndSelect(value || '', next)
|
|
390
|
+
.catch(() => {});
|
|
391
|
+
});
|
|
711
392
|
|
|
712
393
|
editor
|
|
713
394
|
.registerCommand('search', {
|
|
@@ -716,18 +397,15 @@ export class search extends Plugin {
|
|
|
716
397
|
value?: string,
|
|
717
398
|
next: boolean = true
|
|
718
399
|
) => {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
value || '',
|
|
722
|
-
next
|
|
723
|
-
);
|
|
400
|
+
value &&
|
|
401
|
+
self.findAndSelect(value, next).catch(() => {});
|
|
724
402
|
|
|
725
403
|
return false;
|
|
726
404
|
}
|
|
727
405
|
})
|
|
728
406
|
.registerCommand('openSearchDialog', {
|
|
729
407
|
exec: () => {
|
|
730
|
-
self.open();
|
|
408
|
+
self.ui.open();
|
|
731
409
|
return false;
|
|
732
410
|
},
|
|
733
411
|
hotkeys: ['ctrl+f', 'cmd+f']
|
|
@@ -735,7 +413,7 @@ export class search extends Plugin {
|
|
|
735
413
|
.registerCommand('openReplaceDialog', {
|
|
736
414
|
exec: () => {
|
|
737
415
|
if (!editor.o.readonly) {
|
|
738
|
-
self.open(true);
|
|
416
|
+
self.ui.open(true);
|
|
739
417
|
}
|
|
740
418
|
return false;
|
|
741
419
|
},
|
|
@@ -746,31 +424,7 @@ export class search extends Plugin {
|
|
|
746
424
|
|
|
747
425
|
/** @override */
|
|
748
426
|
beforeDestruct(jodit: IJodit): void {
|
|
749
|
-
|
|
750
|
-
jodit.
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
/**
|
|
754
|
-
* Calculate position if sticky is enabled
|
|
755
|
-
*/
|
|
756
|
-
@autobind
|
|
757
|
-
private calcSticky(enabled: boolean): void {
|
|
758
|
-
if (this.isOpened) {
|
|
759
|
-
this.searchBox.classList.toggle('jodit-search_sticky', enabled);
|
|
760
|
-
|
|
761
|
-
if (enabled) {
|
|
762
|
-
const pos = position(this.j.toolbarContainer);
|
|
763
|
-
|
|
764
|
-
css(this.searchBox, {
|
|
765
|
-
top: pos.top + pos.height,
|
|
766
|
-
left: pos.left + pos.width
|
|
767
|
-
});
|
|
768
|
-
} else {
|
|
769
|
-
css(this.searchBox, {
|
|
770
|
-
top: null,
|
|
771
|
-
left: null
|
|
772
|
-
});
|
|
773
|
-
}
|
|
774
|
-
}
|
|
427
|
+
this.ui.destruct();
|
|
428
|
+
jodit.e.off('.search');
|
|
775
429
|
}
|
|
776
430
|
}
|