1
0
Fork 0

redone the fast deletion logic

This commit is contained in:
sspanak 2024-10-23 13:14:28 +03:00 committed by Dimo Karaivanov
parent c8c7e1546f
commit 6189298e17
2 changed files with 15 additions and 7 deletions

View file

@ -161,7 +161,7 @@ public class TextField extends InputField {
return 0; return 0;
} }
int whitespaceShift = Math.max(before.lastWhitespaceBlockIndex(), 0); int whitespaceShift = Math.max(before.lastBoundaryIndex(), 0);
return Math.min(before.length() - whitespaceShift, (int) (SettingsStore.BACKSPACE_ACCELERATION_MAX_CHARS * 1.5)); return Math.min(before.length() - whitespaceShift, (int) (SettingsStore.BACKSPACE_ACCELERATION_MAX_CHARS * 1.5));
} }

View file

@ -164,21 +164,29 @@ public class Text extends TextTools {
} }
public int lastWhitespaceBlockIndex() { public int lastBoundaryIndex() {
if (text == null) { if (text == null || text.length() < 2) {
return -1; return -1;
} }
char lastChar = text.charAt(text.length() - 1);
char penultimateChar = text.charAt(text.length() - 2);
boolean endsWithWhitespaceBlock = Character.isWhitespace(lastChar) && Character.isWhitespace(penultimateChar);
boolean endsWithPunctuationBlock = (lastChar == '.' || lastChar == ',') && (penultimateChar == '.' || penultimateChar == ',');
for (int i = text.length() - 1; i >= 0; i--) { for (int i = text.length() - 1; i >= 0; i--) {
char currentChar = text.charAt(i);
if ( if (
Character.isWhitespace(text.charAt(i)) (endsWithPunctuationBlock && currentChar != '.' && currentChar != ',')
&& (i == 0 || !Character.isWhitespace(text.charAt(i - 1))) || (endsWithWhitespaceBlock && !Character.isWhitespace(currentChar))
|| (!endsWithWhitespaceBlock && !endsWithPunctuationBlock && (Character.isWhitespace(currentChar) || currentChar == '.' || currentChar == ','))
) { ) {
return i; return i + 1;
} }
} }
return -1; return 0;
} }