From d3af8b877b6fb2bda2afebf0fb995ff56ecf5b5c Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 17 Sep 2013 16:36:49 -0700 Subject: [PATCH] dm.Surface: Initialize selection at (1,1) instead of (0,0) Code with a similar purpose was added in 568e0e5701 but got lost when some things were moved from ve.Surface to ve.ce.Surface in 5012ed10. Initializing the selection at (0,0) was known to cause problems before, and since 789d0caf093b breaks editing of empty documents: typing in an empty document begins in an inline slug, but SurfaceObserver doesn't notice typing in an inline slug unless the ce.Surface pawns it, which is OK because insertions in slugs are always pawned, but the pawning logic believes the cursor to be at offset 0 where there is no slug (it's at offset 1) and so it doesn't pawn. Bonus: update tests and add descriptions for dm.Surface.change tests Change-Id: Id72314d0fe650dacc7cdb842f5cea2f3bfba5145 --- modules/ve/dm/ve.dm.Surface.js | 2 +- modules/ve/test/dm/ve.dm.Surface.test.js | 10 +++++----- modules/ve/test/dm/ve.dm.SurfaceFragment.test.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/ve/dm/ve.dm.Surface.js b/modules/ve/dm/ve.dm.Surface.js index 735da78620..b6aec21ce2 100644 --- a/modules/ve/dm/ve.dm.Surface.js +++ b/modules/ve/dm/ve.dm.Surface.js @@ -21,7 +21,7 @@ ve.dm.Surface = function VeDmSurface( doc ) { // Properties this.documentModel = doc; this.metaList = new ve.dm.MetaList( this ); - this.selection = new ve.Range( 0, 0 ); + this.selection = new ve.Range( 1, 1 ); this.selectedNodes = {}; this.smallStack = []; this.bigStack = []; diff --git a/modules/ve/test/dm/ve.dm.Surface.test.js b/modules/ve/test/dm/ve.dm.Surface.test.js index 232897dcf3..e589d809de 100644 --- a/modules/ve/test/dm/ve.dm.Surface.test.js +++ b/modules/ve/test/dm/ve.dm.Surface.test.js @@ -51,11 +51,11 @@ QUnit.test( 'change', 3, function ( assert ) { events.change++; } ); surface.change( tx ); - assert.deepEqual( events, { 'transact': 1, 'select': 0, 'change': 1 } ); - surface.change( null, new ve.Range( 1, 1 ) ); - assert.deepEqual( events, { 'transact': 1, 'select': 1, 'change': 2 } ); - surface.change( tx, new ve.Range( 2, 2 ) ); - assert.deepEqual( events, { 'transact': 2, 'select': 2, 'change': 3 } ); + assert.deepEqual( events, { 'transact': 1, 'select': 0, 'change': 1 }, 'transaction without selection' ); + surface.change( null, new ve.Range( 2, 2 ) ); + assert.deepEqual( events, { 'transact': 1, 'select': 1, 'change': 2 }, 'selection without transaction' ); + surface.change( tx, new ve.Range( 3, 3 ) ); + assert.deepEqual( events, { 'transact': 2, 'select': 2, 'change': 3 }, 'transaction and selection' ); } ); QUnit.test( 'breakpoint', 7, function ( assert ) { diff --git a/modules/ve/test/dm/ve.dm.SurfaceFragment.test.js b/modules/ve/test/dm/ve.dm.SurfaceFragment.test.js index f188eab9fb..e8bc066773 100644 --- a/modules/ve/test/dm/ve.dm.SurfaceFragment.test.js +++ b/modules/ve/test/dm/ve.dm.SurfaceFragment.test.js @@ -16,7 +16,7 @@ QUnit.test( 'constructor', 8, function ( assert ) { // Default range and autoSelect assert.strictEqual( fragment.getSurface(), surface, 'surface reference is stored' ); assert.strictEqual( fragment.getDocument(), doc, 'document reference is stored' ); - assert.deepEqual( fragment.getRange(), new ve.Range( 0, 0 ), 'range is taken from surface' ); + assert.deepEqual( fragment.getRange(), new ve.Range( 1, 1 ), 'range is taken from surface' ); assert.strictEqual( fragment.willAutoSelect(), true, 'auto select by default' ); assert.strictEqual( fragment.isNull(), false, 'valid fragment is not null' ); // Invalid range and autoSelect