ChangeBuffer (typing/utils)
@ckeditor/ckeditor5-typing/src/utils/changebuffer
Change buffer allows to group atomic changes (like characters that have been typed) into batches.
Batches represent single undo steps, hence changes added to one single batch are undone together.
The buffer has a configurable limit of atomic changes that it can accommodate. After the limit was
exceeded (see input
), a new batch is created in batch
.
To use the change buffer you need to let it know about the number of changes that were added to the batch:
const buffer = new ChangeBuffer( model, LIMIT );
// Later on in your feature:
buffer.batch.insert( pos, insertedCharacters );
buffer.input( insertedCharacters.length );
Filtering
Properties
-
Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
-
The maximum number of atomic changes which can be contained in one batch.
-
The model instance.
-
The current batch instance.
-
private readonly
_changeCallback : ( EventInfo<string, unknown>, Batch ) => void
module:typing/utils/changebuffer~ChangeBuffer#_changeCallback
The callback to document the change event which later needs to be removed.
-
Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
-
private readonly
_selectionChangeCallback : () => void
module:typing/utils/changebuffer~ChangeBuffer#_selectionChangeCallback
The callback to document selection
change:attribute
andchange:range
events which resets the buffer.
Methods
-
constructor( model, limit )
module:typing/utils/changebuffer~ChangeBuffer#constructor
Creates a new instance of the change buffer.
Parameters
model : Model
limit : number
The maximum number of atomic changes which can be contained in one batch.
Defaults to
20
-
destroy() → void
module:typing/utils/changebuffer~ChangeBuffer#destroy
-
input( changeCount ) → void
module:typing/utils/changebuffer~ChangeBuffer#input
-
lock() → void
module:typing/utils/changebuffer~ChangeBuffer#lock
-
unlock() → void
module:typing/utils/changebuffer~ChangeBuffer#unlock
-
Resets the change buffer.
Parameters
ignoreLock : boolean
Whether internal lock
isLocked
should be ignored.Defaults to
false
Returns
void
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.