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
-
isLocked : Boolean
module:typing/utils/changebuffer~ChangeBuffer#isLocked
readonly
Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
-
limit : Number
module:typing/utils/changebuffer~ChangeBuffer#limit
readonly
The maximum number of atomic changes which can be contained in one batch.
-
The model instance.
-
size : Number
module:typing/utils/changebuffer~ChangeBuffer#size
readonly
-
_batch
module:typing/utils/changebuffer~ChangeBuffer#_batch
private
The current batch instance.
-
_changeCallback
module:typing/utils/changebuffer~ChangeBuffer#_changeCallback
private
The callback to document the change event which later needs to be removed.
-
_selectionChangeCallback
module:typing/utils/changebuffer~ChangeBuffer#_selectionChangeCallback
private
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()
module:typing/utils/changebuffer~ChangeBuffer#destroy
Destroys the buffer.
-
input( changeCount )
module:typing/utils/changebuffer~ChangeBuffer#input
-
lock()
module:typing/utils/changebuffer~ChangeBuffer#lock
Locks the buffer.
-
unlock()
module:typing/utils/changebuffer~ChangeBuffer#unlock
Unlocks the buffer.
-
_reset( [ ignoreLock ] )
module:typing/utils/changebuffer~ChangeBuffer#_reset
private
Resets the change buffer.
Parameters
[ ignoreLock ] : Boolean
Whether internal lock
isLocked
should be ignored.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.