mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-30 05:58:46 +02:00
Fix CKEditor change detector being misled by insert carriage plugin
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { Plugin, type Editor } from 'ckeditor5/src/core.js';
|
||||
import iTopDataProcessor from "./itop-data-processor";
|
||||
import InsertCarriageReturnAfterBlock from "../insert-carriage-return-after-block/insert-carriage-return-after-block.plugin";
|
||||
|
||||
/**
|
||||
* DetectChanges Plugin.
|
||||
*
|
||||
*/
|
||||
export default class DetectChanges extends Plugin {
|
||||
|
||||
private readonly _processor: iTopDataProcessor | undefined;
|
||||
|
||||
constructor( editor: Editor ) {
|
||||
super( editor );
|
||||
const sInitialValue:string = editor.config.get('detectChanges.initialValue') as string;
|
||||
@@ -17,15 +19,23 @@ export default class DetectChanges extends Plugin {
|
||||
// Initialize our own data processor
|
||||
const oProcessor = new iTopDataProcessor( editor.data.viewDocument, sInitialValue, editor.getData() ) as iTopDataProcessor;
|
||||
editor.data.processor = oProcessor;
|
||||
// Listen for the dataReady event only once
|
||||
editor.model.document.once('change:data', () => {
|
||||
oProcessor.setTransformedInitialValue( editor.getData());
|
||||
});
|
||||
this._processor = oProcessor;
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
const editor = this.editor;// Listen for the dataReady event only once
|
||||
editor.model.document.once('change:data', () => {
|
||||
if(this._processor ) {
|
||||
this._processor.setTransformedInitialValue(editor.getData());
|
||||
}
|
||||
});
|
||||
}
|
||||
static get pluginName() {
|
||||
return 'DetectChanges';
|
||||
}
|
||||
|
||||
// Needed as InsertCarriageReturnAfterBlock will possibly change data on initialization if there's a block in the content, so we need to make sure it's loaded first
|
||||
static get requires() {
|
||||
return [ InsertCarriageReturnAfterBlock ];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user