浏览代码

Rename getText() to getLastTextLine().

Maciej Gołaszewski 6 年之前
父节点
当前提交
179c1f0333

+ 2 - 2
packages/ckeditor5-typing/src/textwatcher.js

@@ -9,7 +9,7 @@
 
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
-import getText from './utils/gettext';
+import getLastTextLine from './utils/getlasttextline';
 
 /**
  * The text watcher feature.
@@ -133,7 +133,7 @@ export default class TextWatcher {
 
 		const rangeBeforeSelection = model.createRange( model.createPositionAt( selection.focus.parent, 0 ), selection.focus );
 
-		return getText( rangeBeforeSelection, model );
+		return getLastTextLine( rangeBeforeSelection, model );
 	}
 }
 

+ 13 - 5
packages/ckeditor5-typing/src/utils/gettext.js

@@ -4,20 +4,20 @@
  */
 
 /**
- * @module typing/utils/gettext
+ * @module typing/utils/getlasttextline
  */
 
 /**
- * Returns the whole text from a given range by adding all data from the text nodes together.
+ * Returns a last text limited by a non-text node from a given range.
  *
- * **Note** The text is trimmed to the last occurrence of any inline element (e.g. `<softBreak>`).
+ * A text "line" is understood to be a text limited either by a parent block or by inline elements (e.g. `<softBreak>`).
  *
  * @protected
  * @param {module:engine/model/range~Range} range
  * @param {module:engine/model/model~Model} model
- * @returns {Object}
+ * @returns {module:typing/utils/getlasttextline~LastTextLineData}
  */
-export default function getText( range, model ) {
+export default function getLastTextLine( range, model ) {
 	let start = range.start;
 
 	const text = Array.from( range.getItems() ).reduce( ( rangeText, node ) => {
@@ -34,3 +34,11 @@ export default function getText( range, model ) {
 	return { text, range: model.createRange( start, range.end ) };
 }
 
+/**
+ * A value returned from the {@link module:typing/utils/getttext~getLastTextLine}.
+ *
+ * @typedef {Object} module:typing/utils/getlasttextline~LastTextLineData
+ *
+ * @property {String} text The text from the text nodes.
+ * @property {module:engine/model/range~Range} The trimmed range of the text.
+ */

+ 1 - 1
packages/ckeditor5-typing/tests/utils/gettext.js

@@ -5,7 +5,7 @@
 
 import Model from '@ckeditor/ckeditor5-engine/src/model/model';
 import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import getText from '../../src/utils/gettext';
+import getText from '../../src/utils/getlasttextline';
 
 describe( 'utils', () => {
 	let model, doc, root;