rename to ListCursor

This commit is contained in:
Kevin Jahns 2022-07-19 14:49:46 +02:00
parent efcfe4b483
commit a3b97d941b
6 changed files with 23 additions and 23 deletions

View File

@ -8,7 +8,7 @@ export * from './utils/encoding.js'
export * from './utils/EventHandler.js' export * from './utils/EventHandler.js'
export * from './utils/ID.js' export * from './utils/ID.js'
export * from './utils/isParentOf.js' export * from './utils/isParentOf.js'
export * from './utils/ListWalker.js' export * from './utils/ListCursor.js'
export * from './utils/logging.js' export * from './utils/logging.js'
export * from './utils/PermanentUserData.js' export * from './utils/PermanentUserData.js'
export * from './utils/RelativePosition.js' export * from './utils/RelativePosition.js'

View File

@ -10,7 +10,7 @@ import {
createID, createID,
ContentAny, ContentAny,
ContentBinary, ContentBinary,
ListWalker, ListCursor,
ContentDoc, UpdateEncoderV1, UpdateEncoderV2, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, // eslint-disable-line ContentDoc, UpdateEncoderV1, UpdateEncoderV2, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, // eslint-disable-line
} from '../internals.js' } from '../internals.js'
@ -33,16 +33,16 @@ const freshSearchMarkerDistance = 30
* @param {Transaction} tr * @param {Transaction} tr
* @param {AbstractType<any>} yarray * @param {AbstractType<any>} yarray
* @param {number} index * @param {number} index
* @param {function(ListWalker):T} f * @param {function(ListCursor):T} f
* @return T * @return T
*/ */
export const useSearchMarker = (tr, yarray, index, f) => { export const useSearchMarker = (tr, yarray, index, f) => {
const searchMarker = yarray._searchMarker const searchMarker = yarray._searchMarker
if (searchMarker === null || yarray._start === null || index < freshSearchMarkerDistance) { 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) { 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) searchMarker.push(sm)
if (sm.nextItem) sm.nextItem.marker = true 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 newIsCheaper = math.abs(sm.index - index) >= index
const createFreshMarker = searchMarker.length < maxSearchMarker && (math.abs(sm.index - index) > freshSearchMarkerDistance || newIsCheaper) 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) const prevItem = /** @type {Item} */ (sm.nextItem)
if (createFreshMarker) { if (createFreshMarker) {
searchMarker.push(fsm) searchMarker.push(fsm)
@ -94,10 +94,10 @@ export const useSearchMarker = (tr, yarray, index, f) => {
* *
* This should be called before doing a deletion! * This should be called before doing a deletion!
* *
* @param {Array<ListWalker>} searchMarker * @param {Array<ListCursor>} searchMarker
* @param {number} index * @param {number} index
* @param {number} len If insertion, len is positive. If deletion, len is negative. * @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) => { export const updateMarkerChanges = (searchMarker, index, len, origSearchMarker) => {
for (let i = searchMarker.length - 1; i >= 0; i--) { for (let i = searchMarker.length - 1; i >= 0; i--) {
@ -190,7 +190,7 @@ export class AbstractType {
*/ */
this._dEH = createEventHandler() this._dEH = createEventHandler()
/** /**
* @type {null | Array<ListWalker>} * @type {null | Array<ListCursor>}
*/ */
this._searchMarker = null this._searchMarker = null
/** /**

View File

@ -8,7 +8,7 @@ import {
YArrayRefID, YArrayRefID,
callTypeObservers, callTypeObservers,
transact, transact,
ListWalker, ListCursor,
useSearchMarker, useSearchMarker,
createRelativePositionFromTypeIndex, createRelativePositionFromTypeIndex,
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, // eslint-disable-line UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, // eslint-disable-line
@ -45,7 +45,7 @@ export class YArray extends AbstractType {
*/ */
this._prelimContent = [] this._prelimContent = []
/** /**
* @type {Array<ListWalker>} * @type {Array<ListCursor>}
*/ */
this._searchMarker = [] this._searchMarker = []
} }
@ -262,7 +262,7 @@ export class YArray extends AbstractType {
*/ */
toArray () { toArray () {
return transact(/** @type {Doc} */ (this.doc), tr => 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) { map (f) {
return transact(/** @type {Doc} */ (this.doc), tr => 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) { forEach (f) {
return transact(/** @type {Doc} */ (this.doc), tr => return transact(/** @type {Doc} */ (this.doc), tr =>
new ListWalker(this).forEach(tr, f) new ListCursor(this).forEach(tr, f)
) )
} }

View File

@ -28,7 +28,7 @@ import {
ContentType, ContentType,
useSearchMarker, useSearchMarker,
findIndexCleanStart, 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' } from '../internals.js'
import * as object from 'lib0/object' import * as object from 'lib0/object'
@ -785,7 +785,7 @@ export class YText extends AbstractType {
*/ */
this._pending = string !== undefined ? [() => this.insert(0, string)] : [] this._pending = string !== undefined ? [() => this.insert(0, string)] : []
/** /**
* @type {Array<ListWalker>} * @type {Array<ListCursor>}
*/ */
this._searchMarker = [] this._searchMarker = []
} }

View File

@ -14,7 +14,7 @@ import {
typeListSlice, typeListSlice,
useSearchMarker, useSearchMarker,
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook, Snapshot, // eslint-disable-line UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook, Snapshot, // eslint-disable-line
ListWalker ListCursor
} from '../internals.js' } from '../internals.js'
import * as error from 'lib0/error' import * as error from 'lib0/error'
@ -254,7 +254,7 @@ export class YXmlFragment extends AbstractType {
*/ */
toString () { toString () {
if (this.doc != null) { 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 '' return ''
} }

View File

@ -30,7 +30,7 @@ const lengthExceeded = error.create('Length exceeded!')
* computed item. * computed item.
* *
* @param {Transaction} tr * @param {Transaction} tr
* @param {ListWalker} li * @param {ListCursor} li
*/ */
const popMovedStack = (tr, li) => { const popMovedStack = (tr, li) => {
let { start, end, move } = li.movedStack.pop() || { start: null, end: null, move: null } 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. * 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 * @param {AbstractType<any>} type
*/ */
@ -104,7 +104,7 @@ export class ListWalker {
} }
clone () { clone () {
const iter = new ListWalker(this.type) const iter = new ListCursor(this.type)
iter.index = this.index iter.index = this.index
iter.rel = this.rel iter.rel = this.rel
iter.nextItem = this.nextItem iter.nextItem = this.nextItem
@ -244,7 +244,7 @@ export class ListWalker {
/** /**
* @param {Transaction} tr * @param {Transaction} tr
* @param {number} len * @param {number} len
* @return {ListWalker} * @return {ListCursor}
*/ */
backward (tr, len) { backward (tr, len) {
if (this.index - len < 0) { if (this.index - len < 0) {
@ -594,7 +594,7 @@ const concatArrayContent = (content, added) => {
* * Delete the stack-items that both of them have in common * * Delete the stack-items that both of them have in common
* *
* @param {Transaction} tr * @param {Transaction} tr
* @param {ListWalker} walker * @param {ListCursor} walker
* @param {number} len * @param {number} len
* @return {Array<{ start: RelativePosition, end: RelativePosition }>} * @return {Array<{ start: RelativePosition, end: RelativePosition }>}
*/ */