1
0
Fork 0

fixed fast deleting deleting too many characters when there is a new line

This commit is contained in:
sspanak 2024-10-16 16:43:57 +03:00 committed by Dimo Karaivanov
parent 1e47bee232
commit d47528f550
2 changed files with 46 additions and 4 deletions

View file

@ -161,13 +161,13 @@ public class TextField extends InputField {
return 0;
}
String before = getStringBeforeCursor();
Text before = getTextBeforeCursor();
if (before.isEmpty()) {
return 0;
}
int spaceShift = Math.max(before.lastIndexOf(' '), 0);
return Math.min(before.length() - spaceShift, (int) (SettingsStore.BACKSPACE_ACCELERATION_MAX_CHARS * 1.5));
int whitespaceShift = Math.max(before.lastWhitespaceBlockIndex(), 0);
return Math.min(before.length() - whitespaceShift, (int) (SettingsStore.BACKSPACE_ACCELERATION_MAX_CHARS * 1.5));
}

View file

@ -11,16 +11,19 @@ public class Text extends TextTools {
private final Language language;
private final String text;
public Text(Language language, String text) {
this.language = language;
this.text = text;
}
public Text(String text) {
this.language = null;
this.text = text;
}
public String capitalize() {
if (language == null || text == null || text.isEmpty() || !language.hasUpperCase()) {
return text;
@ -32,11 +35,11 @@ public class Text extends TextTools {
}
public boolean endsWithGraphic() {
return text != null && !text.isEmpty() && Characters.isGraphic(text.charAt(text.length() - 1));
}
public int getTextCase() {
if (isUpperCase()) {
return InputMode.CASE_UPPER;
@ -49,6 +52,7 @@ public class Text extends TextTools {
}
}
public boolean isAlphabetic() {
for (int i = 0, end = text == null ? 0 : text.length(); i < end; i++) {
if (!Character.isAlphabetic(text.charAt(i))) {
@ -59,6 +63,7 @@ public class Text extends TextTools {
return true;
}
public boolean isNumeric() {
if (text == null) {
return false;
@ -73,10 +78,12 @@ public class Text extends TextTools {
return true;
}
public boolean isEmpty() {
return text == null || text.isEmpty();
}
private boolean isCapitalized() {
if (text == null || text.length() < 2) {
return false;
@ -95,6 +102,7 @@ public class Text extends TextTools {
return true;
}
public boolean isMixedCase() {
return
language != null
@ -103,10 +111,12 @@ public class Text extends TextTools {
&& !text.toUpperCase(language.getLocale()).equals(text);
}
public boolean isUpperCase() {
return language != null && text != null && text.toUpperCase(language.getLocale()).equals(text);
}
public String leaveEndingGraphics() {
if (text == null) {
return "";
@ -127,6 +137,7 @@ public class Text extends TextTools {
return sb.toString();
}
public String leaveStartingGraphics() {
if (text == null) {
return "";
@ -148,22 +159,49 @@ public class Text extends TextTools {
}
public int length() {
return text == null ? 0 : text.length();
}
public int lastWhitespaceBlockIndex() {
if (text == null) {
return -1;
}
for (int i = text.length() - 1; i >= 0; i--) {
if (
Character.isWhitespace(text.charAt(i))
&& (i == 0 || !Character.isWhitespace(text.charAt(i - 1)))
) {
return i;
}
}
return -1;
}
public boolean startsWithWhitespace() {
return text != null && !text.isEmpty() && Character.isWhitespace(text.charAt(0)) && !text.startsWith("\n");
}
public boolean startsWithNumber() {
return text != null && !text.isEmpty() && Character.isDigit(text.charAt(0));
}
public boolean startsWithGraphic() {
return text != null && !text.isEmpty() && Characters.isGraphic(text.charAt(0));
}
public boolean startsWithWord() {
return text != null && !text.isEmpty() && Character.isAlphabetic(text.charAt(0));
}
public String subStringEndingWord(boolean keepApostrophe, boolean keepQuote) {
if (text == null) {
return "";
@ -184,6 +222,7 @@ public class Text extends TextTools {
return sub.toString();
}
public String subStringStartingWord(boolean keepApostrophe, boolean keepQuote) {
if (text == null) {
return "";
@ -204,6 +243,7 @@ public class Text extends TextTools {
return sub.toString();
}
public String toLowerCase() {
if (text == null) {
return "";
@ -212,6 +252,7 @@ public class Text extends TextTools {
}
}
public String toUpperCase() {
if (text == null) {
return "";
@ -220,6 +261,7 @@ public class Text extends TextTools {
}
}
@NonNull
@Override
public String toString() {