Skip to content

Commit

Permalink
Fix #34.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasMikula committed Apr 18, 2014
1 parent 71fc850 commit 74f3a25
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ public void setStyle(int from, int to, S style) {

try(Hold commitOnClose = beginStyleChange(from, to)) {
Position start = navigator.offsetToPosition(from, Forward);
Position end = start.offsetBy(to - from, Backward);
Position end = to == from
? start
: start.offsetBy(to - from, Backward);
int firstParIdx = start.getMajor();
int firstParFrom = start.getMinor();
int lastParIdx = end.getMajor();
Expand Down Expand Up @@ -246,7 +248,9 @@ public void setStyleSpans(int from, StyleSpans<? extends S> styleSpans) {
int len = styleSpans.length();
try(Hold commitOnClose = beginStyleChange(from, from + len)) {
Position start = offsetToPosition(from, Forward);
Position end = start.offsetBy(len, Backward);
Position end = len == 0
? start
: start.offsetBy(len, Backward);
int firstParIdx = start.getMajor();
int firstParFrom = start.getMinor();
int lastParIdx = end.getMajor();
Expand Down Expand Up @@ -444,4 +448,4 @@ private S getStyleForInsertionAt(Position insertionPos) {
Paragraph<S> par = paragraphs.get(insertionPos.getMajor());
return par.getStyleAtPosition(insertionPos.getMinor());
}
}
}
4 changes: 3 additions & 1 deletion richtextfx/src/main/java/org/fxmisc/richtext/Paragraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ public StyleSpans<S> getStyleRanges() {

public StyleSpans<S> getStyleRanges(int from, int to) {
Position start = navigator.offsetToPosition(from, Forward);
Position end = start.offsetBy(to - from, Backward);
Position end = to == from
? start
: start.offsetBy(to - from, Backward);
int startSegIdx = start.getMajor();
int endSegIdx = end.getMajor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ public IndexRange getStyleRangeAtPosition(int paragraph, int position) {
@Override
public StyleSpans<S> getStyleSpans(int from, int to) {
Position start = offsetToPosition(from, Forward);
Position end = start.offsetBy(to - from, Backward);
Position end = to == from
? start
: start.offsetBy(to - from, Backward);
int startParIdx = start.getMajor();
int endParIdx = end.getMajor();

Expand Down Expand Up @@ -220,10 +222,10 @@ private <P, R> R sub(
SubMap<Paragraph<S>, P> subMap,
Function<List<P>, R> combine) {

int length = end - start;

Position start2D = navigator.offsetToPosition(start, Forward);
Position end2D = start2D.offsetBy(length, Backward);
Position end2D = end == start
? start2D
: start2D.offsetBy(end - start, Backward);
int p1 = start2D.getMajor();
int col1 = start2D.getMinor();
int p2 = end2D.getMajor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ public <C> StyledTextArea(S initialStyle, BiConsumer<Text, S> applyStyle,
internalSelection.addListener(obs -> {
IndexRange sel = internalSelection.get();
selectionStart2D = offsetToPosition(sel.getStart(), Forward);
selectionEnd2D = selectionStart2D.offsetBy(sel.getLength(), Backward);
selectionEnd2D = sel.getLength() == 0
? selectionStart2D
: selectionStart2D.offsetBy(sel.getLength(), Backward);
});
internalSelection.set(EMPTY_RANGE);

Expand Down

0 comments on commit 74f3a25

Please sign in to comment.