@ckeditor/ckeditor5-find-and-replace 29.2.0 → 32.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.
Files changed (53) hide show
  1. package/LICENSE.md +2 -2
  2. package/build/find-and-replace.js +3 -3
  3. package/build/translations/bs.js +1 -0
  4. package/build/translations/cs.js +1 -0
  5. package/build/translations/da.js +1 -0
  6. package/build/translations/de.js +1 -1
  7. package/build/translations/es.js +1 -0
  8. package/build/translations/hu.js +1 -1
  9. package/build/translations/id.js +1 -0
  10. package/build/translations/it.js +1 -1
  11. package/build/translations/nl.js +1 -0
  12. package/build/translations/no.js +1 -0
  13. package/build/translations/pl.js +1 -0
  14. package/build/translations/pt-br.js +1 -0
  15. package/build/translations/sr-latn.js +1 -0
  16. package/build/translations/sr.js +1 -0
  17. package/build/translations/zh-cn.js +1 -0
  18. package/build/translations/zh.js +1 -0
  19. package/lang/translations/bs.po +69 -0
  20. package/lang/translations/cs.po +69 -0
  21. package/lang/translations/da.po +69 -0
  22. package/lang/translations/de.po +4 -4
  23. package/lang/translations/en.po +1 -1
  24. package/lang/translations/es.po +69 -0
  25. package/lang/translations/gl.po +1 -1
  26. package/lang/translations/hu.po +4 -4
  27. package/lang/translations/id.po +69 -0
  28. package/lang/translations/it.po +4 -4
  29. package/lang/translations/nl.po +69 -0
  30. package/lang/translations/no.po +69 -0
  31. package/lang/translations/pl.po +69 -0
  32. package/lang/translations/pt-br.po +69 -0
  33. package/lang/translations/ru.po +1 -1
  34. package/lang/translations/sr-latn.po +69 -0
  35. package/lang/translations/sr.po +69 -0
  36. package/lang/translations/zh-cn.po +69 -0
  37. package/lang/translations/zh.po +69 -0
  38. package/package.json +23 -22
  39. package/src/findandreplace.js +1 -1
  40. package/src/findandreplaceediting.js +18 -7
  41. package/src/findandreplacestate.js +14 -2
  42. package/src/findandreplaceui.js +15 -8
  43. package/src/findcommand.js +19 -15
  44. package/src/findnextcommand.js +12 -9
  45. package/src/findpreviouscommand.js +5 -2
  46. package/src/index.js +1 -1
  47. package/src/replaceallcommand.js +4 -2
  48. package/src/replacecommand.js +12 -2
  49. package/src/ui/findandreplaceformview.js +15 -4
  50. package/src/utils.js +29 -23
  51. package/theme/findandreplace.css +1 -1
  52. package/theme/findandreplaceform.css +1 -1
  53. package/CHANGELOG.md +0 -4
package/src/utils.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
6
6
  /**
7
- * @module find-and-replace
7
+ * @module find-and-replace/utils
8
8
  */
9
9
 
10
10
  import { uid, Collection } from 'ckeditor5/src/utils';
@@ -13,11 +13,11 @@ import { escapeRegExp } from 'lodash-es';
13
13
  /**
14
14
  * Executes findCallback and updates search results list.
15
15
  *
16
- * @param {module:engine/model/range~Range} range
17
- * @param {module:engine/model/model~Model} model
18
- * @param {Function} findCallback
16
+ * @param {module:engine/model/range~Range} range The model range to scan for matches.
17
+ * @param {module:engine/model/model~Model} model The model.
18
+ * @param {Function} findCallback The callback that should return `true` if provided text matches the search term.
19
19
  * @param {module:utils/collection~Collection} [startResults] An optional collection of find matches that the function should
20
- * starts with. This would be a collection returned by a previous `updateFindResultFromRange()` call.
20
+ * start with. This would be a collection returned by a previous `updateFindResultFromRange()` call.
21
21
  * @returns {module:utils/collection~Collection} A collection of objects describing find match.
22
22
  *
23
23
  * An example structure:
@@ -33,20 +33,20 @@ import { escapeRegExp } from 'lodash-es';
33
33
  export function updateFindResultFromRange( range, model, findCallback, startResults ) {
34
34
  const results = startResults || new Collection();
35
35
 
36
- [ ...range ].forEach( ( { type, item } ) => {
37
- if ( type === 'elementStart' ) {
38
- if ( model.schema.checkChild( item, '$text' ) ) {
39
- const foundItems = findCallback( {
40
- item,
41
- text: rangeToText( model.createRangeIn( item ) )
42
- } );
36
+ model.change( writer => {
37
+ [ ...range ].forEach( ( { type, item } ) => {
38
+ if ( type === 'elementStart' ) {
39
+ if ( model.schema.checkChild( item, '$text' ) ) {
40
+ const foundItems = findCallback( {
41
+ item,
42
+ text: rangeToText( model.createRangeIn( item ) )
43
+ } );
43
44
 
44
- if ( !foundItems ) {
45
- return;
46
- }
45
+ if ( !foundItems ) {
46
+ return;
47
+ }
47
48
 
48
- foundItems.forEach( foundItem => {
49
- model.change( writer => {
49
+ foundItems.forEach( foundItem => {
50
50
  const resultId = `findResult:${ uid() }`;
51
51
  const marker = writer.addMarker( resultId, {
52
52
  usingOperation: false,
@@ -68,9 +68,9 @@ export function updateFindResultFromRange( range, model, findCallback, startResu
68
68
  index
69
69
  );
70
70
  } );
71
- } );
71
+ }
72
72
  }
73
- }
73
+ } );
74
74
  } );
75
75
 
76
76
  return results;
@@ -79,6 +79,9 @@ export function updateFindResultFromRange( range, model, findCallback, startResu
79
79
  /**
80
80
  * Returns text representation of a range. The returned text length should be the same as range length.
81
81
  * In order to achieve this this function will replace inline elements (text-line) as new line character ("\n").
82
+ *
83
+ * @param {module:engine/model/range~Range} range The model range.
84
+ * @returns {String} The text content of the provided range.
82
85
  */
83
86
  export function rangeToText( range ) {
84
87
  return Array.from( range.getItems() ).reduce( ( rangeText, node ) => {
@@ -93,6 +96,7 @@ export function rangeToText( range ) {
93
96
  }, '' );
94
97
  }
95
98
 
99
+ // Finds the appropriate index in the resultsList Collection.
96
100
  function findInsertIndex( resultsList, markerToInsert ) {
97
101
  const result = resultsList.find( ( { marker } ) => {
98
102
  return markerToInsert.getStart().isBefore( marker.getStart() );
@@ -101,6 +105,7 @@ function findInsertIndex( resultsList, markerToInsert ) {
101
105
  return result ? resultsList.getIndex( result ) : resultsList.length;
102
106
  }
103
107
 
108
+ // Maps RegExp match result to find result.
104
109
  function regexpMatchToFindResult( matchResult ) {
105
110
  const lastGroupIndex = matchResult.length - 1;
106
111
 
@@ -120,9 +125,10 @@ function regexpMatchToFindResult( matchResult ) {
120
125
  }
121
126
 
122
127
  /**
128
+ * Creates a text matching callback for a specified search term and matching options.
123
129
  *
124
- * @param {String} searchTerm
125
- * @param {Object} [options]
130
+ * @param {String} searchTerm The search term.
131
+ * @param {Object} [options] Matching options.
126
132
  * @param {Boolean} [options.matchCase=false] If set to `true` letter casing will be ignored.
127
133
  * @param {Boolean} [options.wholeWords=false] If set to `true` only whole words that match `callbackOrText` will be matched.
128
134
  * @returns {Function}
@@ -144,7 +150,7 @@ export function findByTextCallback( searchTerm, options ) {
144
150
  }
145
151
 
146
152
  if ( !new RegExp( nonLetterGroup + '$' ).test( searchTerm ) ) {
147
- regExpQuery = `${ regExpQuery }(?:_|${ nonLetterGroup }|$)`;
153
+ regExpQuery = `${ regExpQuery }(?=_|${ nonLetterGroup }|$)`;
148
154
  }
149
155
  }
150
156
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
package/CHANGELOG.md DELETED
@@ -1,4 +0,0 @@
1
- Changelog
2
- =========
3
-
4
- All changes in the package are documented in the main repository. See: https://github.com/ckeditor/ckeditor5/blob/master/CHANGELOG.md.