Remove unnecessary _modifyScheduled field from JS Text/Combo classes

_modifyScheduled field was used to prevent the onSend listener to be
registered more than once. Actually, the implementation of
Connection#onNextSend takes care about it.
Always use onSend function to send "Modify" operation in Combo (prevent
multiple notify operations). This happens if text and selection are
changed very fast in editable Combo one after another.

Change-Id: I4933fed43f7ec04a5c8ec06c2d2b397698261a5b
Signed-off-by: Ivan Furnadjiev <ivan@eclipsesource.com>
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Combo.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Combo.js
index 44c2859..ca641bc 100755
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Combo.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Combo.js
@@ -14,7 +14,6 @@
 
   construct : function( isCCombo ) {
     this.base( arguments );
-    this._modifyScheduled = false;
     this._editable = true;
     this._userSelection = true;
     this._listMinWidth = -1;
@@ -333,14 +332,9 @@
 
     _onTextInput : function( event ) {
       if( this._editable ) {
-        var connection = rwt.remote.Connection.getInstance();
-        var remoteObject = connection.getRemoteObject( this );
-        if( !this._modifyScheduled && remoteObject.isListening( "Modify" ) ) {
-          this._modifyScheduled = true;
-          connection.onNextSend( this._onSend, this );
-          connection.sendDelayed( 500 );
-        }
+        var remoteObject = rwt.remote.Connection.getInstance().getRemoteObject( this );
         remoteObject.set( "text", this._field.getComputedValue() );
+        this._notifyModify( true );
         this._internalSelectionChanged = true;
         this._list.setSelectionIndex( -1 );
         this._internalSelectionChanged = false;
@@ -394,16 +388,24 @@
         }
         remoteObject.set( "selectionIndex", event.index );
         rwt.remote.EventUtil.notifySelected( this );
-        remoteObject.notify( "Modify" );
-        this._modifyScheduled = false;
+        this._notifyModify();
+      }
+    },
+
+    _notifyModify : function( delayed ) {
+      var connection = rwt.remote.Connection.getInstance();
+      if( connection.getRemoteObject( this ).isListening( "Modify" ) ) {
+        connection.onNextSend( this._onSend, this );
+        if( delayed ) {
+          connection.sendDelayed( 500 );
+        } else {
+          connection.send();
+        }
       }
     },
 
     _onSend : function( event ) {
-      if( this._modifyScheduled ) {
-        rwt.remote.Connection.getInstance().getRemoteObject( this ).notify( "Modify" );
-        this._modifyScheduled = false;
-      }
+      rwt.remote.Connection.getInstance().getRemoteObject( this ).notify( "Modify", null, true );
     }
 
     ////////////////////////////
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Text.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Text.js
index b699702..3127cf0 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Text.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Text.js
@@ -25,7 +25,6 @@
       this.setAllowStretchY( true );
       this.__oninput = rwt.util.Functions.bindEvent( this._oninputDomTextarea, this );
     }
-    this._modifyScheduled = false;
     this._message = null;
     this._messageElement = null;
     this._searchIconElement = null;
@@ -139,24 +138,24 @@
     },
 
     _handleModification : function() {
-      var connection = rwt.remote.Connection.getInstance();
-      var remoteObject = connection.getRemoteObject( this );
-      if( !this._modifyScheduled && remoteObject.isListening( "Modify" ) ) {
-        this._modifyScheduled = true;
-        connection.onNextSend( this._onSend, this );
-        connection.sendDelayed( 500 );
-      }
+      var remoteObject = rwt.remote.Connection.getInstance().getRemoteObject( this );
       remoteObject.set( "text", this.getComputedValue() );
+      this._notifyModify();
       this._detectSelectionChange();
     },
 
-    _onSend : function() {
-      if( this._modifyScheduled ) {
-        rwt.remote.Connection.getInstance().getRemoteObject( this ).notify( "Modify", null, true );
-        this._modifyScheduled = false;
+    _notifyModify : function() {
+      var connection = rwt.remote.Connection.getInstance();
+      if( connection.getRemoteObject( this ).isListening( "Modify" ) ) {
+        connection.onNextSend( this._onSend, this );
+        connection.sendDelayed( 500 );
       }
     },
 
+    _onSend : function() {
+      rwt.remote.Connection.getInstance().getRemoteObject( this ).notify( "Modify", null, true );
+    },
+
     ///////////////////
     // textarea support
 
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ComboTest.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ComboTest.js
index 83cc1d3..72f26e7 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ComboTest.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ComboTest.js
@@ -666,6 +666,25 @@
       assertNotNull( message.findNotifyOperation( "w3", "Modify" ) );
     },
 
+    testSendModify_onChangeSelection : function() {
+      TestUtil.fakeListener( combo, "Modify", true );
+      combo.setEditable( true );
+      combo.setListVisible( true );
+      combo.select( 3 );
+      TestUtil.flush();
+      combo.focus();
+      TestUtil.initRequestLog();
+
+      field.setValue( "a" );
+      field._oninput();
+      TestUtil.press( field, "Down" );
+
+      assertEquals( 1, TestUtil.getRequestsSend() );
+      var message = TestUtil.getMessageObject();
+      assertEquals( "Eiffel", message.findSetProperty( "w3", "text" ) );
+      assertNotNull( message.findNotifyOperation( "w3", "Modify" ) );
+    },
+
     testSelectionByFirstLetter_ReadOnly : function() {
       TestUtil.press( field, "R" );