Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 305666
Collapse All | Expand All

(-)js/org/eclipse/rwt/widgets/Text.js (-2 / +5 lines)
Lines 93-107 Link Here
93
          var oldValue = this.getValue();
93
          var oldValue = this.getValue();
94
          // NOTE [tb] : When pasting strings, this might not always 
94
          // NOTE [tb] : When pasting strings, this might not always 
95
          //             behave like SWT. There is no reliable fix for that.
95
          //             behave like SWT. There is no reliable fix for that.
96
          var position = this.getSelectionStart();
96
          if( oldValue.length == ( value.length - 1 ) ) {
97
          if( oldValue.length == ( value.length - 1 ) ) {
97
            // The user added one character, undo.
98
            // The user added one character, undo.
98
            var position = this.getSelectionStart();
99
            this._inputElement.value = oldValue;
99
            this._inputElement.value = oldValue;
100
            this.setSelectionStart( position - 1 );
100
            this.setSelectionStart( position - 1 );
101
            this.setSelectionLength( 0 );
101
            this.setSelectionLength( 0 );
102
          } else if( value.length >= oldValue.length && value != oldValue) {
102
          } else if( value.length >= oldValue.length && value != oldValue) {
103
            // The user pasted a string, shorten:
103
            // The user pasted a string, shorten:
104
            this._inputElement.value = value.slice( 0, this.getMaxLength() );
104
            this._inputElement.value = value.slice( 0, this.getMaxLength() );            
105
            this.setSelectionStart( Math.min( position, this.getMaxLength() ) );
106
            this.setSelectionLength( 0 );
105
          }
107
          }
106
          if( this._inputElement.value == oldValue ) {
108
          if( this._inputElement.value == oldValue ) {
107
            fireEvents = false;
109
            fireEvents = false;
Lines 139-144 Link Here
139
      this._firstInputFixApplied = false;
141
      this._firstInputFixApplied = false;
140
      this._applyElement( this.getElement(), null );
142
      this._applyElement( this.getElement(), null );
141
      this._afterAppear();
143
      this._afterAppear();
144
      org.eclipse.swt.TextUtil._updateLineHeight( this );
142
      this._postApply();
145
      this._postApply();
143
      this._applyFocused( this.getFocused() );
146
      this._applyFocused( this.getFocused() );
144
      this.setSelectionStart( selectionStart );
147
      this.setSelectionStart( selectionStart );
(-)js/org/eclipse/rwt/test/tests/TextTest.js (-41 / +48 lines)
Lines 157-203 Link Here
157
      testUtil.clearTimerOnceLog();
157
      testUtil.clearTimerOnceLog();
158
    },
158
    },
159
    
159
    
160
    testTextAreaMaxLength : function() {
160
    testTextAreaMaxLength : qx.core.Variant.select("qx.client", {
161
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
161
      "mshtml" : function() {
162
      testUtil.prepareTimerUse();
162
        // NOTE: This test would fail in IE because it has a bug that sometimes
163
      var text = new org.eclipse.rwt.widgets.Text( true );
163
        // prevents a textFields value from being overwritten and read in the 
164
      org.eclipse.swt.TextUtil.initialize( text );
164
        // same call
165
      var changeLog = [];
165
      },
166
      text.addEventListener( "input", function(){
166
      "default" : function() {
167
        changeLog.push( true );
167
        var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
168
      } );
168
        testUtil.prepareTimerUse();
169
      text.setValue( "0123456789" );
169
        var text = new org.eclipse.rwt.widgets.Text( true );
170
      text.addToDocument();
170
        org.eclipse.swt.TextUtil.initialize( text );
171
      testUtil.flush();
171
        var changeLog = [];
172
      assertEquals( "0123456789", text.getValue() );
172
        text.addEventListener( "input", function(){
173
      assertEquals( "0123456789", text.getComputedValue() );
173
          changeLog.push( true );
174
      text.setMaxLength( 5 );
174
        } );
175
      assertEquals( "0123456789", text.getValue() );
175
        text.setValue( "0123456789" );
176
      assertEquals( "0123456789", text.getComputedValue() );
176
        text.addToDocument();
177
      assertEquals( 0, changeLog.length );
177
        testUtil.flush();
178
      text._inputElement.value = "012345678";
178
        assertEquals( "0123456789", text.getValue() );
179
      text.__oninput( {} );
179
        assertEquals( "0123456789", text.getComputedValue() );
180
      assertEquals( "012345678", text.getValue() );
180
        text.setMaxLength( 5 );
181
      assertEquals( "012345678", text.getComputedValue() );
181
        assertEquals( "0123456789", text.getValue() );
182
      assertEquals( 1, changeLog.length );
182
        assertEquals( "0123456789", text.getComputedValue() );
183
      text._inputElement.value = "01234567x8";
183
        assertEquals( 0, changeLog.length );
184
      text.setSelectionStart( 9 );
184
        text._inputElement.value = "012345678";
185
      text.__oninput( {} );
185
        text.__oninput( {} );
186
      assertEquals( "012345678", text.getValue() );
186
        assertEquals( "012345678", text.getValue() );
187
      assertEquals( "012345678", text.getComputedValue() );
187
        assertEquals( "012345678", text.getComputedValue() );
188
      assertEquals( 1, changeLog.length );
188
        assertEquals( 1, changeLog.length );
189
      assertEquals( 8, text.getSelectionStart() );
189
        text._inputElement.value = "01234567x8";
190
      text._inputElement.value = "abcdefghiklmnopq";
190
        text.setSelectionStart( 9 );
191
      text.__oninput( {} );
191
        text.__oninput( {} );
192
      assertEquals( "abcde", text.getValue() );
192
        assertEquals( "012345678", text.getValue() );
193
      assertEquals( "abcde", text.getComputedValue() );
193
        assertEquals( "012345678", text.getComputedValue() );
194
      assertEquals( 2, changeLog.length );
194
        assertEquals( 1, changeLog.length );
195
      assertEquals( 5, text.getSelectionStart() );
195
        assertEquals( 8, text.getSelectionStart() );
196
      text.setParent( null );
196
        text._inputElement.value = "abcdefghiklmnopq";
197
      text.destroy();
197
        text.__oninput( {} );
198
      testUtil.flush();
198
        assertEquals( "abcde", text.getValue() );
199
      testUtil.clearTimerOnceLog();
199
        assertEquals( "abcde", text.getComputedValue() );
200
    },
200
        assertEquals( 2, changeLog.length );
201
        assertEquals( 5, text.getSelectionStart() );
202
        text.setParent( null );
203
        text.destroy();
204
        testUtil.flush();
205
        testUtil.clearTimerOnceLog();
206
      }
207
    } )
201
208
202
  }
209
  }
203
  
210
  

Return to bug 305666