am e0b108cd: am 21417a0d: Merge "Text selection: Fix moving by character when should move by word" into mnc-dev
* commit 'e0b108cd951f3b6db13b562a5035f22fa1cbd961': Text selection: Fix moving by character when should move by word
This commit is contained in:
@@ -3913,10 +3913,20 @@ public class Editor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePosition(float x, float y) {
|
public void updatePosition(float x, float y) {
|
||||||
final int trueOffset = mTextView.getOffsetForPosition(x, y);
|
final int selectionEnd = mTextView.getSelectionEnd();
|
||||||
final int currLine = mTextView.getLineAtCoordinate(y);
|
final Layout layout = mTextView.getLayout();
|
||||||
|
int initialOffset = mTextView.getOffsetForPosition(x, y);
|
||||||
|
int currLine = mTextView.getLineAtCoordinate(y);
|
||||||
boolean positionCursor = false;
|
boolean positionCursor = false;
|
||||||
int offset = trueOffset;
|
|
||||||
|
if (initialOffset >= selectionEnd) {
|
||||||
|
// Handles have crossed, bound it to the last selected line and
|
||||||
|
// adjust by word / char as normal.
|
||||||
|
currLine = layout != null ? layout.getLineForOffset(selectionEnd) : mPrevLine;
|
||||||
|
initialOffset = mTextView.getOffsetAtCoordinate(currLine, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int offset = initialOffset;
|
||||||
int end = getWordEnd(offset);
|
int end = getWordEnd(offset);
|
||||||
int start = getWordStart(offset);
|
int start = getWordStart(offset);
|
||||||
|
|
||||||
@@ -3932,8 +3942,7 @@ public class Editor {
|
|||||||
offset = mPreviousOffset;
|
offset = mPreviousOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Layout layout = mTextView.getLayout();
|
if (layout != null && offset < initialOffset) {
|
||||||
if (layout != null && offset < trueOffset) {
|
|
||||||
final float adjustedX = layout.getPrimaryHorizontal(offset);
|
final float adjustedX = layout.getPrimaryHorizontal(offset);
|
||||||
mTouchWordDelta =
|
mTouchWordDelta =
|
||||||
mTextView.convertToLocalHorizontalCoordinate(x) - adjustedX;
|
mTextView.convertToLocalHorizontalCoordinate(x) - adjustedX;
|
||||||
@@ -3949,8 +3958,7 @@ public class Editor {
|
|||||||
if (currLine > mPrevLine) {
|
if (currLine > mPrevLine) {
|
||||||
// We're on a different line, so we'll snap to word boundaries.
|
// We're on a different line, so we'll snap to word boundaries.
|
||||||
offset = start;
|
offset = start;
|
||||||
final Layout layout = mTextView.getLayout();
|
if (layout != null && offset < initialOffset) {
|
||||||
if (layout != null && offset < trueOffset) {
|
|
||||||
final float adjustedX = layout.getPrimaryHorizontal(offset);
|
final float adjustedX = layout.getPrimaryHorizontal(offset);
|
||||||
mTouchWordDelta =
|
mTouchWordDelta =
|
||||||
mTextView.convertToLocalHorizontalCoordinate(x) - adjustedX;
|
mTextView.convertToLocalHorizontalCoordinate(x) - adjustedX;
|
||||||
@@ -3964,18 +3972,10 @@ public class Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles can not cross and selection is at least one character.
|
|
||||||
if (positionCursor) {
|
if (positionCursor) {
|
||||||
final int selectionEnd = mTextView.getSelectionEnd();
|
// Handles can not cross and selection is at least one character.
|
||||||
if (offset >= selectionEnd) {
|
if (offset >= selectionEnd) {
|
||||||
// We can't cross the handles so let's just constrain the Y value.
|
offset = getNextCursorOffset(selectionEnd, false);
|
||||||
int alteredOffset = mTextView.getOffsetAtCoordinate(mPrevLine, x);
|
|
||||||
if (alteredOffset >= selectionEnd) {
|
|
||||||
// Can't pass the other drag handle.
|
|
||||||
offset = getNextCursorOffset(selectionEnd, false);
|
|
||||||
} else {
|
|
||||||
offset = alteredOffset;
|
|
||||||
}
|
|
||||||
mTouchWordDelta = 0.0f;
|
mTouchWordDelta = 0.0f;
|
||||||
}
|
}
|
||||||
mInWord = !getWordIteratorWithText().isBoundary(offset);
|
mInWord = !getWordIteratorWithText().isBoundary(offset);
|
||||||
@@ -4031,10 +4031,20 @@ public class Editor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePosition(float x, float y) {
|
public void updatePosition(float x, float y) {
|
||||||
final int trueOffset = mTextView.getOffsetForPosition(x, y);
|
final int selectionStart = mTextView.getSelectionStart();
|
||||||
final int currLine = mTextView.getLineAtCoordinate(y);
|
final Layout layout = mTextView.getLayout();
|
||||||
int offset = trueOffset;
|
int initialOffset = mTextView.getOffsetForPosition(x, y);
|
||||||
|
int currLine = mTextView.getLineAtCoordinate(y);
|
||||||
boolean positionCursor = false;
|
boolean positionCursor = false;
|
||||||
|
|
||||||
|
if (initialOffset <= selectionStart) {
|
||||||
|
// Handles have crossed, bound it to the first selected line and
|
||||||
|
// adjust by word / char as normal.
|
||||||
|
currLine = layout != null ? layout.getLineForOffset(selectionStart) : mPrevLine;
|
||||||
|
initialOffset = mTextView.getOffsetAtCoordinate(currLine, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int offset = initialOffset;
|
||||||
int end = getWordEnd(offset);
|
int end = getWordEnd(offset);
|
||||||
int start = getWordStart(offset);
|
int start = getWordStart(offset);
|
||||||
|
|
||||||
@@ -4050,8 +4060,7 @@ public class Editor {
|
|||||||
offset = mPreviousOffset;
|
offset = mPreviousOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Layout layout = mTextView.getLayout();
|
if (layout != null && offset > initialOffset) {
|
||||||
if (layout != null && offset > trueOffset) {
|
|
||||||
final float adjustedX = layout.getPrimaryHorizontal(offset);
|
final float adjustedX = layout.getPrimaryHorizontal(offset);
|
||||||
mTouchWordDelta =
|
mTouchWordDelta =
|
||||||
adjustedX - mTextView.convertToLocalHorizontalCoordinate(x);
|
adjustedX - mTextView.convertToLocalHorizontalCoordinate(x);
|
||||||
@@ -4067,8 +4076,7 @@ public class Editor {
|
|||||||
if (currLine < mPrevLine) {
|
if (currLine < mPrevLine) {
|
||||||
// We're on a different line, so we'll snap to word boundaries.
|
// We're on a different line, so we'll snap to word boundaries.
|
||||||
offset = end;
|
offset = end;
|
||||||
final Layout layout = mTextView.getLayout();
|
if (layout != null && offset > initialOffset) {
|
||||||
if (layout != null && offset > trueOffset) {
|
|
||||||
final float adjustedX = layout.getPrimaryHorizontal(offset);
|
final float adjustedX = layout.getPrimaryHorizontal(offset);
|
||||||
mTouchWordDelta =
|
mTouchWordDelta =
|
||||||
adjustedX - mTextView.convertToLocalHorizontalCoordinate(x);
|
adjustedX - mTextView.convertToLocalHorizontalCoordinate(x);
|
||||||
@@ -4083,17 +4091,9 @@ public class Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (positionCursor) {
|
if (positionCursor) {
|
||||||
final int selectionStart = mTextView.getSelectionStart();
|
// Handles can not cross and selection is at least one character.
|
||||||
if (offset <= selectionStart) {
|
if (offset <= selectionStart) {
|
||||||
// We can't cross the handles so let's just constrain the Y value.
|
offset = getNextCursorOffset(selectionStart, true);
|
||||||
int alteredOffset = mTextView.getOffsetAtCoordinate(mPrevLine, x);
|
|
||||||
int length = mTextView.getText().length();
|
|
||||||
if (alteredOffset <= selectionStart) {
|
|
||||||
// Can't pass the other drag handle.
|
|
||||||
offset = getNextCursorOffset(selectionStart, true);
|
|
||||||
} else {
|
|
||||||
offset = Math.min(alteredOffset, length);
|
|
||||||
}
|
|
||||||
mTouchWordDelta = 0.0f;
|
mTouchWordDelta = 0.0f;
|
||||||
}
|
}
|
||||||
mInWord = !getWordIteratorWithText().isBoundary(offset);
|
mInWord = !getWordIteratorWithText().isBoundary(offset);
|
||||||
|
|||||||
Reference in New Issue
Block a user