- rollback shorter url to original and ignore max length check for specific line

- add opts sanitize for applyDelata in YText
- apply applyDelata document about YText
This commit is contained in:
Cole 2020-06-03 11:00:50 +09:00
parent 9d3dd4e082
commit e4223760b0
2 changed files with 20 additions and 7 deletions

View File

@ -395,12 +395,14 @@ YTextEvents compute changes as deltas.
<dd></dd>
<b><code>format(index:number, length:number, formattingAttributes:Object&lt;string,string&gt;)</code></b>
<dd>Assign formatting attributes to a range in the text</dd>
<b><code>applyDelta(delta)</code></b>
<dd>See <a href="https://quilljs.com/docs/delta/">Quill Delta</a></dd>
<b><code>applyDelta(delta, opts:Object&lt;string,any&gt;)</code></b>
<dd>
See <a href="https://quilljs.com/docs/delta/">Quill Delta</a>
Can set options for preventing remove ending newLines, default is true.
<pre>ytext.applyDelta(delta, { sanitize: false })</pre>
</dd>
<b><code>length:number</code></b>
<dd></dd>
<b><code>permitEmptyParagraph(permit:boolean)</code></b>
<dd>Permit empty paragraph at the end of the content when applyDelta</dd>
<b><code>toString():string</code></b>
<dd>Transforms this type, without formatting options, into a string.</dd>
<b><code>toJSON():string</code></b>

View File

@ -848,10 +848,13 @@ export class YText extends AbstractType {
* Apply a {@link Delta} on this shared YText type.
*
* @param {any} delta The changes to apply on this element.
* @param {object} [opts]
* @param {boolean} [opts.sanitize] Sanitize input delta. Removes ending newlines if set to true.
*
*
* @public
*/
applyDelta (delta) {
applyDelta (delta, { sanitize = true } = {}) {
if (this.doc !== null) {
transact(this.doc, transaction => {
/**
@ -861,8 +864,16 @@ export class YText extends AbstractType {
const currentAttributes = new Map()
for (let i = 0; i < delta.length; i++) {
const op = delta[i]
if (op.insert !== undefined && (typeof op.insert !== 'string' || op.insert.length > 0)) {
pos = insertText(transaction, this, pos.left, pos.right, currentAttributes, op.insert, op.attributes || {})
if (op.insert !== undefined) {
// Quill assumes that the content starts with an empty paragraph.
// Yjs/Y.Text assumes that it starts empty. We always hide that
// there is a newline at the end of the content.
// If we omit this step, clients will see a different number of
// paragraphs, but nothing bad will happen.
const ins = (!sanitize && typeof op.insert === 'string' && i === delta.length - 1 && pos.right === null && op.insert.slice(-1) === '\n') ? op.insert.slice(0, -1) : op.insert
if (typeof ins !== 'string' || ins.length > 0) {
pos = insertText(transaction, this, pos.left, pos.right, currentAttributes, ins, op.attributes || {})
}
} else if (op.retain !== undefined) {
pos = formatText(transaction, this, pos.left, pos.right, currentAttributes, op.retain, op.attributes || {})
} else if (op.delete !== undefined) {