Ver código fonte

Pseudo-code better than nothing.

Piotrek Koszuliński 6 anos atrás
pai
commit
0041b03cd1
1 arquivos alterados com 7 adições e 19 exclusões
  1. 7 19
      packages/ckeditor5-engine/src/view/document.js

+ 7 - 19
packages/ckeditor5-engine/src/view/document.js

@@ -124,33 +124,21 @@ export default class Document {
 	 *
 	 * As a parameter, a post-fixer callback receives a {@link module:engine/view/downcastwriter~DowncastWriter downcast writer}.
 	 *
-	 * Here is an example from the link plugin which adds highlight class to the link if the selection is in that link:
+	 * Typically, a post-fixer will look like this:
 	 *
 	 *		editor.editing.view.document.registerPostFixer( writer => {
-	 *			const modelSelection = editor.model.document.selection;
-	 *
-	 *			if ( modelSelection.hasAttribute( 'linkHref' ) ) {
-	 *				// Get a range containing the entire link in which the given selection is placed.
-	 *				// See @ckeditor/ckeditor5-link/src/findlinkrange.
-	 *				const modelRange = findLinkRange( modelSelection );
-	 *				const viewRange = editor.editing.mapper.toViewRange( modelRange );
-	 *
-	 *				// There might be multiple `a` elements in the `viewRange`, for example,
-	 *				//  when the `a` element is broken by a UIElement.
-	 *				for ( const item of viewRange.getItems() ) {
-	 *					if ( item.is( 'a' ) ) {
-	 *						writer.addClass( HIGHLIGHT_CLASS, item );
-	 *					}
-	 *				}
+	 *			if ( checkSomeCondition() ) {
+	 *				writer.doSomething();
 	 *
 	 *				// Let other post-fixers know that something changed.
 	 *				return true;
 	 *			}
 	 *		} );
 	 *
-	 * Note that nothing will happen when you will execute this code in the console. It is because adding a post-fixer will not execute it.
-	 * It will be executed as soon as any change in the document causes rendering. If you want to re-render the editor's
-	 * view after registering the post-fixer then you should do it manually calling
+	 * Note that nothing happens right after you register a post-fixer (e.g. execute such a code in the console).
+	 * That is because adding a post-fixer does not execute it.
+	 * The post-fixer will be executed as soon as any change in the document needs to cause its rendering.
+	 * If you want to re-render the editor's view after registering the post-fixer then you should do it manually by calling
 	 * {@link module:engine/view/view~View#forceRender `view.forceRender()`}.
 	 *
 	 * If you need to register a callback which is executed when DOM elements are already updated,