Merge "Delete CR LF at the same time with one backspace key." into nyc-dev
This commit is contained in:
@@ -48,6 +48,9 @@ public abstract class BaseKeyListener extends MetaKeyKeyListener
|
|||||||
implements KeyListener {
|
implements KeyListener {
|
||||||
/* package */ static final Object OLD_SEL_START = new NoCopySpan.Concrete();
|
/* package */ static final Object OLD_SEL_START = new NoCopySpan.Concrete();
|
||||||
|
|
||||||
|
private static final int LINE_FEED = 0x0A;
|
||||||
|
private static final int CARRIAGE_RETURN = 0x0D;
|
||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
@@ -110,34 +113,37 @@ public abstract class BaseKeyListener extends MetaKeyKeyListener
|
|||||||
// Initial state
|
// Initial state
|
||||||
final int STATE_START = 0;
|
final int STATE_START = 0;
|
||||||
|
|
||||||
|
// The offset is immediately before line feed.
|
||||||
|
final int STATE_LF = 1;
|
||||||
|
|
||||||
// The offset is immediately before a KEYCAP.
|
// The offset is immediately before a KEYCAP.
|
||||||
final int STATE_BEFORE_KEYCAP = 1;
|
final int STATE_BEFORE_KEYCAP = 2;
|
||||||
// The offset is immediately before a variation selector and a KEYCAP.
|
// The offset is immediately before a variation selector and a KEYCAP.
|
||||||
final int STATE_BEFORE_VS_AND_KEYCAP = 2;
|
final int STATE_BEFORE_VS_AND_KEYCAP = 3;
|
||||||
|
|
||||||
// The offset is immediately before an emoji modifier.
|
// The offset is immediately before an emoji modifier.
|
||||||
final int STATE_BEFORE_EMOJI_MODIFIER = 3;
|
final int STATE_BEFORE_EMOJI_MODIFIER = 4;
|
||||||
// The offset is immediately before a variation selector and an emoji modifier.
|
// The offset is immediately before a variation selector and an emoji modifier.
|
||||||
final int STATE_BEFORE_VS_AND_EMOJI_MODIFIER = 4;
|
final int STATE_BEFORE_VS_AND_EMOJI_MODIFIER = 5;
|
||||||
|
|
||||||
// The offset is immediately before a variation selector.
|
// The offset is immediately before a variation selector.
|
||||||
final int STATE_BEFORE_VS = 5;
|
final int STATE_BEFORE_VS = 6;
|
||||||
|
|
||||||
// The offset is immediately before a ZWJ emoji.
|
// The offset is immediately before a ZWJ emoji.
|
||||||
final int STATE_BEFORE_ZWJ_EMOJI = 6;
|
final int STATE_BEFORE_ZWJ_EMOJI = 7;
|
||||||
// The offset is immediately before a ZWJ that were seen before a ZWJ emoji.
|
// The offset is immediately before a ZWJ that were seen before a ZWJ emoji.
|
||||||
final int STATE_BEFORE_ZWJ = 7;
|
final int STATE_BEFORE_ZWJ = 8;
|
||||||
// The offset is immediately before a variation selector and a ZWJ that were seen before a
|
// The offset is immediately before a variation selector and a ZWJ that were seen before a
|
||||||
// ZWJ emoji.
|
// ZWJ emoji.
|
||||||
final int STATE_BEFORE_VS_AND_ZWJ = 8;
|
final int STATE_BEFORE_VS_AND_ZWJ = 9;
|
||||||
|
|
||||||
// The number of following RIS code points is odd.
|
// The number of following RIS code points is odd.
|
||||||
final int STATE_ODD_NUMBERED_RIS = 9;
|
final int STATE_ODD_NUMBERED_RIS = 10;
|
||||||
// The number of following RIS code points is even.
|
// The number of following RIS code points is even.
|
||||||
final int STATE_EVEN_NUMBERED_RIS = 10;
|
final int STATE_EVEN_NUMBERED_RIS = 11;
|
||||||
|
|
||||||
// The state machine has been stopped.
|
// The state machine has been stopped.
|
||||||
final int STATE_FINISHED = 11;
|
final int STATE_FINISHED = 12;
|
||||||
|
|
||||||
int deleteCharCount = 0; // Char count to be deleted by backspace.
|
int deleteCharCount = 0; // Char count to be deleted by backspace.
|
||||||
int lastSeenVSCharCount = 0; // Char count of previous variation selector.
|
int lastSeenVSCharCount = 0; // Char count of previous variation selector.
|
||||||
@@ -152,7 +158,9 @@ public abstract class BaseKeyListener extends MetaKeyKeyListener
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
case STATE_START:
|
case STATE_START:
|
||||||
deleteCharCount = Character.charCount(codePoint);
|
deleteCharCount = Character.charCount(codePoint);
|
||||||
if (isVariationSelector(codePoint)) {
|
if (codePoint == LINE_FEED) {
|
||||||
|
state = STATE_LF;
|
||||||
|
} else if (isVariationSelector(codePoint)) {
|
||||||
state = STATE_BEFORE_VS;
|
state = STATE_BEFORE_VS;
|
||||||
} else if (Emoji.isZwjEmoji(codePoint)) {
|
} else if (Emoji.isZwjEmoji(codePoint)) {
|
||||||
state = STATE_BEFORE_ZWJ_EMOJI;
|
state = STATE_BEFORE_ZWJ_EMOJI;
|
||||||
@@ -166,6 +174,11 @@ public abstract class BaseKeyListener extends MetaKeyKeyListener
|
|||||||
state = STATE_FINISHED;
|
state = STATE_FINISHED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case STATE_LF:
|
||||||
|
if (codePoint == CARRIAGE_RETURN) {
|
||||||
|
++deleteCharCount;
|
||||||
|
}
|
||||||
|
state = STATE_FINISHED;
|
||||||
case STATE_ODD_NUMBERED_RIS:
|
case STATE_ODD_NUMBERED_RIS:
|
||||||
if (Emoji.isRegionalIndicatorSymbol(codePoint)) {
|
if (Emoji.isRegionalIndicatorSymbol(codePoint)) {
|
||||||
deleteCharCount += 2; /* Char count of RIS */
|
deleteCharCount += 2; /* Char count of RIS */
|
||||||
|
|||||||
Reference in New Issue
Block a user