Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #79 from ckeditor/t/78
Browse files Browse the repository at this point in the history
Fix: Fixed a bug when editor sometimes crashed when list item was moved outside and before a container in which it was. Closes #78.
  • Loading branch information
Piotr Jasiun committed Aug 25, 2017
2 parents aaf362c + d9d6196 commit 3d8814e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"devDependencies": {
"@ckeditor/ckeditor5-basic-styles": "^0.8.1",
"@ckeditor/ckeditor5-block-quote": "^0.1.1",
"@ckeditor/ckeditor5-clipboard": "^0.6.0",
"@ckeditor/ckeditor5-dev-lint": "^3.1.0",
"@ckeditor/ckeditor5-editor-classic": "^0.7.3",
Expand Down
14 changes: 10 additions & 4 deletions src/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,17 +577,23 @@ export function modelChangePostFixer( document ) {
}

if ( type == 'remove' ) {
const howMany = changes.range.end.offset - changes.range.start.offset;
const sourcePos = changes.sourcePosition._getTransformedByInsertion( changes.range.start, howMany, true );

// Fix list items after the cut-out range.
// This fix is needed if items in model after cut-out range have now wrong indents compared to their previous siblings.
_fixItemsIndent( changes.sourcePosition, document, batch );
_fixItemsIndent( sourcePos, document, batch );
// This fix is needed if two different nested lists got merged, change types of list items "below".
_fixItemsType( changes.sourcePosition, false, document, batch );
_fixItemsType( sourcePos, false, document, batch );
} else if ( type == 'move' ) {
const howMany = changes.range.end.offset - changes.range.start.offset;
const sourcePos = changes.sourcePosition._getTransformedByInsertion( changes.range.start, howMany, true );

// Fix list items after the cut-out range.
// This fix is needed if items in model after cut-out range have now wrong indents compared to their previous siblings.
_fixItemsIndent( changes.sourcePosition, document, batch );
_fixItemsIndent( sourcePos, document, batch );
// This fix is needed if two different nested lists got merged, change types of list items "below".
_fixItemsType( changes.sourcePosition, false, document, batch );
_fixItemsType( sourcePos, false, document, batch );

// Fix items in moved range.
// This fix is needed if inserted items are too deeply intended.
Expand Down
26 changes: 25 additions & 1 deletion tests/listengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import BoldEngine from '@ckeditor/ckeditor5-basic-styles/src/boldengine';
import UndoEngine from '@ckeditor/ckeditor5-undo/src/undoengine';
import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
import BlockQuoteEngine from '@ckeditor/ckeditor5-block-quote/src/blockquoteengine';

import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import { getData as getModelData, setData as setModelData, parse as parseModel } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
Expand All @@ -28,7 +29,7 @@ describe( 'ListEngine', () => {
beforeEach( () => {
return VirtualTestEditor
.create( {
plugins: [ Clipboard, BoldEngine, Paragraph, ListEngine, UndoEngine ]
plugins: [ Clipboard, BoldEngine, Paragraph, ListEngine, UndoEngine, BlockQuoteEngine ]
} )
.then( newEditor => {
editor = newEditor;
Expand Down Expand Up @@ -2999,6 +3000,29 @@ describe( 'ListEngine', () => {
'<listItem indent="1" type="bulleted">e</listItem>' +
'<listItem indent="1" type="bulleted">i</listItem>'
);

// #78.
test(
'move out of container',

'<blockQuote>' +
'<listItem indent="0" type="bulleted">a</listItem>' +
'<listItem indent="1" type="bulleted">b</listItem>' +
'<listItem indent="1" type="bulleted">c</listItem>' +
'<listItem indent="1" type="bulleted">d</listItem>' +
'[<listItem indent="2" type="bulleted">e</listItem>]' +
'</blockQuote>',

0,

'<listItem indent="0" type="bulleted">e</listItem>' +
'<blockQuote>' +
'<listItem indent="0" type="bulleted">a</listItem>' +
'<listItem indent="1" type="bulleted">b</listItem>' +
'<listItem indent="1" type="bulleted">c</listItem>' +
'<listItem indent="1" type="bulleted">d</listItem>' +
'</blockQuote>'
);
} );

describe( 'rename', () => {
Expand Down

0 comments on commit 3d8814e

Please sign in to comment.