+ if (left()) {
+ del();
+ }
+ }
+
+ /**
+ * Insert a character at the cursor.
+ *
+ * @param ch the character to insert
+ */
+ public void addChar(final int ch) {
+ if (position < getDisplayLength() - 1) {
+ rawText.insert(position, Character.toChars(ch));
+ } else {
+ rawText.append(Character.toChars(ch));
+ }
+ position += Character.charCount(ch);
+ screenPosition += StringUtils.width(ch);
+ scanLine();
+ }
+
+ /**
+ * Replace a character at the cursor.
+ *
+ * @param ch the character to replace
+ */
+ public void replaceChar(final int ch) {
+ if (position < getDisplayLength() - 1) {
+ // Replace character
+ String oldText = rawText.toString();
+ rawText = new StringBuilder(oldText.substring(0, position));
+ rawText.append(Character.toChars(ch));
+ rawText.append(oldText.substring(position + 1));
+ screenPosition += StringUtils.width(rawText.codePointAt(position));
+ position += Character.charCount(ch);
+ } else {
+ rawText.append(Character.toChars(ch));
+ position += Character.charCount(ch);
+ screenPosition += StringUtils.width(ch);
+ }
+ scanLine();