fixed again Backspace swiping deleting too many characters
This commit is contained in:
parent
3a2d805b24
commit
45285828e0
2 changed files with 21 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package io.github.sspanak.tt9.ui.main.keys;
|
package io.github.sspanak.tt9.ui.main.keys;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
|
@ -11,6 +12,7 @@ import io.github.sspanak.tt9.ui.Vibration;
|
||||||
|
|
||||||
public class SoftKeyBackspace extends SwipeableKey {
|
public class SoftKeyBackspace extends SwipeableKey {
|
||||||
private int repeat = 0;
|
private int repeat = 0;
|
||||||
|
private final Handler waitForSwipe = new Handler();
|
||||||
|
|
||||||
public SoftKeyBackspace(Context context) {
|
public SoftKeyBackspace(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
@ -61,7 +63,15 @@ public class SoftKeyBackspace extends SwipeableKey {
|
||||||
@Override
|
@Override
|
||||||
final protected boolean handlePress() {
|
final protected boolean handlePress() {
|
||||||
super.handlePress();
|
super.handlePress();
|
||||||
return deleteText();
|
waitForSwipe.postDelayed(this::handlePressDebounced, 15);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void handlePressDebounced() {
|
||||||
|
if (notSwiped()) {
|
||||||
|
deleteText();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -80,6 +90,12 @@ public class SoftKeyBackspace extends SwipeableKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleStartSwipeX(float position, float delta) {
|
||||||
|
waitForSwipe.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleEndSwipeX(float position, float delta) {
|
protected void handleEndSwipeX(float position, float delta) {
|
||||||
if (validateTT9Handler()) {
|
if (validateTT9Handler()) {
|
||||||
|
|
@ -88,16 +104,13 @@ public class SoftKeyBackspace extends SwipeableKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean deleteText() {
|
private void deleteText() {
|
||||||
if (validateTT9Handler() && !tt9.onBackspace(repeat)) {
|
if (validateTT9Handler() && !tt9.onBackspace(repeat)) {
|
||||||
// Limited or special numeric field (e.g. formatted money or dates) cannot always return
|
// Limited or special numeric field (e.g. formatted money or dates) cannot always return
|
||||||
// the text length, therefore onBackspace() seems them as empty and does nothing. This results
|
// the text length, therefore onBackspace() seems them as empty and does nothing. This results
|
||||||
// in fallback to the default hardware key action. Here we simulate the hardware BACKSPACE.
|
// in fallback to the default hardware key action. Here we simulate the hardware BACKSPACE.
|
||||||
tt9.sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
tt9.sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -175,12 +175,13 @@ public class Text extends TextTools {
|
||||||
boolean endsWithWhitespaceBlock = Character.isWhitespace(lastChar) && Character.isWhitespace(penultimateChar);
|
boolean endsWithWhitespaceBlock = Character.isWhitespace(lastChar) && Character.isWhitespace(penultimateChar);
|
||||||
boolean endsWithPunctuationBlock = (lastChar == '.' || lastChar == ',') && (penultimateChar == '.' || penultimateChar == ',');
|
boolean endsWithPunctuationBlock = (lastChar == '.' || lastChar == ',') && (penultimateChar == '.' || penultimateChar == ',');
|
||||||
|
|
||||||
for (int i = text.length() - 1; i >= 0; i--) {
|
for (int i = text.length() - 1, firstChar = 1; i >= 0; i--, firstChar = 0) {
|
||||||
char currentChar = text.charAt(i);
|
char currentChar = text.charAt(i);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(endsWithPunctuationBlock && currentChar != '.' && currentChar != ',')
|
(endsWithPunctuationBlock && currentChar != '.' && currentChar != ',')
|
||||||
|| (endsWithWhitespaceBlock && !Character.isWhitespace(currentChar))
|
|| (endsWithWhitespaceBlock && !Character.isWhitespace(currentChar))
|
||||||
|| (!endsWithWhitespaceBlock && !endsWithPunctuationBlock && (Character.isWhitespace(currentChar) || currentChar == '.' || currentChar == ','))
|
|| (!endsWithWhitespaceBlock && !endsWithPunctuationBlock && firstChar == 0 && Character.isWhitespace(currentChar))
|
||||||
) {
|
) {
|
||||||
return i + 1;
|
return i + 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue