@ckeditor/ckeditor5-find-and-replace 39.0.2 → 40.0.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/build/find-and-replace.js.map +1 -0
- package/build/translations/pt-br.js +1 -1
- package/lang/translations/pt-br.po +6 -6
- package/package.json +3 -3
- package/src/augmentation.d.ts +20 -20
- package/src/augmentation.js +5 -5
- package/src/findandreplace.d.ts +42 -42
- package/src/findandreplace.js +84 -84
- package/src/findandreplaceediting.d.ts +63 -63
- package/src/findandreplaceediting.js +201 -201
- package/src/findandreplacestate.d.ts +69 -69
- package/src/findandreplacestate.js +60 -60
- package/src/findandreplaceui.d.ts +55 -55
- package/src/findandreplaceui.js +132 -132
- package/src/findandreplaceutils.d.ts +67 -67
- package/src/findandreplaceutils.js +143 -143
- package/src/findcommand.d.ts +51 -51
- package/src/findcommand.js +63 -63
- package/src/findnextcommand.d.ts +35 -35
- package/src/findnextcommand.js +47 -47
- package/src/findpreviouscommand.d.ts +19 -19
- package/src/findpreviouscommand.js +25 -25
- package/src/index.d.ts +17 -17
- package/src/index.js +17 -17
- package/src/replaceallcommand.d.ts +35 -35
- package/src/replaceallcommand.js +50 -50
- package/src/replacecommand.d.ts +22 -22
- package/src/replacecommand.js +20 -20
- package/src/replacecommandbase.d.ts +31 -31
- package/src/replacecommandbase.js +56 -56
- package/src/ui/findandreplaceformview.d.ts +288 -288
- package/src/ui/findandreplaceformview.js +453 -453
|
@@ -1,453 +1,453 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module find-and-replace/ui/findandreplaceformview
|
|
7
|
-
*/
|
|
8
|
-
import { View, ButtonView, FormHeaderView, LabeledFieldView, Model, FocusCycler, createLabeledInputText, submitHandler, ViewCollection, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
|
|
9
|
-
import { FocusTracker, KeystrokeHandler, Collection, Rect, isVisible } from 'ckeditor5/src/utils';
|
|
10
|
-
// See: #8833.
|
|
11
|
-
// eslint-disable-next-line ckeditor5-rules/ckeditor-imports
|
|
12
|
-
import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
|
|
13
|
-
import '../../theme/findandreplaceform.css';
|
|
14
|
-
// eslint-disable-next-line ckeditor5-rules/ckeditor-imports
|
|
15
|
-
import previousArrow from '@ckeditor/ckeditor5-ui/theme/icons/previous-arrow.svg';
|
|
16
|
-
import { icons } from 'ckeditor5/src/core';
|
|
17
|
-
/**
|
|
18
|
-
* The find and replace form view class.
|
|
19
|
-
*
|
|
20
|
-
* See {@link module:find-and-replace/ui/findandreplaceformview~FindAndReplaceFormView}.
|
|
21
|
-
*/
|
|
22
|
-
export default class FindAndReplaceFormView extends View {
|
|
23
|
-
/**
|
|
24
|
-
* Creates a view of find and replace form.
|
|
25
|
-
*
|
|
26
|
-
* @param locale The localization services instance.
|
|
27
|
-
*/
|
|
28
|
-
constructor(locale) {
|
|
29
|
-
super(locale);
|
|
30
|
-
const t = locale.t;
|
|
31
|
-
this.set('matchCount', 0);
|
|
32
|
-
this.set('highlightOffset', 0);
|
|
33
|
-
this.set('isDirty', false);
|
|
34
|
-
this.set('_areCommandsEnabled', {});
|
|
35
|
-
this.set('_resultsCounterText', '');
|
|
36
|
-
this.set('_matchCase', false);
|
|
37
|
-
this.set('_wholeWordsOnly', false);
|
|
38
|
-
this.bind('_searchResultsFound').to(this, 'matchCount', this, 'isDirty', (matchCount, isDirty) => {
|
|
39
|
-
return matchCount > 0 && !isDirty;
|
|
40
|
-
});
|
|
41
|
-
this._findInputView = this._createInputField(t('Find in text…'));
|
|
42
|
-
this._replaceInputView = this._createInputField(t('Replace with…'));
|
|
43
|
-
this._findButtonView = this._createButton({
|
|
44
|
-
label: t('Find'),
|
|
45
|
-
class: 'ck-button-find ck-button-action',
|
|
46
|
-
withText: true
|
|
47
|
-
});
|
|
48
|
-
this._findPrevButtonView = this._createButton({
|
|
49
|
-
label: t('Previous result'),
|
|
50
|
-
class: 'ck-button-prev',
|
|
51
|
-
icon: previousArrow,
|
|
52
|
-
keystroke: 'Shift+F3',
|
|
53
|
-
tooltip: true
|
|
54
|
-
});
|
|
55
|
-
this._findNextButtonView = this._createButton({
|
|
56
|
-
label: t('Next result'),
|
|
57
|
-
class: 'ck-button-next',
|
|
58
|
-
icon: previousArrow,
|
|
59
|
-
keystroke: 'F3',
|
|
60
|
-
tooltip: true
|
|
61
|
-
});
|
|
62
|
-
this._optionsDropdown = this._createOptionsDropdown();
|
|
63
|
-
this._replaceButtonView = this._createButton({
|
|
64
|
-
label: t('Replace'),
|
|
65
|
-
class: 'ck-button-replace',
|
|
66
|
-
withText: true
|
|
67
|
-
});
|
|
68
|
-
this._replaceAllButtonView = this._createButton({
|
|
69
|
-
label: t('Replace all'),
|
|
70
|
-
class: 'ck-button-replaceall',
|
|
71
|
-
withText: true
|
|
72
|
-
});
|
|
73
|
-
this._findFieldsetView = this._createFindFieldset();
|
|
74
|
-
this._replaceFieldsetView = this._createReplaceFieldset();
|
|
75
|
-
this._focusTracker = new FocusTracker();
|
|
76
|
-
this._keystrokes = new KeystrokeHandler();
|
|
77
|
-
this._focusables = new ViewCollection();
|
|
78
|
-
this._focusCycler = new FocusCycler({
|
|
79
|
-
focusables: this._focusables,
|
|
80
|
-
focusTracker: this._focusTracker,
|
|
81
|
-
keystrokeHandler: this._keystrokes,
|
|
82
|
-
actions: {
|
|
83
|
-
// Navigate form fields backwards using the <kbd>Shift</kbd> + <kbd>Tab</kbd> keystroke.
|
|
84
|
-
focusPrevious: 'shift + tab',
|
|
85
|
-
// Navigate form fields forwards using the <kbd>Tab</kbd> key.
|
|
86
|
-
focusNext: 'tab'
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
this.setTemplate({
|
|
90
|
-
tag: 'form',
|
|
91
|
-
attributes: {
|
|
92
|
-
class: [
|
|
93
|
-
'ck',
|
|
94
|
-
'ck-find-and-replace-form'
|
|
95
|
-
],
|
|
96
|
-
tabindex: '-1'
|
|
97
|
-
},
|
|
98
|
-
children: [
|
|
99
|
-
new FormHeaderView(locale, {
|
|
100
|
-
label: t('Find and replace')
|
|
101
|
-
}),
|
|
102
|
-
this._findFieldsetView,
|
|
103
|
-
this._replaceFieldsetView
|
|
104
|
-
]
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* @inheritDoc
|
|
109
|
-
*/
|
|
110
|
-
render() {
|
|
111
|
-
super.render();
|
|
112
|
-
submitHandler({ view: this });
|
|
113
|
-
this._initFocusCycling();
|
|
114
|
-
this._initKeystrokeHandling();
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @inheritDoc
|
|
118
|
-
*/
|
|
119
|
-
destroy() {
|
|
120
|
-
super.destroy();
|
|
121
|
-
this._focusTracker.destroy();
|
|
122
|
-
this._keystrokes.destroy();
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Focuses the fist {@link #_focusables} in the form.
|
|
126
|
-
*/
|
|
127
|
-
focus() {
|
|
128
|
-
this._focusCycler.focusFirst();
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Resets the form before re-appearing.
|
|
132
|
-
*
|
|
133
|
-
* It clears error messages, hides the match counter and disables the replace feature
|
|
134
|
-
* until the next hit of the "Find" button.
|
|
135
|
-
*
|
|
136
|
-
* **Note**: It does not reset inputs and options, though. This way the form works better in editors with
|
|
137
|
-
* disappearing toolbar (e.g. BalloonEditor): hiding the toolbar by accident (together with the find and replace UI)
|
|
138
|
-
* does not require filling the entire form again.
|
|
139
|
-
*/
|
|
140
|
-
reset() {
|
|
141
|
-
this._findInputView.errorText = null;
|
|
142
|
-
this.isDirty = true;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Returns the value of the find input.
|
|
146
|
-
*/
|
|
147
|
-
get _textToFind() {
|
|
148
|
-
return this._findInputView.fieldView.element.value;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Returns the value of the replace input.
|
|
152
|
-
*/
|
|
153
|
-
get _textToReplace() {
|
|
154
|
-
return this._replaceInputView.fieldView.element.value;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Configures and returns the `<fieldset>` aggregating all find controls.
|
|
158
|
-
*/
|
|
159
|
-
_createFindFieldset() {
|
|
160
|
-
const locale = this.locale;
|
|
161
|
-
const fieldsetView = new View(locale);
|
|
162
|
-
// Typing in the find field invalidates all previous results (the form is "dirty").
|
|
163
|
-
this._findInputView.fieldView.on('input', () => {
|
|
164
|
-
this.isDirty = true;
|
|
165
|
-
});
|
|
166
|
-
this._findButtonView.on('execute', this._onFindButtonExecute.bind(this));
|
|
167
|
-
// Pressing prev/next buttons fires related event on the form.
|
|
168
|
-
this._findPrevButtonView.delegate('execute').to(this, 'findPrevious');
|
|
169
|
-
this._findNextButtonView.delegate('execute').to(this, 'findNext');
|
|
170
|
-
// Prev/next buttons will be disabled when related editor command gets disabled.
|
|
171
|
-
this._findPrevButtonView.bind('isEnabled').to(this, '_areCommandsEnabled', ({ findPrevious }) => findPrevious);
|
|
172
|
-
this._findNextButtonView.bind('isEnabled').to(this, '_areCommandsEnabled', ({ findNext }) => findNext);
|
|
173
|
-
this._injectFindResultsCounter();
|
|
174
|
-
fieldsetView.setTemplate({
|
|
175
|
-
tag: 'fieldset',
|
|
176
|
-
attributes: {
|
|
177
|
-
class: ['ck', 'ck-find-and-replace-form__find']
|
|
178
|
-
},
|
|
179
|
-
children: [
|
|
180
|
-
this._findInputView,
|
|
181
|
-
this._findButtonView,
|
|
182
|
-
this._findPrevButtonView,
|
|
183
|
-
this._findNextButtonView
|
|
184
|
-
]
|
|
185
|
-
});
|
|
186
|
-
return fieldsetView;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* The action performed when the {@link #_findButtonView} is pressed.
|
|
190
|
-
*/
|
|
191
|
-
_onFindButtonExecute() {
|
|
192
|
-
// When hitting "Find" in an empty input, an error should be displayed.
|
|
193
|
-
// Also, if the form was "dirty", it should remain so.
|
|
194
|
-
if (!this._textToFind) {
|
|
195
|
-
const t = this.t;
|
|
196
|
-
this._findInputView.errorText = t('Text to find must not be empty.');
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
// Hitting "Find" automatically clears the dirty state.
|
|
200
|
-
this.isDirty = false;
|
|
201
|
-
this.fire('findNext', {
|
|
202
|
-
searchText: this._textToFind,
|
|
203
|
-
matchCase: this._matchCase,
|
|
204
|
-
wholeWords: this._wholeWordsOnly
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Configures an injects the find results counter displaying a "N of M" label of the {@link #_findInputView}.
|
|
209
|
-
*/
|
|
210
|
-
_injectFindResultsCounter() {
|
|
211
|
-
const locale = this.locale;
|
|
212
|
-
const t = locale.t;
|
|
213
|
-
const bind = this.bindTemplate;
|
|
214
|
-
const resultsCounterView = new View(this.locale);
|
|
215
|
-
this.bind('_resultsCounterText').to(this, 'highlightOffset', this, 'matchCount', (highlightOffset, matchCount) => t('%0 of %1', [highlightOffset, matchCount]));
|
|
216
|
-
resultsCounterView.setTemplate({
|
|
217
|
-
tag: 'span',
|
|
218
|
-
attributes: {
|
|
219
|
-
class: [
|
|
220
|
-
'ck',
|
|
221
|
-
'ck-results-counter',
|
|
222
|
-
// The counter only makes sense when the field text corresponds to search results in the editing.
|
|
223
|
-
bind.if('isDirty', 'ck-hidden')
|
|
224
|
-
]
|
|
225
|
-
},
|
|
226
|
-
children: [
|
|
227
|
-
{
|
|
228
|
-
text: bind.to('_resultsCounterText')
|
|
229
|
-
}
|
|
230
|
-
]
|
|
231
|
-
});
|
|
232
|
-
// The whole idea is that when the text of the counter changes, its width also increases/decreases and
|
|
233
|
-
// it consumes more or less space over the input. The input, on the other hand, should adjust it's right
|
|
234
|
-
// padding so its *entire* text always remains visible and available to the user.
|
|
235
|
-
const updateFindInputPadding = () => {
|
|
236
|
-
const inputElement = this._findInputView.fieldView.element;
|
|
237
|
-
// Don't adjust the padding if the input (also: counter) were not rendered or not inserted into DOM yet.
|
|
238
|
-
if (!inputElement || !isVisible(inputElement)) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
const counterWidth = new Rect(resultsCounterView.element).width;
|
|
242
|
-
const paddingPropertyName = locale.uiLanguageDirection === 'ltr' ? 'paddingRight' : 'paddingLeft';
|
|
243
|
-
if (!counterWidth) {
|
|
244
|
-
inputElement.style[paddingPropertyName] = '';
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
inputElement.style[paddingPropertyName] = `calc( 2 * var(--ck-spacing-standard) + ${counterWidth}px )`;
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
// Adjust the input padding when the text of the counter changes, for instance "1 of 200" is narrower than "123 of 200".
|
|
251
|
-
// Using "low" priority to let the text be set by the template binding first.
|
|
252
|
-
this.on('change:_resultsCounterText', updateFindInputPadding, { priority: 'low' });
|
|
253
|
-
// Adjust the input padding when the counter shows or hides. When hidden, there should be no padding. When it shows, the
|
|
254
|
-
// padding should be set according to the text of the counter.
|
|
255
|
-
// Using "low" priority to let the text be set by the template binding first.
|
|
256
|
-
this.on('change:isDirty', updateFindInputPadding, { priority: 'low' });
|
|
257
|
-
// Put the counter element next to the <input> in the find field.
|
|
258
|
-
this._findInputView.template.children[0].children.push(resultsCounterView);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Configures and returns the `<fieldset>` aggregating all replace controls.
|
|
262
|
-
*/
|
|
263
|
-
_createReplaceFieldset() {
|
|
264
|
-
const locale = this.locale;
|
|
265
|
-
const t = locale.t;
|
|
266
|
-
const fieldsetView = new View(this.locale);
|
|
267
|
-
this._replaceButtonView.bind('isEnabled').to(this, '_areCommandsEnabled', this, '_searchResultsFound', ({ replace }, resultsFound) => replace && resultsFound);
|
|
268
|
-
this._replaceAllButtonView.bind('isEnabled').to(this, '_areCommandsEnabled', this, '_searchResultsFound', ({ replaceAll }, resultsFound) => replaceAll && resultsFound);
|
|
269
|
-
this._replaceInputView.bind('isEnabled').to(this, '_areCommandsEnabled', this, '_searchResultsFound', ({ replace }, resultsFound) => replace && resultsFound);
|
|
270
|
-
this._replaceInputView.bind('infoText').to(this._replaceInputView, 'isEnabled', this._replaceInputView, 'isFocused', (isEnabled, isFocused) => {
|
|
271
|
-
if (isEnabled || !isFocused) {
|
|
272
|
-
return '';
|
|
273
|
-
}
|
|
274
|
-
return t('Tip: Find some text first in order to replace it.');
|
|
275
|
-
});
|
|
276
|
-
this._replaceButtonView.on('execute', () => {
|
|
277
|
-
this.fire('replace', {
|
|
278
|
-
searchText: this._textToFind,
|
|
279
|
-
replaceText: this._textToReplace
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
this._replaceAllButtonView.on('execute', () => {
|
|
283
|
-
this.fire('replaceAll', {
|
|
284
|
-
searchText: this._textToFind,
|
|
285
|
-
replaceText: this._textToReplace
|
|
286
|
-
});
|
|
287
|
-
this.focus();
|
|
288
|
-
});
|
|
289
|
-
fieldsetView.setTemplate({
|
|
290
|
-
tag: 'fieldset',
|
|
291
|
-
attributes: {
|
|
292
|
-
class: ['ck', 'ck-find-and-replace-form__replace']
|
|
293
|
-
},
|
|
294
|
-
children: [
|
|
295
|
-
this._replaceInputView,
|
|
296
|
-
this._optionsDropdown,
|
|
297
|
-
this._replaceButtonView,
|
|
298
|
-
this._replaceAllButtonView
|
|
299
|
-
]
|
|
300
|
-
});
|
|
301
|
-
return fieldsetView;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Creates, configures and returns and instance of a dropdown allowing users to narrow
|
|
305
|
-
* the search criteria down. The dropdown has a list with switch buttons for each option.
|
|
306
|
-
*/
|
|
307
|
-
_createOptionsDropdown() {
|
|
308
|
-
const locale = this.locale;
|
|
309
|
-
const t = locale.t;
|
|
310
|
-
const dropdownView = createDropdown(this.locale);
|
|
311
|
-
dropdownView.class = 'ck-options-dropdown';
|
|
312
|
-
dropdownView.buttonView.set({
|
|
313
|
-
withText: false,
|
|
314
|
-
label: t('Show options'),
|
|
315
|
-
icon: icons.cog,
|
|
316
|
-
tooltip: true
|
|
317
|
-
});
|
|
318
|
-
const matchCaseModel = new Model({
|
|
319
|
-
withText: true,
|
|
320
|
-
label: t('Match case'),
|
|
321
|
-
// A dummy read-only prop to make it easy to tell which switch was toggled.
|
|
322
|
-
_isMatchCaseSwitch: true
|
|
323
|
-
});
|
|
324
|
-
const wholeWordsOnlyModel = new Model({
|
|
325
|
-
withText: true,
|
|
326
|
-
label: t('Whole words only')
|
|
327
|
-
});
|
|
328
|
-
// Let the switches be controlled by form's observable properties.
|
|
329
|
-
matchCaseModel.bind('isOn').to(this, '_matchCase');
|
|
330
|
-
wholeWordsOnlyModel.bind('isOn').to(this, '_wholeWordsOnly');
|
|
331
|
-
// Update the state of the form when a switch is toggled.
|
|
332
|
-
dropdownView.on('execute', evt => {
|
|
333
|
-
if (evt.source._isMatchCaseSwitch) {
|
|
334
|
-
this._matchCase = !this._matchCase;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
this._wholeWordsOnly = !this._wholeWordsOnly;
|
|
338
|
-
}
|
|
339
|
-
// Toggling a switch makes the form dirty because this changes search criteria
|
|
340
|
-
// just like typing text of the find input.
|
|
341
|
-
this.isDirty = true;
|
|
342
|
-
});
|
|
343
|
-
addListToDropdown(dropdownView, new Collection([
|
|
344
|
-
{ type: 'switchbutton', model: matchCaseModel },
|
|
345
|
-
{ type: 'switchbutton', model: wholeWordsOnlyModel }
|
|
346
|
-
]));
|
|
347
|
-
return dropdownView;
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Initializes the {@link #_focusables} and {@link #_focusTracker} to allow navigation
|
|
351
|
-
* using <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keystrokes in the right order.
|
|
352
|
-
*/
|
|
353
|
-
_initFocusCycling() {
|
|
354
|
-
const childViews = [
|
|
355
|
-
this._findInputView,
|
|
356
|
-
this._findButtonView,
|
|
357
|
-
this._findPrevButtonView,
|
|
358
|
-
this._findNextButtonView,
|
|
359
|
-
this._replaceInputView,
|
|
360
|
-
this._optionsDropdown,
|
|
361
|
-
this._replaceButtonView,
|
|
362
|
-
this._replaceAllButtonView
|
|
363
|
-
];
|
|
364
|
-
childViews.forEach(v => {
|
|
365
|
-
// Register the view as focusable.
|
|
366
|
-
this._focusables.add(v);
|
|
367
|
-
// Register the view in the focus tracker.
|
|
368
|
-
this._focusTracker.add(v.element);
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Initializes the keystroke handling in the form.
|
|
373
|
-
*/
|
|
374
|
-
_initKeystrokeHandling() {
|
|
375
|
-
const stopPropagation = (data) => data.stopPropagation();
|
|
376
|
-
const stopPropagationAndPreventDefault = (data) => {
|
|
377
|
-
data.stopPropagation();
|
|
378
|
-
data.preventDefault();
|
|
379
|
-
};
|
|
380
|
-
// Start listening for the keystrokes coming from #element.
|
|
381
|
-
this._keystrokes.listenTo(this.element);
|
|
382
|
-
// Find the next result upon F3.
|
|
383
|
-
this._keystrokes.set('f3', event => {
|
|
384
|
-
stopPropagationAndPreventDefault(event);
|
|
385
|
-
this._findNextButtonView.fire('execute');
|
|
386
|
-
});
|
|
387
|
-
// Find the previous result upon F3.
|
|
388
|
-
this._keystrokes.set('shift+f3', event => {
|
|
389
|
-
stopPropagationAndPreventDefault(event);
|
|
390
|
-
this._findPrevButtonView.fire('execute');
|
|
391
|
-
});
|
|
392
|
-
// Find or replace upon pressing Enter in the find and replace fields.
|
|
393
|
-
this._keystrokes.set('enter', event => {
|
|
394
|
-
const target = event.target;
|
|
395
|
-
if (target === this._findInputView.fieldView.element) {
|
|
396
|
-
if (this._areCommandsEnabled.findNext) {
|
|
397
|
-
this._findNextButtonView.fire('execute');
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
this._findButtonView.fire('execute');
|
|
401
|
-
}
|
|
402
|
-
stopPropagationAndPreventDefault(event);
|
|
403
|
-
}
|
|
404
|
-
else if (target === this._replaceInputView.fieldView.element && !this.isDirty) {
|
|
405
|
-
this._replaceButtonView.fire('execute');
|
|
406
|
-
stopPropagationAndPreventDefault(event);
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
// Find previous upon pressing Shift+Enter in the find field.
|
|
410
|
-
this._keystrokes.set('shift+enter', event => {
|
|
411
|
-
const target = event.target;
|
|
412
|
-
if (target !== this._findInputView.fieldView.element) {
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
if (this._areCommandsEnabled.findPrevious) {
|
|
416
|
-
this._findPrevButtonView.fire('execute');
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
this._findButtonView.fire('execute');
|
|
420
|
-
}
|
|
421
|
-
stopPropagationAndPreventDefault(event);
|
|
422
|
-
});
|
|
423
|
-
// Since the form is in the dropdown panel which is a child of the toolbar, the toolbar's
|
|
424
|
-
// keystroke handler would take over the key management in the URL input.
|
|
425
|
-
// We need to prevent this ASAP. Otherwise, the basic caret movement using the arrow keys will be impossible.
|
|
426
|
-
this._keystrokes.set('arrowright', stopPropagation);
|
|
427
|
-
this._keystrokes.set('arrowleft', stopPropagation);
|
|
428
|
-
this._keystrokes.set('arrowup', stopPropagation);
|
|
429
|
-
this._keystrokes.set('arrowdown', stopPropagation);
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Creates a button view.
|
|
433
|
-
*
|
|
434
|
-
* @param options The properties of the `ButtonView`.
|
|
435
|
-
* @returns The button view instance.
|
|
436
|
-
*/
|
|
437
|
-
_createButton(options) {
|
|
438
|
-
const button = new ButtonView(this.locale);
|
|
439
|
-
button.set(options);
|
|
440
|
-
return button;
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Creates a labeled input view.
|
|
444
|
-
*
|
|
445
|
-
* @param label The input label.
|
|
446
|
-
* @returns The labeled input view instance.
|
|
447
|
-
*/
|
|
448
|
-
_createInputField(label) {
|
|
449
|
-
const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
|
|
450
|
-
labeledInput.label = label;
|
|
451
|
-
return labeledInput;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module find-and-replace/ui/findandreplaceformview
|
|
7
|
+
*/
|
|
8
|
+
import { View, ButtonView, FormHeaderView, LabeledFieldView, Model, FocusCycler, createLabeledInputText, submitHandler, ViewCollection, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
|
|
9
|
+
import { FocusTracker, KeystrokeHandler, Collection, Rect, isVisible } from 'ckeditor5/src/utils';
|
|
10
|
+
// See: #8833.
|
|
11
|
+
// eslint-disable-next-line ckeditor5-rules/ckeditor-imports
|
|
12
|
+
import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
|
|
13
|
+
import '../../theme/findandreplaceform.css';
|
|
14
|
+
// eslint-disable-next-line ckeditor5-rules/ckeditor-imports
|
|
15
|
+
import previousArrow from '@ckeditor/ckeditor5-ui/theme/icons/previous-arrow.svg';
|
|
16
|
+
import { icons } from 'ckeditor5/src/core';
|
|
17
|
+
/**
|
|
18
|
+
* The find and replace form view class.
|
|
19
|
+
*
|
|
20
|
+
* See {@link module:find-and-replace/ui/findandreplaceformview~FindAndReplaceFormView}.
|
|
21
|
+
*/
|
|
22
|
+
export default class FindAndReplaceFormView extends View {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a view of find and replace form.
|
|
25
|
+
*
|
|
26
|
+
* @param locale The localization services instance.
|
|
27
|
+
*/
|
|
28
|
+
constructor(locale) {
|
|
29
|
+
super(locale);
|
|
30
|
+
const t = locale.t;
|
|
31
|
+
this.set('matchCount', 0);
|
|
32
|
+
this.set('highlightOffset', 0);
|
|
33
|
+
this.set('isDirty', false);
|
|
34
|
+
this.set('_areCommandsEnabled', {});
|
|
35
|
+
this.set('_resultsCounterText', '');
|
|
36
|
+
this.set('_matchCase', false);
|
|
37
|
+
this.set('_wholeWordsOnly', false);
|
|
38
|
+
this.bind('_searchResultsFound').to(this, 'matchCount', this, 'isDirty', (matchCount, isDirty) => {
|
|
39
|
+
return matchCount > 0 && !isDirty;
|
|
40
|
+
});
|
|
41
|
+
this._findInputView = this._createInputField(t('Find in text…'));
|
|
42
|
+
this._replaceInputView = this._createInputField(t('Replace with…'));
|
|
43
|
+
this._findButtonView = this._createButton({
|
|
44
|
+
label: t('Find'),
|
|
45
|
+
class: 'ck-button-find ck-button-action',
|
|
46
|
+
withText: true
|
|
47
|
+
});
|
|
48
|
+
this._findPrevButtonView = this._createButton({
|
|
49
|
+
label: t('Previous result'),
|
|
50
|
+
class: 'ck-button-prev',
|
|
51
|
+
icon: previousArrow,
|
|
52
|
+
keystroke: 'Shift+F3',
|
|
53
|
+
tooltip: true
|
|
54
|
+
});
|
|
55
|
+
this._findNextButtonView = this._createButton({
|
|
56
|
+
label: t('Next result'),
|
|
57
|
+
class: 'ck-button-next',
|
|
58
|
+
icon: previousArrow,
|
|
59
|
+
keystroke: 'F3',
|
|
60
|
+
tooltip: true
|
|
61
|
+
});
|
|
62
|
+
this._optionsDropdown = this._createOptionsDropdown();
|
|
63
|
+
this._replaceButtonView = this._createButton({
|
|
64
|
+
label: t('Replace'),
|
|
65
|
+
class: 'ck-button-replace',
|
|
66
|
+
withText: true
|
|
67
|
+
});
|
|
68
|
+
this._replaceAllButtonView = this._createButton({
|
|
69
|
+
label: t('Replace all'),
|
|
70
|
+
class: 'ck-button-replaceall',
|
|
71
|
+
withText: true
|
|
72
|
+
});
|
|
73
|
+
this._findFieldsetView = this._createFindFieldset();
|
|
74
|
+
this._replaceFieldsetView = this._createReplaceFieldset();
|
|
75
|
+
this._focusTracker = new FocusTracker();
|
|
76
|
+
this._keystrokes = new KeystrokeHandler();
|
|
77
|
+
this._focusables = new ViewCollection();
|
|
78
|
+
this._focusCycler = new FocusCycler({
|
|
79
|
+
focusables: this._focusables,
|
|
80
|
+
focusTracker: this._focusTracker,
|
|
81
|
+
keystrokeHandler: this._keystrokes,
|
|
82
|
+
actions: {
|
|
83
|
+
// Navigate form fields backwards using the <kbd>Shift</kbd> + <kbd>Tab</kbd> keystroke.
|
|
84
|
+
focusPrevious: 'shift + tab',
|
|
85
|
+
// Navigate form fields forwards using the <kbd>Tab</kbd> key.
|
|
86
|
+
focusNext: 'tab'
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.setTemplate({
|
|
90
|
+
tag: 'form',
|
|
91
|
+
attributes: {
|
|
92
|
+
class: [
|
|
93
|
+
'ck',
|
|
94
|
+
'ck-find-and-replace-form'
|
|
95
|
+
],
|
|
96
|
+
tabindex: '-1'
|
|
97
|
+
},
|
|
98
|
+
children: [
|
|
99
|
+
new FormHeaderView(locale, {
|
|
100
|
+
label: t('Find and replace')
|
|
101
|
+
}),
|
|
102
|
+
this._findFieldsetView,
|
|
103
|
+
this._replaceFieldsetView
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @inheritDoc
|
|
109
|
+
*/
|
|
110
|
+
render() {
|
|
111
|
+
super.render();
|
|
112
|
+
submitHandler({ view: this });
|
|
113
|
+
this._initFocusCycling();
|
|
114
|
+
this._initKeystrokeHandling();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @inheritDoc
|
|
118
|
+
*/
|
|
119
|
+
destroy() {
|
|
120
|
+
super.destroy();
|
|
121
|
+
this._focusTracker.destroy();
|
|
122
|
+
this._keystrokes.destroy();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Focuses the fist {@link #_focusables} in the form.
|
|
126
|
+
*/
|
|
127
|
+
focus() {
|
|
128
|
+
this._focusCycler.focusFirst();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Resets the form before re-appearing.
|
|
132
|
+
*
|
|
133
|
+
* It clears error messages, hides the match counter and disables the replace feature
|
|
134
|
+
* until the next hit of the "Find" button.
|
|
135
|
+
*
|
|
136
|
+
* **Note**: It does not reset inputs and options, though. This way the form works better in editors with
|
|
137
|
+
* disappearing toolbar (e.g. BalloonEditor): hiding the toolbar by accident (together with the find and replace UI)
|
|
138
|
+
* does not require filling the entire form again.
|
|
139
|
+
*/
|
|
140
|
+
reset() {
|
|
141
|
+
this._findInputView.errorText = null;
|
|
142
|
+
this.isDirty = true;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the value of the find input.
|
|
146
|
+
*/
|
|
147
|
+
get _textToFind() {
|
|
148
|
+
return this._findInputView.fieldView.element.value;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns the value of the replace input.
|
|
152
|
+
*/
|
|
153
|
+
get _textToReplace() {
|
|
154
|
+
return this._replaceInputView.fieldView.element.value;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Configures and returns the `<fieldset>` aggregating all find controls.
|
|
158
|
+
*/
|
|
159
|
+
_createFindFieldset() {
|
|
160
|
+
const locale = this.locale;
|
|
161
|
+
const fieldsetView = new View(locale);
|
|
162
|
+
// Typing in the find field invalidates all previous results (the form is "dirty").
|
|
163
|
+
this._findInputView.fieldView.on('input', () => {
|
|
164
|
+
this.isDirty = true;
|
|
165
|
+
});
|
|
166
|
+
this._findButtonView.on('execute', this._onFindButtonExecute.bind(this));
|
|
167
|
+
// Pressing prev/next buttons fires related event on the form.
|
|
168
|
+
this._findPrevButtonView.delegate('execute').to(this, 'findPrevious');
|
|
169
|
+
this._findNextButtonView.delegate('execute').to(this, 'findNext');
|
|
170
|
+
// Prev/next buttons will be disabled when related editor command gets disabled.
|
|
171
|
+
this._findPrevButtonView.bind('isEnabled').to(this, '_areCommandsEnabled', ({ findPrevious }) => findPrevious);
|
|
172
|
+
this._findNextButtonView.bind('isEnabled').to(this, '_areCommandsEnabled', ({ findNext }) => findNext);
|
|
173
|
+
this._injectFindResultsCounter();
|
|
174
|
+
fieldsetView.setTemplate({
|
|
175
|
+
tag: 'fieldset',
|
|
176
|
+
attributes: {
|
|
177
|
+
class: ['ck', 'ck-find-and-replace-form__find']
|
|
178
|
+
},
|
|
179
|
+
children: [
|
|
180
|
+
this._findInputView,
|
|
181
|
+
this._findButtonView,
|
|
182
|
+
this._findPrevButtonView,
|
|
183
|
+
this._findNextButtonView
|
|
184
|
+
]
|
|
185
|
+
});
|
|
186
|
+
return fieldsetView;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The action performed when the {@link #_findButtonView} is pressed.
|
|
190
|
+
*/
|
|
191
|
+
_onFindButtonExecute() {
|
|
192
|
+
// When hitting "Find" in an empty input, an error should be displayed.
|
|
193
|
+
// Also, if the form was "dirty", it should remain so.
|
|
194
|
+
if (!this._textToFind) {
|
|
195
|
+
const t = this.t;
|
|
196
|
+
this._findInputView.errorText = t('Text to find must not be empty.');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
// Hitting "Find" automatically clears the dirty state.
|
|
200
|
+
this.isDirty = false;
|
|
201
|
+
this.fire('findNext', {
|
|
202
|
+
searchText: this._textToFind,
|
|
203
|
+
matchCase: this._matchCase,
|
|
204
|
+
wholeWords: this._wholeWordsOnly
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Configures an injects the find results counter displaying a "N of M" label of the {@link #_findInputView}.
|
|
209
|
+
*/
|
|
210
|
+
_injectFindResultsCounter() {
|
|
211
|
+
const locale = this.locale;
|
|
212
|
+
const t = locale.t;
|
|
213
|
+
const bind = this.bindTemplate;
|
|
214
|
+
const resultsCounterView = new View(this.locale);
|
|
215
|
+
this.bind('_resultsCounterText').to(this, 'highlightOffset', this, 'matchCount', (highlightOffset, matchCount) => t('%0 of %1', [highlightOffset, matchCount]));
|
|
216
|
+
resultsCounterView.setTemplate({
|
|
217
|
+
tag: 'span',
|
|
218
|
+
attributes: {
|
|
219
|
+
class: [
|
|
220
|
+
'ck',
|
|
221
|
+
'ck-results-counter',
|
|
222
|
+
// The counter only makes sense when the field text corresponds to search results in the editing.
|
|
223
|
+
bind.if('isDirty', 'ck-hidden')
|
|
224
|
+
]
|
|
225
|
+
},
|
|
226
|
+
children: [
|
|
227
|
+
{
|
|
228
|
+
text: bind.to('_resultsCounterText')
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
});
|
|
232
|
+
// The whole idea is that when the text of the counter changes, its width also increases/decreases and
|
|
233
|
+
// it consumes more or less space over the input. The input, on the other hand, should adjust it's right
|
|
234
|
+
// padding so its *entire* text always remains visible and available to the user.
|
|
235
|
+
const updateFindInputPadding = () => {
|
|
236
|
+
const inputElement = this._findInputView.fieldView.element;
|
|
237
|
+
// Don't adjust the padding if the input (also: counter) were not rendered or not inserted into DOM yet.
|
|
238
|
+
if (!inputElement || !isVisible(inputElement)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const counterWidth = new Rect(resultsCounterView.element).width;
|
|
242
|
+
const paddingPropertyName = locale.uiLanguageDirection === 'ltr' ? 'paddingRight' : 'paddingLeft';
|
|
243
|
+
if (!counterWidth) {
|
|
244
|
+
inputElement.style[paddingPropertyName] = '';
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
inputElement.style[paddingPropertyName] = `calc( 2 * var(--ck-spacing-standard) + ${counterWidth}px )`;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
// Adjust the input padding when the text of the counter changes, for instance "1 of 200" is narrower than "123 of 200".
|
|
251
|
+
// Using "low" priority to let the text be set by the template binding first.
|
|
252
|
+
this.on('change:_resultsCounterText', updateFindInputPadding, { priority: 'low' });
|
|
253
|
+
// Adjust the input padding when the counter shows or hides. When hidden, there should be no padding. When it shows, the
|
|
254
|
+
// padding should be set according to the text of the counter.
|
|
255
|
+
// Using "low" priority to let the text be set by the template binding first.
|
|
256
|
+
this.on('change:isDirty', updateFindInputPadding, { priority: 'low' });
|
|
257
|
+
// Put the counter element next to the <input> in the find field.
|
|
258
|
+
this._findInputView.template.children[0].children.push(resultsCounterView);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Configures and returns the `<fieldset>` aggregating all replace controls.
|
|
262
|
+
*/
|
|
263
|
+
_createReplaceFieldset() {
|
|
264
|
+
const locale = this.locale;
|
|
265
|
+
const t = locale.t;
|
|
266
|
+
const fieldsetView = new View(this.locale);
|
|
267
|
+
this._replaceButtonView.bind('isEnabled').to(this, '_areCommandsEnabled', this, '_searchResultsFound', ({ replace }, resultsFound) => replace && resultsFound);
|
|
268
|
+
this._replaceAllButtonView.bind('isEnabled').to(this, '_areCommandsEnabled', this, '_searchResultsFound', ({ replaceAll }, resultsFound) => replaceAll && resultsFound);
|
|
269
|
+
this._replaceInputView.bind('isEnabled').to(this, '_areCommandsEnabled', this, '_searchResultsFound', ({ replace }, resultsFound) => replace && resultsFound);
|
|
270
|
+
this._replaceInputView.bind('infoText').to(this._replaceInputView, 'isEnabled', this._replaceInputView, 'isFocused', (isEnabled, isFocused) => {
|
|
271
|
+
if (isEnabled || !isFocused) {
|
|
272
|
+
return '';
|
|
273
|
+
}
|
|
274
|
+
return t('Tip: Find some text first in order to replace it.');
|
|
275
|
+
});
|
|
276
|
+
this._replaceButtonView.on('execute', () => {
|
|
277
|
+
this.fire('replace', {
|
|
278
|
+
searchText: this._textToFind,
|
|
279
|
+
replaceText: this._textToReplace
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
this._replaceAllButtonView.on('execute', () => {
|
|
283
|
+
this.fire('replaceAll', {
|
|
284
|
+
searchText: this._textToFind,
|
|
285
|
+
replaceText: this._textToReplace
|
|
286
|
+
});
|
|
287
|
+
this.focus();
|
|
288
|
+
});
|
|
289
|
+
fieldsetView.setTemplate({
|
|
290
|
+
tag: 'fieldset',
|
|
291
|
+
attributes: {
|
|
292
|
+
class: ['ck', 'ck-find-and-replace-form__replace']
|
|
293
|
+
},
|
|
294
|
+
children: [
|
|
295
|
+
this._replaceInputView,
|
|
296
|
+
this._optionsDropdown,
|
|
297
|
+
this._replaceButtonView,
|
|
298
|
+
this._replaceAllButtonView
|
|
299
|
+
]
|
|
300
|
+
});
|
|
301
|
+
return fieldsetView;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Creates, configures and returns and instance of a dropdown allowing users to narrow
|
|
305
|
+
* the search criteria down. The dropdown has a list with switch buttons for each option.
|
|
306
|
+
*/
|
|
307
|
+
_createOptionsDropdown() {
|
|
308
|
+
const locale = this.locale;
|
|
309
|
+
const t = locale.t;
|
|
310
|
+
const dropdownView = createDropdown(this.locale);
|
|
311
|
+
dropdownView.class = 'ck-options-dropdown';
|
|
312
|
+
dropdownView.buttonView.set({
|
|
313
|
+
withText: false,
|
|
314
|
+
label: t('Show options'),
|
|
315
|
+
icon: icons.cog,
|
|
316
|
+
tooltip: true
|
|
317
|
+
});
|
|
318
|
+
const matchCaseModel = new Model({
|
|
319
|
+
withText: true,
|
|
320
|
+
label: t('Match case'),
|
|
321
|
+
// A dummy read-only prop to make it easy to tell which switch was toggled.
|
|
322
|
+
_isMatchCaseSwitch: true
|
|
323
|
+
});
|
|
324
|
+
const wholeWordsOnlyModel = new Model({
|
|
325
|
+
withText: true,
|
|
326
|
+
label: t('Whole words only')
|
|
327
|
+
});
|
|
328
|
+
// Let the switches be controlled by form's observable properties.
|
|
329
|
+
matchCaseModel.bind('isOn').to(this, '_matchCase');
|
|
330
|
+
wholeWordsOnlyModel.bind('isOn').to(this, '_wholeWordsOnly');
|
|
331
|
+
// Update the state of the form when a switch is toggled.
|
|
332
|
+
dropdownView.on('execute', evt => {
|
|
333
|
+
if (evt.source._isMatchCaseSwitch) {
|
|
334
|
+
this._matchCase = !this._matchCase;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
this._wholeWordsOnly = !this._wholeWordsOnly;
|
|
338
|
+
}
|
|
339
|
+
// Toggling a switch makes the form dirty because this changes search criteria
|
|
340
|
+
// just like typing text of the find input.
|
|
341
|
+
this.isDirty = true;
|
|
342
|
+
});
|
|
343
|
+
addListToDropdown(dropdownView, new Collection([
|
|
344
|
+
{ type: 'switchbutton', model: matchCaseModel },
|
|
345
|
+
{ type: 'switchbutton', model: wholeWordsOnlyModel }
|
|
346
|
+
]));
|
|
347
|
+
return dropdownView;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Initializes the {@link #_focusables} and {@link #_focusTracker} to allow navigation
|
|
351
|
+
* using <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keystrokes in the right order.
|
|
352
|
+
*/
|
|
353
|
+
_initFocusCycling() {
|
|
354
|
+
const childViews = [
|
|
355
|
+
this._findInputView,
|
|
356
|
+
this._findButtonView,
|
|
357
|
+
this._findPrevButtonView,
|
|
358
|
+
this._findNextButtonView,
|
|
359
|
+
this._replaceInputView,
|
|
360
|
+
this._optionsDropdown,
|
|
361
|
+
this._replaceButtonView,
|
|
362
|
+
this._replaceAllButtonView
|
|
363
|
+
];
|
|
364
|
+
childViews.forEach(v => {
|
|
365
|
+
// Register the view as focusable.
|
|
366
|
+
this._focusables.add(v);
|
|
367
|
+
// Register the view in the focus tracker.
|
|
368
|
+
this._focusTracker.add(v.element);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Initializes the keystroke handling in the form.
|
|
373
|
+
*/
|
|
374
|
+
_initKeystrokeHandling() {
|
|
375
|
+
const stopPropagation = (data) => data.stopPropagation();
|
|
376
|
+
const stopPropagationAndPreventDefault = (data) => {
|
|
377
|
+
data.stopPropagation();
|
|
378
|
+
data.preventDefault();
|
|
379
|
+
};
|
|
380
|
+
// Start listening for the keystrokes coming from #element.
|
|
381
|
+
this._keystrokes.listenTo(this.element);
|
|
382
|
+
// Find the next result upon F3.
|
|
383
|
+
this._keystrokes.set('f3', event => {
|
|
384
|
+
stopPropagationAndPreventDefault(event);
|
|
385
|
+
this._findNextButtonView.fire('execute');
|
|
386
|
+
});
|
|
387
|
+
// Find the previous result upon F3.
|
|
388
|
+
this._keystrokes.set('shift+f3', event => {
|
|
389
|
+
stopPropagationAndPreventDefault(event);
|
|
390
|
+
this._findPrevButtonView.fire('execute');
|
|
391
|
+
});
|
|
392
|
+
// Find or replace upon pressing Enter in the find and replace fields.
|
|
393
|
+
this._keystrokes.set('enter', event => {
|
|
394
|
+
const target = event.target;
|
|
395
|
+
if (target === this._findInputView.fieldView.element) {
|
|
396
|
+
if (this._areCommandsEnabled.findNext) {
|
|
397
|
+
this._findNextButtonView.fire('execute');
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
this._findButtonView.fire('execute');
|
|
401
|
+
}
|
|
402
|
+
stopPropagationAndPreventDefault(event);
|
|
403
|
+
}
|
|
404
|
+
else if (target === this._replaceInputView.fieldView.element && !this.isDirty) {
|
|
405
|
+
this._replaceButtonView.fire('execute');
|
|
406
|
+
stopPropagationAndPreventDefault(event);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
// Find previous upon pressing Shift+Enter in the find field.
|
|
410
|
+
this._keystrokes.set('shift+enter', event => {
|
|
411
|
+
const target = event.target;
|
|
412
|
+
if (target !== this._findInputView.fieldView.element) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (this._areCommandsEnabled.findPrevious) {
|
|
416
|
+
this._findPrevButtonView.fire('execute');
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
this._findButtonView.fire('execute');
|
|
420
|
+
}
|
|
421
|
+
stopPropagationAndPreventDefault(event);
|
|
422
|
+
});
|
|
423
|
+
// Since the form is in the dropdown panel which is a child of the toolbar, the toolbar's
|
|
424
|
+
// keystroke handler would take over the key management in the URL input.
|
|
425
|
+
// We need to prevent this ASAP. Otherwise, the basic caret movement using the arrow keys will be impossible.
|
|
426
|
+
this._keystrokes.set('arrowright', stopPropagation);
|
|
427
|
+
this._keystrokes.set('arrowleft', stopPropagation);
|
|
428
|
+
this._keystrokes.set('arrowup', stopPropagation);
|
|
429
|
+
this._keystrokes.set('arrowdown', stopPropagation);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Creates a button view.
|
|
433
|
+
*
|
|
434
|
+
* @param options The properties of the `ButtonView`.
|
|
435
|
+
* @returns The button view instance.
|
|
436
|
+
*/
|
|
437
|
+
_createButton(options) {
|
|
438
|
+
const button = new ButtonView(this.locale);
|
|
439
|
+
button.set(options);
|
|
440
|
+
return button;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Creates a labeled input view.
|
|
444
|
+
*
|
|
445
|
+
* @param label The input label.
|
|
446
|
+
* @returns The labeled input view instance.
|
|
447
|
+
*/
|
|
448
|
+
_createInputField(label) {
|
|
449
|
+
const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
|
|
450
|
+
labeledInput.label = label;
|
|
451
|
+
return labeledInput;
|
|
452
|
+
}
|
|
453
|
+
}
|