Przeglądaj źródła

Merge branch 'master' into t/48

Krzysztof Krztoń 9 lat temu
rodzic
commit
9a1280ce3b

+ 1 - 1
packages/ckeditor5-typing/.github/PULL_REQUEST_TEMPLATE.md

@@ -1,6 +1,6 @@
 ### Suggested merge commit message ([convention](https://github.com/ckeditor/ckeditor5-design/wiki/Git-commit-message-convention))
 
-Type: Message. Closes: #000.
+Type: Message. Closes #000.
 
 ---
 

+ 1 - 1
packages/ckeditor5-typing/src/input.js

@@ -215,7 +215,7 @@ class MutationHandler {
 		const viewPos = new ViewPosition( mutation.node, firstChangeAt );
 		const modelPos = this.editing.mapper.toModelPosition( viewPos );
 		const removeRange = deletions > 0 ? ModelRange.createFromPositionAndShift( modelPos, deletions ) : null;
-		const insertText = mutation.newText.substr( firstChangeAt, insertions );
+		const insertText = newText.substr( firstChangeAt, insertions );
 
 		this.editor.execute( 'input', {
 			text: insertText,

+ 55 - 0
packages/ckeditor5-typing/tests/input.js

@@ -249,6 +249,61 @@ describe( 'Input feature', () => {
 			expect( Batch.prototype.weakInsert.calledOnce ).to.be.true;
 			expect( Batch.prototype.remove.calledOnce ).to.be.true;
 		} );
+
+		it( 'should replace last   with space', () => {
+			model.enqueueChanges( () => {
+				model.selection.setRanges( [
+					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
+				] );
+			} );
+
+			view.fire( 'mutations', [
+				{
+					type: 'text',
+					oldText: 'foobar',
+					newText: 'foobar\u00A0',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				}
+			] );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>foobar []</paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p>foobar {}</p>' );
+		} );
+
+		it( 'should replace first &nbsp; with space', () => {
+			model.enqueueChanges( () => {
+				model.selection.setRanges( [
+					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
+				] );
+			} );
+
+			view.fire( 'mutations', [
+				{
+					type: 'text',
+					oldText: 'foobar',
+					newText: '\u00A0foobar',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				}
+			] );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph> foobar[]</paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p> foobar{}</p>' );
+		} );
+
+		it( 'should replace all &nbsp; with spaces', () => {
+			view.fire( 'mutations', [
+				{
+					type: 'text',
+					oldText: 'foobar',
+					newText: 'foobar\u00A0\u00A0\u00A0baz',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				}
+			] );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar   baz</paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p>foo{}bar' +
+				'   baz</p>' );
+		} );
 	} );
 
 	describe( 'keystroke handling', () => {

+ 0 - 15
packages/ckeditor5-typing/tests/manual/49/1.md

@@ -1,15 +0,0 @@
-### Issue [#49](https://github.com/ckeditor/ckeditor5-typing/issues/49) manual test
-
-Non-breakable spaces created by browser after using <kbd>space</kbd> should be changed to normal space characters when
-inserted to model and view. Still, `&nbsp;` have to be correctly rendered in DOM.
-
-Multiple consecutive spaces should be allowed, as well as spaces at the beginning or end of element.
-
-Open console and start using <kbd>space</kbd>. After each change, console is refreshed with output:
-* There should be no `&nbsp;` inserted in view and model after using <kbd>space</kbd>.
-* There should be `&nbsp;` in DOM and `getData` output, where needed.
-
-Use `editor.setData()` to test whether whitespaces in input HTML are correctly removed and `&nbsp;` are correctly
-saved in model and view. `&nbsp;` inserted through `editor.setData()` should be kept, not changed to normal spaces.
-
-Use the button to test whether `&nbsp;`s are correctly preserved in model, view and DOM.

+ 0 - 0
packages/ckeditor5-typing/tests/manual/49/1.html → packages/ckeditor5-typing/tests/manual/nbsp.html


+ 1 - 1
packages/ckeditor5-typing/tests/manual/49/1.js → packages/ckeditor5-typing/tests/manual/nbsp.js

@@ -7,7 +7,7 @@
 
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
 import Enter from '@ckeditor/ckeditor5-enter/src/enter';
-import Typing from '../../../src/typing';
+import Typing from '../../src/typing';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';

+ 21 - 0
packages/ckeditor5-typing/tests/manual/nbsp.md

@@ -0,0 +1,21 @@
+### `&nbsp;` handling test
+
+Typing plugin should correctly handle spaces and &nbsp; characters.
+
+**Requirements:**
+
+1. Non-breakable spaces created by browser when using <kbd>space</kbd> should be changed to normal space characters when
+inserted to model (and then, to view).
+2. In DOM we still need to render them as `&nbsp;`s.
+3. Multiple consecutive spaces should be allowed, as well as spaces at the beginning or end of element.
+4. `&nbsp;` characters inserted intentionally should be kept as `&nbsp;` in model (and view).
+5. Whitespaces should be removed when editor data is set.
+
+**Test steps:**
+
+1. Open console and start using <kbd>space</kbd>. After each change, console is refreshed with output:
+    - There should be no `&nbsp;` inserted in view and model after using <kbd>space</kbd>.
+    - There should be `&nbsp;` in DOM and `getData` output, where needed.
+2. Use `editor.setData()` to test whether whitespaces in input HTML are correctly removed and `&nbsp;` are correctly
+saved in model and view. `&nbsp;` inserted through `editor.setData()` should be kept, not changed to normal spaces.
+3. Use the button to test whether `&nbsp;`s are correctly preserved in model, view and DOM.