Merge pull request #205 from Kisama/ytext-newline-option
Add sanitize option
This commit is contained in:
commit
149ca6f636
@ -395,8 +395,12 @@ YTextEvents compute changes as deltas.
|
||||
<dd></dd>
|
||||
<b><code>format(index:number, length:number, formattingAttributes:Object<string,string>)</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<string,any>)</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>toString():string</code></b>
|
||||
|
@ -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 => {
|
||||
/**
|
||||
@ -867,7 +870,7 @@ export class YText extends AbstractType {
|
||||
// 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 = (typeof op.insert === 'string' && i === delta.length - 1 && pos.right === null && op.insert.slice(-1) === '\n') ? op.insert.slice(0, -1) : op.insert
|
||||
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 || {})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user