浏览代码

Fixed minor issues with view selection getSelectedElement.

Szymon Kupś 9 年之前
父节点
当前提交
aada33fa97
共有 2 个文件被更改,包括 12 次插入12 次删除
  1. 10 10
      packages/ckeditor5-engine/src/view/selection.js
  2. 2 2
      packages/ckeditor5-engine/tests/view/selection.js

+ 10 - 10
packages/ckeditor5-engine/src/view/selection.js

@@ -462,22 +462,22 @@ export default class Selection {
 	}
 
 	/**
-	 * Returns selected element. {@link engine.view.Element Element} is considered as selected if there is only
-	 * one range in selection, and that range is placed exactly on one element.
+	 * Returns the selected element. {@link engine.view.Element Element} is considered as selected if there is only
+	 * one range in the selection, and that range contains exactly one element.
 	 * Returns `null` if there is no selected element.
 	 *
-	 * @return {engine.view.Element|null}
+	 * @returns {engine.view.Element|null}
 	 */
 	getSelectedElement() {
-		if ( this.rangeCount == 1 ) {
-			const range = this.getFirstRange();
-			const nodeAfterStart = range.start.nodeAfter;
-			const nodeBeforeEnd = range.end.nodeBefore;
-
-			return nodeAfterStart instanceof Element && nodeAfterStart == nodeBeforeEnd ? nodeAfterStart : null;
+		if ( this.rangeCount !== 1 ) {
+			return null;
 		}
 
-		return null;
+		const range = this.getFirstRange();
+		const nodeAfterStart = range.start.nodeAfter;
+		const nodeBeforeEnd = range.end.nodeBefore;
+
+		return ( nodeAfterStart instanceof Element && nodeAfterStart == nodeBeforeEnd ) ? nodeAfterStart : null;
 	}
 
 	/**

+ 2 - 2
packages/ckeditor5-engine/tests/view/selection.js

@@ -789,9 +789,9 @@ describe( 'Selection', () => {
 	describe( 'getSelectedElement', () => {
 		it( 'should return selected element', () => {
 			const { selection, view } = parse( 'foo [<b>bar</b>] baz' );
-			const p = view.getChild( 1 );
+			const b = view.getChild( 1 );
 
-			expect( selection.getSelectedElement() ).to.equal( p );
+			expect( selection.getSelectedElement() ).to.equal( b );
 		} );
 
 		it( 'should return null if there is more than one range', () => {