EditField substring

So I am making a TextField class to update an old one. However, some code that worked fine before isn’t working now. I was wondering if anybody could help me figure out what is wrong.

Issue:

  • Every character can be deleted excepted for the first one

Code the handles input and updates the text.

Variables not shown:

StringBuilder input;
int pointer;
inputHandler.attach(new InputAdapter() {
			@Override
			public void key(int keycode) {
				boolean pointerShift = (keycode == 203) || (keycode == 205); // left arrow and right arrow
				if (keycode == 14 && input.length() > 0) { // delete key
					if (input.length() > 1) {
						input.deleteCharAt(Math.min(input.length() - 1, pointer - 1));
						pointer -= 1;
					}
				}
				else if (keycode == 211) {  // backspace key
					if (input.length() > 0 || pointer == 0) {
						input.deleteCharAt(Math.min(input.length() - 1, pointer));
					} else {
						input = new StringBuilder();
					}
				}
				else if (pointerShift) {
					if (keycode == 203)  // left arrow
						pointer = Math.max(0, pointer - 1);
					else  // right arrow
						pointer = Math.min(input.length(), pointer + 1);
				}
				else {
					input.insert(Math.max(0, Math.min(input.length(), pointer)), Keys.getLetter(keycode, inputHandler));  // regular key
					pointer += 1;
				}
			}
	}

Any help would be appreciated :slight_smile: