This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 164820
Collapse All | Expand All

(-)a/editor.lib/src/org/netbeans/editor/DrawEngineLineView.java (-1 / +37 lines)
Lines 52-57 Link Here
52
import javax.swing.text.Element;
52
import javax.swing.text.Element;
53
import javax.swing.text.JTextComponent;
53
import javax.swing.text.JTextComponent;
54
import javax.swing.text.Position;
54
import javax.swing.text.Position;
55
import javax.swing.text.Position.Bias;
55
import javax.swing.text.View;
56
import javax.swing.text.View;
56
import javax.swing.text.ViewFactory;
57
import javax.swing.text.ViewFactory;
57
import org.netbeans.editor.view.spi.EstimatedSpanView;
58
import org.netbeans.editor.view.spi.EstimatedSpanView;
Lines 894-898 Link Here
894
        }
895
        }
895
        
896
        
896
    } // End of FragmentView class
897
    } // End of FragmentView class
897
    
898
899
	// #164820
900
	@Override
901
	public int getNextVisualPositionFrom(int pos, Bias b, Shape a, int direction, Bias[] biasRet) throws BadLocationException {
902
		
903
		switch (direction) {
904
		case WEST:
905
			{
906
				pos = super.getNextVisualPositionFrom(pos, b, a, direction, biasRet);
907
				char[] chars = getDocument().getText(pos, 1).toCharArray();
908
				if (chars.length > 0 && Character.isLowSurrogate(chars[0])) {
909
					// Supplementary character
910
					return super.getNextVisualPositionFrom(pos, b, a, direction, biasRet);
911
				}
912
			}
913
			break;
914
915
		case EAST:
916
			{
917
				pos = super.getNextVisualPositionFrom(pos, b, a, direction, biasRet);
918
				char[] chars = getDocument().getText(pos, 1).toCharArray();
919
				if (chars.length > 0 && Character.isLowSurrogate(chars[0])) {
920
					// Supplementary character
921
					return super.getNextVisualPositionFrom(pos, b, a, direction, biasRet);
922
				}
923
			}
924
			break;
925
926
		default:
927
			pos = super.getNextVisualPositionFrom(pos, b, a, direction, biasRet);
928
			break;
929
		}
930
931
		return pos;
932
	}
933
	
898
}
934
}
(-)a/editor.lib/src/org/netbeans/editor/Mark.java (-3 / +20 lines)
Lines 47-52 Link Here
47
import javax.swing.text.BadLocationException;
47
import javax.swing.text.BadLocationException;
48
import javax.swing.text.Element;
48
import javax.swing.text.Element;
49
import javax.swing.text.Position;
49
import javax.swing.text.Position;
50
import javax.swing.text.Position.Bias;
50
51
51
/**
52
/**
52
* Marks hold the relative position in the document.
53
* Marks hold the relative position in the document.
Lines 109-117 Link Here
109
                + ", class=" + this.getClass()); // NOI18N
110
                + ", class=" + this.getClass()); // NOI18N
110
            }
111
            }
111
112
112
            if (offset < 0 || offset > ldoc.getLength() + 1) { // doc.getEndPosition() is valid
113
			if (offset < 0 || offset > ldoc.getLength() + 1) { // doc.getEndPosition() is valid
113
                throw new BadLocationException("Invalid offset", offset); // NOI18N
114
				throw new BadLocationException("Invalid offset", offset); // NOI18N
114
            }
115
			}
116
117
			// Deal with supplementary characters #164820
118
			char[] chars = doc.getText(offset, 1).toCharArray();
119
			if (chars.length > 0 && Character.isLowSurrogate(chars[0])) {
120
				if (bias == Bias.Forward && offset < ldoc.getLength()) {
121
					offset++;
122
123
				} else if (bias == Bias.Backward && offset > 0) {
124
					offset--;
125
				}
126
				
127
				// If there is still a low surrogate after recalculating,
128
				// treat it as an invalid document, just ignore and pass through.
129
				// Since there should be a surrogate pair in Java and Unicode to
130
				// represent a supplementary character.
131
			}
115
132
116
            multiMark = doc.marksStorage.createBiasMark(offset, bias);
133
            multiMark = doc.marksStorage.createBiasMark(offset, bias);
117
            doc.marksStorage.insert(multiMark);
134
            doc.marksStorage.insert(multiMark);
(-)a/editor.lib/src/org/netbeans/editor/Utilities.java (-9 / +29 lines)
Lines 355-372 Link Here
355
        int best = findBestSpan(c, start, end, x);
355
        int best = findBestSpan(c, start, end, x);
356
        
356
        
357
        if (best<c.getDocument().getLength()){
357
        if (best<c.getDocument().getLength()){
358
            // #56056
358
			// #56056
359
            int tmp = best + 1;
359
			int tmp = best + 1;
360
            int nextVisualPosition = c.getUI().getNextVisualPositionFrom(c,
360
			int nextVisualPosition = c.getUI().getNextVisualPositionFrom(c,
361
                    tmp, javax.swing.text.Position.Bias.Backward, javax.swing.SwingConstants.WEST, null);
361
					tmp, javax.swing.text.Position.Bias.Backward, javax.swing.SwingConstants.WEST, null);
362
            if (nextVisualPosition<best && nextVisualPosition >= 0){
362
            if (nextVisualPosition<best && nextVisualPosition >= 0){
363
                return nextVisualPosition;
363
				// #164820
364
            }
364
				// We are in the collapsed fold, now try to find which position
365
				// is the best, whether foldEnd or foldStart
366
				tempRect = c.modelToView(nextVisualPosition);
367
				if (tempRect == null) {
368
					return nextVisualPosition;
369
				}
370
				int leftX = tempRect.x;
371
				int nextVisualPositionRight = c.getUI().getNextVisualPositionFrom(c,
372
						nextVisualPosition, javax.swing.text.Position.Bias.Forward, javax.swing.SwingConstants.EAST, null);
373
				tempRect = c.modelToView(nextVisualPositionRight);
374
				if (tempRect == null) {
375
					return nextVisualPosition;
376
				}
377
				int rightX = tempRect.x;
378
379
				if (Math.abs(leftX - x) < Math.abs(rightX - x)) {
380
					return nextVisualPosition;
381
				} else {
382
					return nextVisualPositionRight;
383
				}
384
			}
365
        }
385
        }
366
        
386
367
        return best;
387
        return best;
368
    }    
388
    }
369
    
389
370
    /** Get the position that is one line above and visually at some
390
    /** Get the position that is one line above and visually at some
371
    * x-coordinate value.
391
    * x-coordinate value.
372
    * @param c text component to operate on
392
    * @param c text component to operate on

Return to bug 164820