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;
}
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));
}

View file

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