8
0
Просмотр исходного кода

Add code sample to getLastTextLine() function.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
0e54dbdfa0
1 измененных файлов с 22 добавлено и 0 удалено
  1. 22 0
      packages/ckeditor5-typing/src/utils/getlasttextline.js

+ 22 - 0
packages/ckeditor5-typing/src/utils/getlasttextline.js

@@ -13,6 +13,28 @@
  * "The last text line" is understood as text (from one or more text nodes) which is limited either by a parent block
  * or by inline elements (e.g. `<softBreak>`).
  *
+ * This method can be used to evaluate text from a block in which user sets cursor:
+ *
+ *		const selection = model.document.selection;
+ *
+ *		// Evaluate text in from selection parent up to the cursor:
+ *		const rangeToCheck = model.createRange(
+ *			model.createPositionAt( paragraph, 0 ),
+ *			model.createPositionAt( paragraph, 'end' )
+ *		);
+ *
+ *		const { text, range } = getLastTextLine( range, model );
+ *
+ *	The returned text will consist "Foo bar baz" for a model below:
+ *
+ *		<paragraph>Foo bar baz<paragraph>
+ *
+ * However, it will return only "baz" if there's a `<softBreak>` before "baz" text node:
+ *
+ *		<paragraph>Foo<softBreak>bar<softBreak>baz<paragraph>
+ *
+ * In the above example `range` will be set only "baz".
+ *
  * @protected
  * @param {module:engine/model/range~Range} range
  * @param {module:engine/model/model~Model} model