Lines 401-407
Link Here
|
401 |
public EditorCaret() { |
401 |
public EditorCaret() { |
402 |
caretItems = new GapList<>(); |
402 |
caretItems = new GapList<>(); |
403 |
sortedCaretItems = new GapList<>(); |
403 |
sortedCaretItems = new GapList<>(); |
404 |
CaretItem singleCaret = new CaretItem(this, null, null); |
404 |
CaretItem singleCaret = new CaretItem(this, null, Position.Bias.Forward, null, Position.Bias.Forward); |
405 |
caretItems.add(singleCaret); |
405 |
caretItems.add(singleCaret); |
406 |
sortedCaretItems.add(singleCaret); |
406 |
sortedCaretItems.add(singleCaret); |
407 |
|
407 |
|
Lines 418-423
Link Here
|
418 |
public int getDot() { |
418 |
public int getDot() { |
419 |
return getLastCaret().getDot(); |
419 |
return getLastCaret().getDot(); |
420 |
} |
420 |
} |
|
|
421 |
|
422 |
/** |
423 |
* Get a bias of the dot position which is either |
424 |
* {@link Position.Bias.Forward} or {@link Position.Bias.Backward} depending |
425 |
* on whether the caret biases towards the next character or previous one. |
426 |
* The bias is always forward for non bidirectional text document. |
427 |
* |
428 |
* @return either forward or backward bias. |
429 |
* @since 2.12 |
430 |
*/ |
431 |
@NonNull |
432 |
public Position.Bias getDotBias() { |
433 |
return getLastCaret().getDotBias(); |
434 |
} |
421 |
|
435 |
|
422 |
/** |
436 |
/** |
423 |
* Get mark offset of the last created caret in the underlying document. |
437 |
* Get mark offset of the last created caret in the underlying document. |
Lines 431-436
Link Here
|
431 |
} |
445 |
} |
432 |
|
446 |
|
433 |
/** |
447 |
/** |
|
|
448 |
* Get a bias of the mark position which is either |
449 |
* {@link Position.Bias.Forward} or {@link Position.Bias.Backward} depending |
450 |
* on whether the caret biases towards the next character or previous one. |
451 |
* The bias is always forward for non bidirectional text document. |
452 |
* |
453 |
* @return either forward or backward bias. |
454 |
* @since 2.12 |
455 |
*/ |
456 |
@NonNull |
457 |
public Position.Bias getMarkBias() { |
458 |
return getLastCaret().getMarkBias(); |
459 |
} |
460 |
|
461 |
/** |
434 |
* Get information about all existing carets in the order they were created. |
462 |
* Get information about all existing carets in the order they were created. |
435 |
* <br> |
463 |
* <br> |
436 |
* The list always has at least one item. The last caret (last item of the list) |
464 |
* The list always has at least one item. The last caret (last item of the list) |
Lines 530-536
Link Here
|
530 |
* @see Caret#setDot(int) |
558 |
* @see Caret#setDot(int) |
531 |
*/ |
559 |
*/ |
532 |
public @Override void setDot(final int offset) { |
560 |
public @Override void setDot(final int offset) { |
533 |
setDot(offset, MoveCaretsOrigin.DEFAULT); |
561 |
setDot(offset, Position.Bias.Forward, MoveCaretsOrigin.DEFAULT); |
534 |
} |
562 |
} |
535 |
|
563 |
|
536 |
/** |
564 |
/** |
Lines 547-557
Link Here
|
547 |
* actions (pg up, pg down, left, right, ...). |
575 |
* actions (pg up, pg down, left, right, ...). |
548 |
* </p> |
576 |
* </p> |
549 |
* @param offset new offset for the caret |
577 |
* @param offset new offset for the caret |
|
|
578 |
* @param bias new bias for the caret. Use either {@link Position.Bias.Forward} |
579 |
* or {@link Position.Bias.Backward} depending on whether the caret should bias |
580 |
* towards the next character or previous one. Use forward bias for non-bidirectional text document. |
550 |
* @param orig specifies the operation which caused the caret to move. |
581 |
* @param orig specifies the operation which caused the caret to move. |
551 |
* @see #setDot(int) |
582 |
* @see #setDot(int) |
552 |
* @since 2.10 |
583 |
* @since 2.10 |
553 |
*/ |
584 |
*/ |
554 |
public void setDot(final int offset, MoveCaretsOrigin orig) { |
585 |
public void setDot(final int offset, Position.Bias bias, MoveCaretsOrigin orig) { |
555 |
if (LOG.isLoggable(Level.FINE)) { |
586 |
if (LOG.isLoggable(Level.FINE)) { |
556 |
LOG.fine("setDot: offset=" + offset); //NOI18N |
587 |
LOG.fine("setDot: offset=" + offset); //NOI18N |
557 |
if (LOG.isLoggable(Level.FINEST)) { |
588 |
if (LOG.isLoggable(Level.FINEST)) { |
Lines 585-591
Link Here
|
585 |
* @see Caret#moveDot(int) |
616 |
* @see Caret#moveDot(int) |
586 |
*/ |
617 |
*/ |
587 |
public @Override void moveDot(final int offset) { |
618 |
public @Override void moveDot(final int offset) { |
588 |
moveDot(offset, MoveCaretsOrigin.DEFAULT); |
619 |
moveDot(offset, Position.Bias.Forward, MoveCaretsOrigin.DEFAULT); |
589 |
} |
620 |
} |
590 |
|
621 |
|
591 |
/** |
622 |
/** |
Lines 603-613
Link Here
|
603 |
* </p> |
634 |
* </p> |
604 |
* |
635 |
* |
605 |
* @param offset new offset for the caret |
636 |
* @param offset new offset for the caret |
|
|
637 |
* @param bias new bias for the caret. Use either {@link Position.Bias.Forward} |
638 |
* or {@link Position.Bias.Backward} depending on whether the caret should bias |
639 |
* towards the next character or previous one. Use forward bias for non-bidirectional text document. |
606 |
* @param orig specifies the operation which caused the caret to move. |
640 |
* @param orig specifies the operation which caused the caret to move. |
607 |
* @see #moveDot(int) |
641 |
* @see #moveDot(int) |
608 |
* @since 2.10 |
642 |
* @since 2.10 |
609 |
*/ |
643 |
*/ |
610 |
public void moveDot(final int offset, MoveCaretsOrigin orig) { |
644 |
public void moveDot(final int offset, Position.Bias bias, MoveCaretsOrigin orig) { |
611 |
if (LOG.isLoggable(Level.FINE)) { |
645 |
if (LOG.isLoggable(Level.FINE)) { |
612 |
LOG.fine("moveDot: offset=" + offset); //NOI18N |
646 |
LOG.fine("moveDot: offset=" + offset); //NOI18N |
613 |
} |
647 |
} |
Lines 719-736
Link Here
|
719 |
* </pre> |
753 |
* </pre> |
720 |
* |
754 |
* |
721 |
* @param dotPos position of the newly created caret. |
755 |
* @param dotPos position of the newly created caret. |
|
|
756 |
* @param dotBias bias of the new caret. Use either {@link Position.Bias.Forward} |
757 |
* or {@link Position.Bias.Backward} depending on whether the caret should bias |
758 |
* towards the next character or previous one. Use forward bias for non-bidirectional text document. |
722 |
* @param markPos beginning of the selection (the other end is dotPos) or the same position like dotPos for no selection. |
759 |
* @param markPos beginning of the selection (the other end is dotPos) or the same position like dotPos for no selection. |
723 |
* The markPos may have higher offset than dotPos to select in a backward direction. |
760 |
* The markPos may have higher offset than dotPos to select in a backward direction. |
|
|
761 |
* @param markBias bias of the begining of the selection. Use either {@link Position.Bias.Forward} |
762 |
* or {@link Position.Bias.Backward} depending on whether the caret should bias |
763 |
* towards the next character or previous one. Use forward bias for non-bidirectional text document. |
724 |
* @return difference between current count of carets and the number of carets when the operation started. |
764 |
* @return difference between current count of carets and the number of carets when the operation started. |
725 |
* Returns Integer.MIN_VALUE if the operation was cancelled due to the caret not being installed in any text component |
765 |
* Returns Integer.MIN_VALUE if the operation was canceled due to the caret not being installed in any text component |
726 |
* or no document installed in the text component. |
766 |
* or no document installed in the text component. |
727 |
* <br> |
767 |
* <br> |
728 |
* Note that adding a new caret to offset where another caret is already located may lead |
768 |
* Note that adding a new caret to offset where another caret is already located may lead |
729 |
* or no document installed in the text component. |
769 |
* or no document installed in the text component. |
730 |
*/ |
770 |
*/ |
731 |
public int addCaret(@NonNull Position dotPos, @NonNull Position markPos) { |
771 |
public int addCaret(@NonNull Position dotPos, @NonNull Position.Bias dotBias, |
|
|
772 |
@NonNull Position markPos, @NonNull Position.Bias markBias) |
773 |
{ |
732 |
return runTransaction(CaretTransaction.RemoveType.NO_REMOVE, 0, |
774 |
return runTransaction(CaretTransaction.RemoveType.NO_REMOVE, 0, |
733 |
new CaretItem[] { new CaretItem(this, dotPos, markPos) }, null); |
775 |
new CaretItem[] { new CaretItem(this, dotPos, dotBias, markPos, markBias) }, null); |
734 |
} |
776 |
} |
735 |
|
777 |
|
736 |
/** |
778 |
/** |
Lines 758-770
Link Here
|
758 |
* @param dotAndMarkPosPairs list of position pairs consisting of dot position |
800 |
* @param dotAndMarkPosPairs list of position pairs consisting of dot position |
759 |
* and mark position (selection start position) which may be the same position like the dot |
801 |
* and mark position (selection start position) which may be the same position like the dot |
760 |
* if the particular caret has no selection. The list must have even size. |
802 |
* if the particular caret has no selection. The list must have even size. |
|
|
803 |
* @param dotAndMarkBiases list of position biases (corresponding to the dot and mark positions |
804 |
* in the previous parameter) or null may be passed if all dotAndMarkPosPairs positions should have a forward bias. |
761 |
* @return difference between current count of carets and the number of carets when the operation started. |
805 |
* @return difference between current count of carets and the number of carets when the operation started. |
762 |
* Returns Integer.MIN_VALUE if the operation was cancelled due to the caret not being installed in any text component |
806 |
* Returns Integer.MIN_VALUE if the operation was canceled due to the caret not being installed in any text component |
763 |
* or no document installed in the text component. |
807 |
* or no document installed in the text component. |
|
|
808 |
* @see #addCaret(javax.swing.text.Position, javax.swing.text.Position.Bias, javax.swing.text.Position, javax.swing.text.Position.Bias) |
764 |
*/ |
809 |
*/ |
765 |
public int addCarets(@NonNull List<Position> dotAndMarkPosPairs) { |
810 |
public int addCarets(@NonNull List<Position> dotAndMarkPosPairs, List<Position.Bias> dotAndMarkBiases) { |
766 |
return runTransaction(CaretTransaction.RemoveType.NO_REMOVE, 0, |
811 |
return runTransaction(CaretTransaction.RemoveType.NO_REMOVE, 0, |
767 |
CaretTransaction.asCaretItems(this, dotAndMarkPosPairs), null); |
812 |
CaretTransaction.asCaretItems(this, dotAndMarkPosPairs, dotAndMarkBiases), null); |
768 |
} |
813 |
} |
769 |
|
814 |
|
770 |
/** |
815 |
/** |
Lines 776-790
Link Here
|
776 |
* @param dotAndMarkPosPairs list of position pairs consisting of dot position |
821 |
* @param dotAndMarkPosPairs list of position pairs consisting of dot position |
777 |
* and mark position (selection start position) which may be the same position like dot |
822 |
* and mark position (selection start position) which may be the same position like dot |
778 |
* if the particular caret has no selection. The list must have even size. |
823 |
* if the particular caret has no selection. The list must have even size. |
|
|
824 |
* @param dotAndMarkBiases list of position biases (corresponding to the dot and mark positions |
825 |
* in the previous parameter) or null may be passed if all dotAndMarkPosPairs positions should have a forward bias. |
779 |
* @return difference between current count of carets and the number of carets when the operation started. |
826 |
* @return difference between current count of carets and the number of carets when the operation started. |
780 |
* Returns Integer.MIN_VALUE if the operation was cancelled due to the caret not being installed in any text component |
827 |
* Returns Integer.MIN_VALUE if the operation was cancelled due to the caret not being installed in any text component |
781 |
* or no document installed in the text component. |
828 |
* or no document installed in the text component. |
782 |
*/ |
829 |
*/ |
783 |
public int replaceCarets(@NonNull List<Position> dotAndMarkPosPairs) { |
830 |
public int replaceCarets(@NonNull List<Position> dotAndMarkPosPairs, List<Position.Bias> dotAndMarkBiases) { |
784 |
if (dotAndMarkPosPairs.isEmpty()) { |
831 |
if (dotAndMarkPosPairs.isEmpty()) { |
785 |
throw new IllegalArgumentException("dotAndSelectionStartPosPairs list must not be empty"); |
832 |
throw new IllegalArgumentException("dotAndSelectionStartPosPairs list must not be empty"); |
786 |
} |
833 |
} |
787 |
CaretItem[] addedItems = CaretTransaction.asCaretItems(this, dotAndMarkPosPairs); |
834 |
CaretItem[] addedItems = CaretTransaction.asCaretItems(this, dotAndMarkPosPairs, dotAndMarkBiases); |
788 |
return runTransaction(CaretTransaction.RemoveType.REMOVE_ALL_CARETS, 0, addedItems, null); |
835 |
return runTransaction(CaretTransaction.RemoveType.REMOVE_ALL_CARETS, 0, addedItems, null); |
789 |
} |
836 |
} |
790 |
|
837 |
|
Lines 1784-1790
Link Here
|
1784 |
|
1831 |
|
1785 |
// Set caret to zero position upon document change (DefaultCaret impl does this too) |
1832 |
// Set caret to zero position upon document change (DefaultCaret impl does this too) |
1786 |
runTransaction(CaretTransaction.RemoveType.REMOVE_ALL_CARETS, 0, |
1833 |
runTransaction(CaretTransaction.RemoveType.REMOVE_ALL_CARETS, 0, |
1787 |
new CaretItem[] { new CaretItem(this, newDoc.getStartPosition(), null) }, null); |
1834 |
new CaretItem[] { new CaretItem(this, newDoc.getStartPosition(), Position.Bias.Forward, |
|
|
1835 |
null, Position.Bias.Forward ) }, null); |
1788 |
|
1836 |
|
1789 |
// Leave caretPos and markPos null => offset==0 |
1837 |
// Leave caretPos and markPos null => offset==0 |
1790 |
prefs = (mimeType != null) ? MimeLookup.getLookup(mimeType).lookup(Preferences.class) : null; |
1838 |
prefs = (mimeType != null) ? MimeLookup.getLookup(mimeType).lookup(Preferences.class) : null; |
Lines 2576-2582
Link Here
|
2576 |
try { |
2624 |
try { |
2577 |
Position pos = doc.createPosition(offset); |
2625 |
Position pos = doc.createPosition(offset); |
2578 |
runTransaction(CaretTransaction.RemoveType.NO_REMOVE, 0, |
2626 |
runTransaction(CaretTransaction.RemoveType.NO_REMOVE, 0, |
2579 |
new CaretItem[] { new CaretItem(EditorCaret.this, pos, pos) }, null); |
2627 |
new CaretItem[] { new CaretItem(EditorCaret.this, pos, Position.Bias.Forward, |
|
|
2628 |
pos, Position.Bias.Forward) }, null); |
2580 |
} catch (BadLocationException ex) { |
2629 |
} catch (BadLocationException ex) { |
2581 |
// Do nothing |
2630 |
// Do nothing |
2582 |
} |
2631 |
} |