improved granularity of prosemirror binding
This commit is contained in:
@@ -49,14 +49,14 @@ export class EventHandler {
|
||||
* Call all event listeners that were added via
|
||||
* {@link EventHandler#addEventListener}.
|
||||
*
|
||||
* @param {Transaction} transaction The transaction object // TODO: do we need this?
|
||||
* @param {Transaction} transaction The transaction object
|
||||
* @param {YEvent} event An event object that describes the change on a type.
|
||||
*/
|
||||
callEventListeners (transaction, event) {
|
||||
for (var i = 0; i < this.eventListeners.length; i++) {
|
||||
try {
|
||||
const f = this.eventListeners[i]
|
||||
f(event)
|
||||
f(event, transaction)
|
||||
} catch (e) {
|
||||
/*
|
||||
Your observer threw an error. This error was caught so that Yjs
|
||||
|
||||
10
utils/Y.js
10
utils/Y.js
@@ -28,17 +28,11 @@ import { Decoder } from '../lib/decoding.js' // eslint-disable-line
|
||||
*/
|
||||
export class Y extends NamedEventHandler {
|
||||
/**
|
||||
* @param {string} room Users in the same room share the same content
|
||||
* @param {Object} conf configuration
|
||||
* @param {Object} [conf] configuration
|
||||
*/
|
||||
constructor (room, conf = {}) {
|
||||
constructor (conf = {}) {
|
||||
super()
|
||||
this.gcEnabled = conf.gc || false
|
||||
/**
|
||||
* The room name that this Yjs instance connects to.
|
||||
* @type {String}
|
||||
*/
|
||||
this.room = room
|
||||
this._contentReady = false
|
||||
this.userID = generateRandomUint32()
|
||||
// TODO: This should be a Map so we can use encodables as keys
|
||||
|
||||
@@ -46,7 +46,7 @@ export const getRelativePosition = (type, offset) => {
|
||||
// TODO: rename to createRelativePosition
|
||||
let t = type._start
|
||||
while (t !== null) {
|
||||
if (t._deleted === false) {
|
||||
if (!t._deleted && t._countable) {
|
||||
if (t._length > offset) {
|
||||
return [t._id.user, t._id.clock + offset]
|
||||
}
|
||||
@@ -60,7 +60,7 @@ export const getRelativePosition = (type, offset) => {
|
||||
/**
|
||||
* @typedef {Object} AbsolutePosition The result of {@link fromRelativePosition}
|
||||
* @property {YType} type The type on which to apply the absolute position.
|
||||
* @property {Integer} offset The absolute offset.r
|
||||
* @property {number} offset The absolute offset.r
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -72,6 +72,9 @@ export const getRelativePosition = (type, offset) => {
|
||||
* (type + offset).
|
||||
*/
|
||||
export const fromRelativePosition = (y, rpos) => {
|
||||
if (rpos === null) {
|
||||
return null
|
||||
}
|
||||
if (rpos[0] === 'endof') {
|
||||
let id
|
||||
if (rpos[3] === null) {
|
||||
@@ -80,6 +83,9 @@ export const fromRelativePosition = (y, rpos) => {
|
||||
id = ID.createRootID(rpos[3], rpos[4])
|
||||
}
|
||||
let type = y.os.get(id)
|
||||
if (type === null) {
|
||||
return null
|
||||
}
|
||||
while (type._redone !== null) {
|
||||
type = type._redone
|
||||
}
|
||||
@@ -93,6 +99,9 @@ export const fromRelativePosition = (y, rpos) => {
|
||||
} else {
|
||||
let offset = 0
|
||||
let struct = y.os.findNodeWithUpperBound(ID.createID(rpos[0], rpos[1])).val
|
||||
if (struct === null || struct._id.user === ID.RootFakeUserID) {
|
||||
return null // TODO: support fake ids?
|
||||
}
|
||||
const diff = rpos[1] - struct._id.clock
|
||||
while (struct._redone !== null) {
|
||||
struct = struct._redone
|
||||
@@ -101,12 +110,12 @@ export const fromRelativePosition = (y, rpos) => {
|
||||
if (struct.constructor === GC || parent._deleted) {
|
||||
return null
|
||||
}
|
||||
if (!struct._deleted) {
|
||||
if (!struct._deleted && struct._countable) {
|
||||
offset = diff
|
||||
}
|
||||
struct = struct._left
|
||||
while (struct !== null) {
|
||||
if (!struct._deleted) {
|
||||
if (!struct._deleted && struct._countable) {
|
||||
offset += struct._length
|
||||
}
|
||||
struct = struct._left
|
||||
@@ -117,3 +126,5 @@ export const fromRelativePosition = (y, rpos) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const equal = (posa, posb) => posa === posb || (posa !== null && posb !== null && posa.length === posb.length && posa.every((v, i) => v === posb[i]))
|
||||
|
||||
Reference in New Issue
Block a user