Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df215f4

Browse files
author
zhourenjian
committed
Fixed bug that resetting Link's text will clear registered listeners
1 parent ca0aea2 commit df215f4

File tree

1 file changed

+29
-3
lines changed
  • sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets

1 file changed

+29
-3
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Link.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public void run() {
343343
}
344344
};
345345
for (int i = 0; i < anchors.length; i++) {
346-
anchors[i].href = "javascript:void(0);";
346+
anchors[i].href = OS.isIE ? "#" : "javascript:void(0);";
347347
anchors[i].target = "_self";
348348
Clazz.addEvent(anchors[i], "click", hLinkSelectionHandler);
349349
Clazz.addEvent(anchors[i], "dblclick", hLinkSelectionHandler);
@@ -539,7 +539,7 @@ String parse (String string, Object handle) {
539539
}
540540
if (anchor != null) {
541541
if ("#".equals(ids[linkIndex])) {
542-
anchor.href = "javascript:void(0);";
542+
anchor.href = OS.isIE ? "#" : "javascript:void(0);";
543543
anchor.target = "_self";
544544
} else {
545545
anchor.href = ids[linkIndex];
@@ -843,8 +843,34 @@ public void setText (String string) {
843843
text = string;
844844
textSizeCached = false;
845845
anchors = new Element[0];
846+
847+
if (hLinkSelectionHandler != null) { // already hook
848+
// try to unhook it before clear all childNodes
849+
for (int i = 0; i < anchors.length; i++) {
850+
Element anchor = anchors[i];
851+
Clazz.removeEvent(anchor, "click", hLinkSelectionHandler);
852+
Clazz.removeEvent(anchor, "dblclick", hLinkSelectionHandler);
853+
if (ids != null) {
854+
if ("#".equals(ids[i])) {
855+
anchor.href = OS.isIE ? "#" : "javascript:void(0);";
856+
anchor.target = "_self";
857+
} else {
858+
anchor.href = ids[i];
859+
anchor.target = "_blank";
860+
}
861+
}
862+
}
863+
}
846864
OS.clearChildren(handle);
847865
parse (string, handle);
866+
if (hLinkSelectionHandler != null) {
867+
for (int i = 0; i < anchors.length; i++) {
868+
anchors[i].href = OS.isIE ? "#" : "javascript:void(0);";
869+
anchors[i].target = "_self";
870+
Clazz.addEvent(anchors[i], "click", hLinkSelectionHandler);
871+
Clazz.addEvent(anchors[i], "dblclick", hLinkSelectionHandler);
872+
}
873+
}
848874
/*
849875
if (OS.COMCTL32_MAJOR >= 6) {
850876
TCHAR buffer = new TCHAR (getCodePage (), string, true);
@@ -891,7 +917,7 @@ void unhookSelection() {
891917
Clazz.removeEvent(anchor, "dblclick", hLinkSelectionHandler);
892918
if (ids != null) {
893919
if ("#".equals(ids[i])) {
894-
anchor.href = "javascript:void(0);";
920+
anchor.href = OS.isIE ? "#" : "javascript:void(0);";
895921
anchor.target = "_self";
896922
} else {
897923
anchor.href = ids[i];

0 commit comments

Comments
 (0)