@scriptollc/react-quill
Advanced tools
Comparing version 2.2.10 to 2.2.11
{ | ||
"name": "@scriptollc/react-quill", | ||
"version": "2.2.10", | ||
"version": "2.2.11", | ||
"description": "The Quill rich-text editor as a React component.", | ||
@@ -5,0 +5,0 @@ "author": "zenoamaro <zenoamaro@gmail.com>", |
@@ -11,3 +11,2 @@ var DEFAULTS = { | ||
this.cursors = {} | ||
quill.on('text-change', this.applyDelta.bind(this)) | ||
} | ||
@@ -58,50 +57,2 @@ | ||
MultiCursor.prototype.shiftCursors = function (index, length, authorId) { | ||
authorId = authorId || null | ||
Object.keys(this.cursors).forEach((cursorKey) => { | ||
var cursor = this.cursors[cursorKey] | ||
var shift = Math.max(length, index - cursor.index) | ||
if (cursor.userId === authorId) { | ||
this.moveCursor(authorId, cursor.index + shift) | ||
} else if (cursor.index > index) { | ||
cursor.index += shift | ||
} | ||
}) | ||
// Object.values(this.cursors).forEach((cursor) => { | ||
// var shift = Math.max(length, index - cursor.index); | ||
// if(cursor.userId == authorId) { | ||
// this.moveCursor(authorId, cursor.index + shift); | ||
// } else if(cursor.index > index) { | ||
// cursor.index += shift; | ||
// } | ||
// }); | ||
} | ||
MultiCursor.prototype.update = function () { | ||
Object.keys(this.cursors).forEach((cursorKey) => { | ||
this.updateCursor(this.cursors[cursorKey]) | ||
}) | ||
// Object.values(this.cursors).forEach(this.updateCursor.bind(this)); | ||
} | ||
MultiCursor.prototype.applyDelta = function (delta) { | ||
var index = 0 | ||
delta.ops.forEach((op) => { | ||
var length = 0 | ||
if (op.insert) { | ||
length = op.insert.length || 1 | ||
var author = op.attributes ? op.attributes.author : null | ||
this.shiftCursors(index, length, author) | ||
} else if (op.delete) { | ||
this.shiftCursors(index, -1 * op.delete, null) | ||
} else if (op.retain) { | ||
this.shiftCursors(index, 0, null) | ||
length = op.retain | ||
} | ||
index += length | ||
}) | ||
this.update() | ||
} | ||
MultiCursor.prototype.buildCursor = function (name, color) { | ||
@@ -122,5 +73,18 @@ var cursorEl = document.createElement('span') | ||
var bounds = this.quill.getBounds(cursor.index) | ||
// MEMO : This is due to quill.js bug. When cursor is at the new line or | ||
// the end of the line, quill's `getBound` can not return correct | ||
// cursor position. Somewhat correct cursor position can be retrieved | ||
// if we getBound for the previous index. | ||
var newLine = false | ||
if (this.quill.getText(cursor.index, 1) === '\n' || this.quill.getText(cursor.index - 1, 1) === '\n') { | ||
bounds = this.quill.getBounds(cursor.index - 1) | ||
newLine = true | ||
} | ||
if (bounds) { | ||
cursor.elem.style.top = (bounds.top + this.quill.container.scrollTop) + 'px' | ||
cursor.elem.style.left = bounds.left + 'px' | ||
// WARNING SUPER HACKY (SORRY!) | ||
// If getBound was done with previous index, off set that by 5px | ||
cursor.elem.style.left = bounds.left + (newLine ? 5 : 0) + 'px' | ||
cursor.elem.style.height = bounds.height + 'px' | ||
@@ -127,0 +91,0 @@ var flag = cursor.elem.querySelector('.ql-cursor-flag') |
2315085
10672