rename to ListCursor
This commit is contained in:
parent
efcfe4b483
commit
a3b97d941b
@ -8,7 +8,7 @@ export * from './utils/encoding.js'
|
||||
export * from './utils/EventHandler.js'
|
||||
export * from './utils/ID.js'
|
||||
export * from './utils/isParentOf.js'
|
||||
export * from './utils/ListWalker.js'
|
||||
export * from './utils/ListCursor.js'
|
||||
export * from './utils/logging.js'
|
||||
export * from './utils/PermanentUserData.js'
|
||||
export * from './utils/RelativePosition.js'
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
createID,
|
||||
ContentAny,
|
||||
ContentBinary,
|
||||
ListWalker,
|
||||
ListCursor,
|
||||
ContentDoc, UpdateEncoderV1, UpdateEncoderV2, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
|
||||
@ -33,16 +33,16 @@ const freshSearchMarkerDistance = 30
|
||||
* @param {Transaction} tr
|
||||
* @param {AbstractType<any>} yarray
|
||||
* @param {number} index
|
||||
* @param {function(ListWalker):T} f
|
||||
* @param {function(ListCursor):T} f
|
||||
* @return T
|
||||
*/
|
||||
export const useSearchMarker = (tr, yarray, index, f) => {
|
||||
const searchMarker = yarray._searchMarker
|
||||
if (searchMarker === null || yarray._start === null || index < freshSearchMarkerDistance) {
|
||||
return f(new ListWalker(yarray).forward(tr, index, true))
|
||||
return f(new ListCursor(yarray).forward(tr, index, true))
|
||||
}
|
||||
if (searchMarker.length === 0) {
|
||||
const sm = new ListWalker(yarray).forward(tr, index, true)
|
||||
const sm = new ListCursor(yarray).forward(tr, index, true)
|
||||
searchMarker.push(sm)
|
||||
if (sm.nextItem) sm.nextItem.marker = true
|
||||
}
|
||||
@ -51,7 +51,7 @@ export const useSearchMarker = (tr, yarray, index, f) => {
|
||||
)
|
||||
const newIsCheaper = math.abs(sm.index - index) >= index
|
||||
const createFreshMarker = searchMarker.length < maxSearchMarker && (math.abs(sm.index - index) > freshSearchMarkerDistance || newIsCheaper)
|
||||
const fsm = createFreshMarker ? (newIsCheaper ? new ListWalker(yarray) : sm.clone()) : sm
|
||||
const fsm = createFreshMarker ? (newIsCheaper ? new ListCursor(yarray) : sm.clone()) : sm
|
||||
const prevItem = /** @type {Item} */ (sm.nextItem)
|
||||
if (createFreshMarker) {
|
||||
searchMarker.push(fsm)
|
||||
@ -94,10 +94,10 @@ export const useSearchMarker = (tr, yarray, index, f) => {
|
||||
*
|
||||
* This should be called before doing a deletion!
|
||||
*
|
||||
* @param {Array<ListWalker>} searchMarker
|
||||
* @param {Array<ListCursor>} searchMarker
|
||||
* @param {number} index
|
||||
* @param {number} len If insertion, len is positive. If deletion, len is negative.
|
||||
* @param {ListWalker|null} origSearchMarker Do not update this searchmarker because it is the one we used to manipulate. @todo !=null for improved perf in ytext
|
||||
* @param {ListCursor|null} origSearchMarker Do not update this searchmarker because it is the one we used to manipulate. @todo !=null for improved perf in ytext
|
||||
*/
|
||||
export const updateMarkerChanges = (searchMarker, index, len, origSearchMarker) => {
|
||||
for (let i = searchMarker.length - 1; i >= 0; i--) {
|
||||
@ -190,7 +190,7 @@ export class AbstractType {
|
||||
*/
|
||||
this._dEH = createEventHandler()
|
||||
/**
|
||||
* @type {null | Array<ListWalker>}
|
||||
* @type {null | Array<ListCursor>}
|
||||
*/
|
||||
this._searchMarker = null
|
||||
/**
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
YArrayRefID,
|
||||
callTypeObservers,
|
||||
transact,
|
||||
ListWalker,
|
||||
ListCursor,
|
||||
useSearchMarker,
|
||||
createRelativePositionFromTypeIndex,
|
||||
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, // eslint-disable-line
|
||||
@ -45,7 +45,7 @@ export class YArray extends AbstractType {
|
||||
*/
|
||||
this._prelimContent = []
|
||||
/**
|
||||
* @type {Array<ListWalker>}
|
||||
* @type {Array<ListCursor>}
|
||||
*/
|
||||
this._searchMarker = []
|
||||
}
|
||||
@ -262,7 +262,7 @@ export class YArray extends AbstractType {
|
||||
*/
|
||||
toArray () {
|
||||
return transact(/** @type {Doc} */ (this.doc), tr =>
|
||||
new ListWalker(this).slice(tr, this.length)
|
||||
new ListCursor(this).slice(tr, this.length)
|
||||
)
|
||||
}
|
||||
|
||||
@ -301,7 +301,7 @@ export class YArray extends AbstractType {
|
||||
*/
|
||||
map (f) {
|
||||
return transact(/** @type {Doc} */ (this.doc), tr =>
|
||||
new ListWalker(this).map(tr, f)
|
||||
new ListCursor(this).map(tr, f)
|
||||
)
|
||||
}
|
||||
|
||||
@ -312,7 +312,7 @@ export class YArray extends AbstractType {
|
||||
*/
|
||||
forEach (f) {
|
||||
return transact(/** @type {Doc} */ (this.doc), tr =>
|
||||
new ListWalker(this).forEach(tr, f)
|
||||
new ListCursor(this).forEach(tr, f)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ import {
|
||||
ContentType,
|
||||
useSearchMarker,
|
||||
findIndexCleanStart,
|
||||
ListWalker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ID, Doc, Item, Snapshot, Transaction // eslint-disable-line
|
||||
ListCursor, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ID, Doc, Item, Snapshot, Transaction // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
|
||||
import * as object from 'lib0/object'
|
||||
@ -785,7 +785,7 @@ export class YText extends AbstractType {
|
||||
*/
|
||||
this._pending = string !== undefined ? [() => this.insert(0, string)] : []
|
||||
/**
|
||||
* @type {Array<ListWalker>}
|
||||
* @type {Array<ListCursor>}
|
||||
*/
|
||||
this._searchMarker = []
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
typeListSlice,
|
||||
useSearchMarker,
|
||||
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook, Snapshot, // eslint-disable-line
|
||||
ListWalker
|
||||
ListCursor
|
||||
} from '../internals.js'
|
||||
|
||||
import * as error from 'lib0/error'
|
||||
@ -254,7 +254,7 @@ export class YXmlFragment extends AbstractType {
|
||||
*/
|
||||
toString () {
|
||||
if (this.doc != null) {
|
||||
return transact(this.doc, tr => new ListWalker(this).map(tr, xml => xml.toString()).join(''))
|
||||
return transact(this.doc, tr => new ListCursor(this).map(tr, xml => xml.toString()).join(''))
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ const lengthExceeded = error.create('Length exceeded!')
|
||||
* computed item.
|
||||
*
|
||||
* @param {Transaction} tr
|
||||
* @param {ListWalker} li
|
||||
* @param {ListCursor} li
|
||||
*/
|
||||
const popMovedStack = (tr, li) => {
|
||||
let { start, end, move } = li.movedStack.pop() || { start: null, end: null, move: null }
|
||||
@ -63,7 +63,7 @@ const popMovedStack = (tr, li) => {
|
||||
/**
|
||||
* Structure that helps to iterate through list-like structures. This is a useful abstraction that keeps track of move operations.
|
||||
*/
|
||||
export class ListWalker {
|
||||
export class ListCursor {
|
||||
/**
|
||||
* @param {AbstractType<any>} type
|
||||
*/
|
||||
@ -104,7 +104,7 @@ export class ListWalker {
|
||||
}
|
||||
|
||||
clone () {
|
||||
const iter = new ListWalker(this.type)
|
||||
const iter = new ListCursor(this.type)
|
||||
iter.index = this.index
|
||||
iter.rel = this.rel
|
||||
iter.nextItem = this.nextItem
|
||||
@ -244,7 +244,7 @@ export class ListWalker {
|
||||
/**
|
||||
* @param {Transaction} tr
|
||||
* @param {number} len
|
||||
* @return {ListWalker}
|
||||
* @return {ListCursor}
|
||||
*/
|
||||
backward (tr, len) {
|
||||
if (this.index - len < 0) {
|
||||
@ -594,7 +594,7 @@ const concatArrayContent = (content, added) => {
|
||||
* * Delete the stack-items that both of them have in common
|
||||
*
|
||||
* @param {Transaction} tr
|
||||
* @param {ListWalker} walker
|
||||
* @param {ListCursor} walker
|
||||
* @param {number} len
|
||||
* @return {Array<{ start: RelativePosition, end: RelativePosition }>}
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user