monaco-editor-core
Version:
A browser based code editor
44 lines • 1.52 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* A simple tracker for dirty regions in a buffer.
*/
export class BufferDirtyTracker {
get dataOffset() {
return this._startIndex;
}
get dirtySize() {
if (this._startIndex === undefined || this._endIndex === undefined) {
return undefined;
}
return this._endIndex - this._startIndex + 1;
}
get isDirty() { return this._startIndex !== undefined; }
/**
* Flag the index(es) as modified. Returns the index flagged.
* @param index An index to flag.
* @param length An optional length to flag. Defaults to 1.
*/
flag(index, length = 1) {
this._flag(index);
if (length > 1) {
this._flag(index + length - 1);
}
return index;
}
_flag(index) {
if (this._startIndex === undefined || index < this._startIndex) {
this._startIndex = index;
}
if (this._endIndex === undefined || index > this._endIndex) {
this._endIndex = index;
}
}
clear() {
this._startIndex = undefined;
this._endIndex = undefined;
}
}
//# sourceMappingURL=bufferDirtyTracker.js.map