@@ -335,13 +335,16 @@ public void run() {
335
335
}
336
336
};
337
337
for (int i = 0 ; i < anchors .length ; i ++) {
338
- anchors [i ].href = "# " ;
338
+ anchors [i ].href = "javascript:void(0); " ;
339
339
anchors [i ].target = null ;
340
340
anchors [i ].onclick = linkHandler ;
341
341
anchors [i ].ondblclick = linkHandler ;
342
342
}
343
343
}
344
344
345
+ /**
346
+ * @j2sIgnore
347
+ */
345
348
void initAccessible () {
346
349
Accessible accessible = getAccessible ();
347
350
accessible .addAccessibleListener (new AccessibleAdapter () {
@@ -456,8 +459,10 @@ String parse (String string, Object handle) {
456
459
offsets = new Point [length / 4 ];
457
460
ids = new String [length / 4 ];
458
461
mnemonics = new int [length / 4 + 1 ];
459
- StringBuffer result = new StringBuffer ();
460
- StringBuffer result2 = new StringBuffer ();
462
+ // StringBuffer result = new StringBuffer ();
463
+ // StringBuffer result2 = new StringBuffer ();
464
+ char [] result = new char [0 ];
465
+ char [] result2 = new char [0 ];
461
466
char [] buffer = new char [length ];
462
467
string .getChars (0 , string .length (), buffer , 0 );
463
468
int index = 0 , state = 0 , linkIndex = 0 ;
@@ -508,21 +513,28 @@ String parse (String string, Object handle) {
508
513
case 6 :
509
514
if (c == '>' ) {
510
515
mnemonics [linkIndex ] = parseMnemonics (buffer , start , tagStart , result , result2 , handle );
511
- int offset = result .length ();
516
+ // int offset = result.length ();
517
+ int offset = result .length ;
512
518
Element anchor = null ;
513
519
if (handle != null ) {
514
520
anchor = document .createElement ("A" );
515
521
el .appendChild (anchor );
516
522
anchors [anchors .length ] = anchor ;
517
523
}
518
524
parseMnemonics (buffer , linkStart , endtagStart , result , result2 , anchor );
519
- offsets [linkIndex ] = new Point (offset , result .length () - 1 );
525
+ // offsets [linkIndex] = new Point (offset, result.length () - 1);
526
+ offsets [linkIndex ] = new Point (offset , result .length - 1 );
520
527
if (ids [linkIndex ] == null ) {
521
528
ids [linkIndex ] = new String (buffer , linkStart , endtagStart - linkStart );
522
529
}
523
530
if (anchor != null ) {
524
- anchor .href = ids [linkIndex ];
525
- anchor .target = "_blank" ;
531
+ if ("#" .equals (ids [linkIndex ])) {
532
+ anchor .href = "javascript:void(0);" ;
533
+ anchor .target = "_self" ;
534
+ } else {
535
+ anchor .href = ids [linkIndex ];
536
+ anchor .target = "_blank" ;
537
+ }
526
538
String title = ids [linkIndex ];
527
539
if (title != null && title .length () > 0 && !title .startsWith ("#" )) {
528
540
anchor .title = ids [linkIndex ];
@@ -599,31 +611,47 @@ String parse (String string, Object handle) {
599
611
System .arraycopy (mnemonics , 0 , newMnemonics , 0 , linkIndex + 1 );
600
612
mnemonics = newMnemonics ;
601
613
}
602
- cachedText = result2 .toString ();
614
+ // cachedText = result2.toString();
615
+ /**
616
+ * @j2sNative
617
+ * this.cachedText = result2.join ('');
618
+ */ {}
603
619
if (anchors != null && anchors .length > 0 && (hooks (SWT .Selection ) || hooks (SWT .DefaultSelection ))) {
604
620
hookSelection ();
605
621
}
622
+ /**
623
+ * @j2sNative
624
+ * return result.join ('');
625
+ */ {}
606
626
return result .toString ();
607
627
}
608
628
609
- int parseMnemonics (char [] buffer , int start , int end , StringBuffer result , StringBuffer result2 , Object handle ) {
629
+ //int parseMnemonics (char[] buffer, int start, int end, StringBuffer result, StringBuffer result2, Object handle) {
630
+ int parseMnemonics (char [] buffer , int start , int end , char [] result , char [] result2 , Object handle ) {
610
631
Element el = (Element ) handle ;
611
632
int mnemonic = -1 , index = start ;
612
- int lastIndex = result .length ();
633
+ // int lastIndex = result.length();
634
+ int lastIndex = result .length ;
613
635
while (index < end ) {
614
636
char c = buffer [index ];
615
- result2 .append (c );
637
+ // result2.append(c);
638
+ result2 [result2 .length ] = c ;
616
639
if (c == '&' ) {
617
640
if (index + 1 < end && buffer [index + 1 ] == '&' ) {
618
- result .append (c );
641
+ // result.append (c);
642
+ result [result .length ] = c ;
619
643
index ++;
620
644
} else {
621
- mnemonic = result .length ();
645
+ // mnemonic = result.length();
646
+ mnemonic = result .length ;
622
647
if (el != null ) {
623
648
if ((mnemonic > lastIndex ) && (el != null )) {
624
649
int len = mnemonic - lastIndex ;
625
650
char [] cs = new char [len ];
626
- result .getChars (lastIndex , mnemonic , cs , 0 );
651
+ // result.getChars(lastIndex, mnemonic, cs, 0);
652
+ for (int i = 0 ; i < cs .length ; i ++) {
653
+ cs [i ] = result [lastIndex + i ];
654
+ }
627
655
String s = new String (cs , 0 , len );
628
656
el .appendChild (document .createTextNode (s ));
629
657
}
@@ -634,12 +662,14 @@ int parseMnemonics (char[] buffer, int start, int end, StringBuffer result, Stri
634
662
}
635
663
}
636
664
} else {
637
- result .append (c );
665
+ // result.append (c);
666
+ result [result .length ] = c ;
638
667
}
639
668
boolean lineBreak = false ;
640
669
if (c == '\r' ) {
641
670
if (index + 1 < end && buffer [index + 1 ] == '\n' ) {
642
- result .append ('\n' );
671
+ // result.append ('\n');
672
+ result [result .length ] = '\n' ;
643
673
index ++;
644
674
}
645
675
lineBreak = true ;
@@ -648,11 +678,15 @@ int parseMnemonics (char[] buffer, int start, int end, StringBuffer result, Stri
648
678
lineBreak = true ;
649
679
}
650
680
if (lineBreak && el != null ) {
651
- int idx = result .length ();
681
+ // int idx = result.length();
682
+ int idx = result .length ;
652
683
if (idx > lastIndex ) {
653
684
int len = idx - lastIndex ;
654
685
char [] cs = new char [len ];
655
- result .getChars (lastIndex , idx , cs , 0 );
686
+ // result.getChars(lastIndex, idx, cs, 0);
687
+ for (int i = 0 ; i < cs .length ; i ++) {
688
+ cs [i ] = result [lastIndex + i ];
689
+ }
656
690
String s = new String (cs , 0 , len );
657
691
el .appendChild (document .createTextNode (s ));
658
692
}
@@ -661,11 +695,15 @@ int parseMnemonics (char[] buffer, int start, int end, StringBuffer result, Stri
661
695
}
662
696
index ++;
663
697
}
664
- int idx = result .length ();
698
+ // int idx = result.length();
699
+ int idx = result .length ;
665
700
if (idx > lastIndex && el != null ) {
666
701
int len = idx - lastIndex ;
667
702
char [] cs = new char [len ];
668
- result .getChars (lastIndex , idx , cs , 0 );
703
+ // result.getChars(lastIndex, idx, cs, 0);
704
+ for (int i = 0 ; i < cs .length ; i ++) {
705
+ cs [i ] = result [lastIndex + i ];
706
+ }
669
707
String s = new String (cs , 0 , len );
670
708
el .appendChild (document .createTextNode (s ));
671
709
}
@@ -833,10 +871,16 @@ public void setText (String string) {
833
871
834
872
void unhookSelection () {
835
873
for (int i = 0 ; i < anchors .length ; i ++) {
836
- anchors [i ].onclick = null ;
837
- anchors [i ].ondblclick = null ;
838
- anchors [i ].href = ids [i ];
839
- anchors [i ].target = "_blank" ;
874
+ Element anchor = anchors [i ];
875
+ anchor .onclick = null ;
876
+ anchor .ondblclick = null ;
877
+ if ("#" .equals (ids [i ])) {
878
+ anchor .href = "javascript:void(0);" ;
879
+ anchor .target = "_self" ;
880
+ } else {
881
+ anchor .href = ids [i ];
882
+ anchor .target = "_blank" ;
883
+ }
840
884
}
841
885
}
842
886
0 commit comments