Skip to content

Commit

Permalink
Add ctrl+backspace/del in TextField
Browse files Browse the repository at this point in the history
  • Loading branch information
zxtej committed Oct 20, 2024
1 parent 4cf4c4c commit a68d566
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions arc-core/src/arc/scene/ui/TextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,11 @@ protected void moveCursor(boolean forward, boolean jump){
int limit = forward ? text.length() : 0;
int charOffset = forward ? 0 : -1;
while((forward ? ++cursor < limit : --cursor > limit) && jump){
if(!continueCursor(cursor, charOffset)) break;
if(forward != continueCursor(cursor, charOffset)) break;
}
if(!jump || (forward && cursor >= limit) || (!forward && cursor <= limit)) return;
while((forward ? ++cursor < limit : --cursor > limit)){
if(forward == continueCursor(cursor, charOffset)) break;
}
}

Expand Down Expand Up @@ -1133,12 +1137,17 @@ public boolean keyTyped(InputEvent event, char character){
if(hasSelection)
cursor = delete(false);
else{
boolean ctrl = Core.input.ctrl() && !Core.input.alt();
boolean jump = ctrl && !passwordMode;
if(backspace && cursor > 0){
text = text.substring(0, cursor - 1) + text.substring(cursor--);
moveCursor(false, jump);
text = text.substring(0, cursor) + text.substring(oldCursor);
renderOffset = 0;
}
if(delete && cursor < text.length()){
text = text.substring(0, cursor) + text.substring(cursor + 1);
moveCursor(true, jump);
text = text.substring(0, oldCursor) + text.substring(cursor);
cursor = oldCursor;
}
}
if(add && !remove){
Expand Down

0 comments on commit a68d566

Please sign in to comment.