@@ -52,8 +52,8 @@ public class Text extends Scrollable {
5252 boolean doubleClick , ignoreModify , ignoreVerify , ignoreCharacter ;
5353
5454 boolean keyDownOK ;
55-
5655 Element textHandle ;
56+ private String textValue ;
5757
5858 int lineHeight ;
5959
@@ -197,6 +197,7 @@ void createHandle () {
197197 textHandle .type = "text" ;
198198 }
199199 }
200+ textValue = "" ;
200201 String textCSSName = null ;
201202 if (OS .isIE ) {
202203 textCSSName = "text-ie-default" ;
@@ -315,26 +316,33 @@ public void run() {
315316 String s = verifyText (txt , 0 , 0 , e );
316317 if (s == null ) {
317318 toReturn (false );
319+ return ;
318320 } else if (hooks (SWT .Modify )) {
319- Event ev = new Event ();
320- ev .type = SWT .Modify ;
321- ev .widget = Text .this ;
322- ev .display = display ;
323- ev .time = display .getLastEventTime ();
324- sendEvent (ev );
325- toReturn (ev .doit );
321+ if (textValue != textHandle .value ) {
322+ textValue = textHandle .value ;
323+ Event ev = new Event ();
324+ ev .type = SWT .Modify ;
325+ ev .widget = Text .this ;
326+ ev .display = display ;
327+ ev .time = display .getLastEventTime ();
328+ sendEvent (ev );
329+ toReturn (ev .doit );
330+ }
326331 }
327332 }
328333 }
329334 keyDownOK = this .isReturned ();
330335 if (!verifyHooked || hooks (SWT .KeyDown )) {
331336 Event ev = new Event ();
332- ev .type = SWT .Modify ;
333- ev .widget = Text .this ;
334- ev .display = display ;
335- ev .time = display .getLastEventTime ();
336- sendEvent (ev );
337- toReturn (ev .doit );
337+ if (textValue != textHandle .value ) {
338+ textValue = textHandle .value ;
339+ ev .type = SWT .Modify ;
340+ ev .widget = Text .this ;
341+ ev .display = display ;
342+ ev .time = display .getLastEventTime ();
343+ sendEvent (ev );
344+ toReturn (ev .doit );
345+ }
338346
339347 HTMLEventWrapper e = new HTMLEventWrapper (getEvent ());
340348 HTMLEvent evt = (HTMLEvent ) e .event ;
@@ -438,24 +446,25 @@ public void run() {
438446 }
439447 String newText = textHandle .value ;
440448 if (newText != null ) {
441- //String oldText = newText;
442449 newText = verifyText (newText , 0 , 0 , null );
443450 if (newText == null ) {
444451 toReturn (true );
445452 return ;
446453 }
447- //if (!newText.equals (oldText)) {
454+ if (textValue != textHandle .value ) {
455+ textValue = textHandle .value ;
448456 Event e = new Event ();
449457 e .type = SWT .Modify ;
450458 e .item = Text .this ;
451459 e .widget = Text .this ;
452460 sendEvent (e );
453461 toReturn (e .doit );
454- // }
462+ }
455463 }
456464 }
457465 };
458466 Clazz .addEvent (textHandle , "keyup" , hModifyKeyUp );
467+ Clazz .addEvent (textHandle , "change" , hModifyKeyUp );
459468
460469 hModifyBlur = new RunnableCompatibility () {
461470 public void run () {
@@ -629,6 +638,10 @@ public void append (String string) {
629638 OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
630639 */
631640 textHandle .value += string ;
641+ if (string .length () > 0 ) {
642+ textValue = textHandle .value ;
643+ sendEvent (SWT .Modify );
644+ }
632645}
633646
634647static int checkStyle (int style ) {
@@ -1632,10 +1645,16 @@ public void insert (String string) {
16321645 ignoreCharacter = false;
16331646 */
16341647 insertTextString (textHandle , string );
1648+ /*
16351649 if ((style & SWT.MULTI) != 0) {
16361650 sendEvent (SWT.Modify);
16371651 // widget could be disposed at this point
16381652 }
1653+ */
1654+ if (textValue != textHandle .value ) {
1655+ textValue = textHandle .value ;
1656+ sendEvent (SWT .Modify );
1657+ }
16391658}
16401659
16411660/**
@@ -1760,6 +1779,7 @@ protected void releaseHandle() {
17601779 hModifyFocus = null ;
17611780 }
17621781 if (hModifyKeyUp != null ) {
1782+ Clazz .removeEvent (textHandle , "change" , hModifyKeyUp );
17631783 Clazz .removeEvent (textHandle , "keyup" , hModifyKeyUp );
17641784 hModifyKeyUp = null ;
17651785 }
@@ -2385,10 +2405,16 @@ public void setText (String string) {
23852405 * notify the application that the text has changed.
23862406 * The fix is to send the event.
23872407 */
2388- //if ((style & SWT.MULTI) != 0) {
2408+ /*
2409+ if ((style & SWT.MULTI) != 0) {
23892410 sendEvent (SWT.Modify);
23902411 // widget could be disposed at this point
2391- //}
2412+ }
2413+ */
2414+ if (textValue != string ) {
2415+ textValue = string ;
2416+ sendEvent (SWT .Modify );
2417+ }
23922418}
23932419
23942420/**
0 commit comments