) {
// Plain old keystroke, process it
// TODO: fix document to use ints, not chars
- document.addChar((char) keypress.getKey().getChar());
+ document.addChar(keypress.getKey().getChar());
alignCursor();
} else {
// Pass other keys (tab etc.) on to TWidget
*
* @param ch the character to replace or insert
*/
- public void addChar(final char ch) {
+ public void addChar(final int ch) {
dirty = true;
if (overwrite) {
lines.get(lineNumber).replaceChar(ch);
* @param ch the character
* @return true if the word should be split
*/
- public boolean shouldSplit(final char ch) {
+ public boolean shouldSplit(final int ch) {
// For now, split on punctuation
String punctuation = "'\"\\<>{}[]!@#$%^&*();:.,-+/*?";
- if (punctuation.indexOf(ch) != -1) {
- return true;
+ if (ch < 0x100) {
+ if (punctuation.indexOf((char) ch) != -1) {
+ return true;
+ }
}
return false;
}
import java.util.List;
import jexer.bits.CellAttributes;
+import jexer.bits.StringUtils;
/**
* A Line represents a single line of text on the screen, as a collection of
* @return the number of cells needed to display this line
*/
public int getDisplayLength() {
- int n = rawText.length();
+ int n = StringUtils.width(rawText.toString());
// For now just return the raw text length.
if (n > 0) {
words.clear();
Word word = new Word(this.defaultColor, this.highlighter);
words.add(word);
- for (int i = 0; i < rawText.length(); i++) {
- char ch = rawText.charAt(i);
+ for (int i = 0; i < rawText.length();) {
+ int ch = rawText.codePointAt(i);
+ i += Character.charCount(ch);
Word newWord = word.addChar(ch);
if (newWord != word) {
words.add(newWord);
if (cursor == 0) {
return false;
}
- cursor--;
+ cursor -= StringUtils.width(rawText.codePointAt(cursor - 1));
return true;
}
if (cursor == getDisplayLength() - 1) {
return false;
}
- cursor++;
+ if (cursor < getDisplayLength()) {
+ cursor += StringUtils.width(rawText.codePointAt(cursor));
+ } else {
+ cursor++;
+ }
return true;
}
assert (words.size() > 0);
if (cursor < getDisplayLength()) {
- rawText.deleteCharAt(cursor);
+ for (int i = 0; i < Character.charCount(rawText.charAt(cursor)); i++) {
+ rawText.deleteCharAt(cursor);
+ }
}
// Re-scan the line to determine the new word boundaries.
*
* @param ch the character to insert
*/
- public void addChar(final char ch) {
+ public void addChar(final int ch) {
if (cursor < getDisplayLength() - 1) {
- rawText.insert(cursor, ch);
+ rawText.insert(cursor, Character.toChars(ch));
} else {
- rawText.append(ch);
+ rawText.append(Character.toChars(ch));
}
scanLine();
cursor++;
*
* @param ch the character to replace
*/
- public void replaceChar(final char ch) {
+ public void replaceChar(final int ch) {
if (cursor < getDisplayLength() - 1) {
- rawText.setCharAt(cursor, ch);
+ for (int i = 0; i < Character.charCount(rawText.charAt(cursor)); i++) {
+ rawText.deleteCharAt(cursor);
+ }
+ rawText.insert(cursor, Character.toChars(ch));
} else {
- rawText.append(ch);
+ rawText.append(Character.toChars(ch));
}
scanLine();
cursor++;
package jexer.teditor;
import jexer.bits.CellAttributes;
+import jexer.bits.StringUtils;
/**
* A Word represents text that was entered by the user. It can be either
* @param defaultColor the color for unhighlighted text
* @param highlighter the highlighter to use
*/
- public Word(final char ch, final CellAttributes defaultColor,
+ public Word(final int ch, final CellAttributes defaultColor,
final Highlighter highlighter) {
this.defaultColor = defaultColor;
this.highlighter = highlighter;
- text.append(ch);
+ text.append(Character.toChars(ch));
}
/**
// TODO: figure out how to handle the tab character. Do we have a
// global tab stops list and current word position?
- return text.length();
+ return StringUtils.width(text.toString());
}
/**
* @return either this word (if it was added), or a new word that
* contains ch
*/
- public Word addChar(final char ch) {
+ public Word addChar(final int ch) {
if (text.length() == 0) {
- text.append(ch);
+ text.append(Character.toChars(ch));
return this;
}
&& Character.isWhitespace(ch)
) {
// Adding to a whitespace word, keep at it.
- text.append(ch);
+ text.append(Character.toChars(ch));
return this;
}
if (!Character.isWhitespace(text.charAt(0))
&& !Character.isWhitespace(ch)
) {
// Adding to a non-whitespace word, keep at it.
- text.append(ch);
+ text.append(Character.toChars(ch));
return this;
}