private void calculateDifferenceAndFire(String oldValue, String newValue, int cursorPos) { oldValue = interpreter.getValue() == null ? "" : interpreter.getValue(); tmpNativeCursor = Math.max(interpreter.getCursorPos(UUID.get()), 0); UndoableRemoteKeyPressEvent e = GWT.create(UndoableRemoteKeyPressEvent.class); if (oldValue.length() > newValue.length()) { // Deletion if (oldValue.length() - 1 == newValue.length()) { // One character removal if (cursorPos < tmpNativeCursor) // Backspace e.setKeyCode(KeyCodes.KEY_BACKSPACE); else // Delete e.setKeyCode(KeyCodes.KEY_DELETE); } else { // More complex deletion // TODO } } else if (newValue.length() > oldValue.length()) { // Insertion e.setText(String.valueOf(newValue.charAt(cursorPos - 1))); } else { e.setCursorPos(cursorPos - tmpNativeCursor); } RemoteTextBox.this.eventBus.fireEventFromSource(e, RemoteTextBox.this); }
private void updateState() { setValue(interpreter.getValue()); setCursorPos( Math.min( Math.max(interpreter.getCursorPos(UUID.get()), -1), interpreter.getValue().length())); }