git://git.nikiroo.be
/
fanfix.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'subtree'
[fanfix.git]
/
src
/
jexer
/
teditor
/
Word.java
diff --git
a/src/jexer/teditor/Word.java
b/src/jexer/teditor/Word.java
index ffb11aa1a520d9b37ca76eee98f776f9509794d9..483f9c3d86c46a1dfbf225876eb7b42c219ba0c1 100644
(file)
--- a/
src/jexer/teditor/Word.java
+++ b/
src/jexer/teditor/Word.java
@@
-29,6
+29,7
@@
package jexer.teditor;
import jexer.bits.CellAttributes;
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
/**
* A Word represents text that was entered by the user. It can be either
@@
-76,12
+77,12
@@
public class Word {
* @param defaultColor the color for unhighlighted text
* @param highlighter the highlighter to use
*/
* @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;
final Highlighter highlighter) {
this.defaultColor = defaultColor;
this.highlighter = highlighter;
- text.append(
ch
);
+ text.append(
Character.toChars(ch)
);
}
/**
}
/**
@@
-134,12
+135,7
@@
public class Word {
* @return the number of cells needed to display this word
*/
public int getDisplayLength() {
* @return the number of cells needed to display this word
*/
public int getDisplayLength() {
- // For now, just use the text length. In the future, this will be a
- // grapheme count.
-
- // 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());
}
/**
}
/**
@@
-184,9
+180,9
@@
public class Word {
* @return either this word (if it was added), or a new word that
* contains ch
*/
* @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) {
if (text.length() == 0) {
- text.append(
ch
);
+ text.append(
Character.toChars(ch)
);
return this;
}
return this;
}
@@
-205,14
+201,14
@@
public class Word {
&& Character.isWhitespace(ch)
) {
// Adding to a whitespace word, keep at it.
&& 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.
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;
}
return this;
}