git://git.nikiroo.be
/
fanfix.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3fe82fa
)
#35 fix crash
author
Kevin Lamonte
<kevin.lamonte@gmail.com>
Wed, 14 Aug 2019 00:08:11 +0000
(19:08 -0500)
committer
Kevin Lamonte
<kevin.lamonte@gmail.com>
Wed, 14 Aug 2019 00:08:11 +0000
(19:08 -0500)
src/jexer/TField.java
patch
|
blob
|
blame
|
history
diff --git
a/src/jexer/TField.java
b/src/jexer/TField.java
index 3d727ea17ce1d19003646ec6091570e6173bb860..0a99840db7f06d9aadff53e6fa11aa35520472ee 100644
(file)
--- a/
src/jexer/TField.java
+++ b/
src/jexer/TField.java
@@
-220,7
+220,7
@@
public class TField extends TWidget {
if (keypress.equals(kbLeft)) {
if (position > 0) {
if (position < text.length()) {
if (keypress.equals(kbLeft)) {
if (position > 0) {
if (position < text.length()) {
- screenPosition -= StringUtils.width(text.c
har
At(position));
+ screenPosition -= StringUtils.width(text.c
odePoint
At(position));
} else {
screenPosition--;
}
} else {
screenPosition--;
}
@@
-228,7
+228,7
@@
public class TField extends TWidget {
}
if (fixed == false) {
if ((screenPosition == windowStart) && (windowStart > 0)) {
}
if (fixed == false) {
if ((screenPosition == windowStart) && (windowStart > 0)) {
- windowStart -= StringUtils.width(text.c
har
At(
+ windowStart -= StringUtils.width(text.c
odePoint
At(
screenToTextPosition(windowStart)));
}
}
screenToTextPosition(windowStart)));
}
}
@@
-238,7
+238,7
@@
public class TField extends TWidget {
if (keypress.equals(kbRight)) {
if (position < text.length()) {
if (keypress.equals(kbRight)) {
if (position < text.length()) {
- screenPosition += StringUtils.width(text.c
har
At(position));
+ screenPosition += StringUtils.width(text.c
odePoint
At(position));
position++;
if (fixed == true) {
if (screenPosition == getWidth()) {
position++;
if (fixed == true) {
if (screenPosition == getWidth()) {
@@
-247,7
+247,7
@@
public class TField extends TWidget {
}
} else {
if ((screenPosition - windowStart) >= getWidth()) {
}
} else {
if ((screenPosition - windowStart) >= getWidth()) {
- windowStart += StringUtils.width(text.c
har
At(
+ windowStart += StringUtils.width(text.c
odePoint
At(
screenToTextPosition(windowStart)));
}
}
screenToTextPosition(windowStart)));
}
}
@@
-295,7
+295,7
@@
public class TField extends TWidget {
if ((screenPosition >= windowStart)
&& (windowStart > 0)
) {
if ((screenPosition >= windowStart)
&& (windowStart > 0)
) {
- windowStart -= StringUtils.width(text.c
har
At(
+ windowStart -= StringUtils.width(text.c
odePoint
At(
screenToTextPosition(windowStart)));
}
}
screenToTextPosition(windowStart)));
}
}
@@
-321,10
+321,10
@@
public class TField extends TWidget {
if (insertMode == false) {
// Replace character
text = text.substring(0, position)
if (insertMode == false) {
// Replace character
text = text.substring(0, position)
- +
keypress.getKey().getChar(
)
+ +
codePointString(keypress.getKey().getChar()
)
+ text.substring(position + 1);
+ text.substring(position + 1);
- screenPosition += StringUtils.width(text.c
har
At(position));
- position
++
;
+ screenPosition += StringUtils.width(text.c
odePoint
At(position));
+ position
+= Character.charCount(keypress.getKey().getChar())
;
} else {
// Insert character
insertChar(keypress.getKey().getChar());
} else {
// Insert character
insertChar(keypress.getKey().getChar());
@@
-338,19
+338,19
@@
public class TField extends TWidget {
} else if ((fixed == true) && (insertMode == false)) {
// Overwrite the last character, maybe move position
text = text.substring(0, position)
} else if ((fixed == true) && (insertMode == false)) {
// Overwrite the last character, maybe move position
text = text.substring(0, position)
- +
keypress.getKey().getChar(
)
+ +
codePointString(keypress.getKey().getChar()
)
+ text.substring(position + 1);
if (screenPosition < getWidth() - 1) {
+ text.substring(position + 1);
if (screenPosition < getWidth() - 1) {
- screenPosition += StringUtils.width(text.c
har
At(position));
- position
++
;
+ screenPosition += StringUtils.width(text.c
odePoint
At(position));
+ position
+= Character.charCount(keypress.getKey().getChar())
;
}
} else if ((fixed == false) && (insertMode == false)) {
// Overwrite the last character, definitely move position
text = text.substring(0, position)
}
} else if ((fixed == false) && (insertMode == false)) {
// Overwrite the last character, definitely move position
text = text.substring(0, position)
- +
keypress.getKey().getChar(
)
+ +
codePointString(keypress.getKey().getChar()
)
+ text.substring(position + 1);
+ text.substring(position + 1);
- screenPosition += StringUtils.width(text.c
har
At(position));
- position
++
;
+ screenPosition += StringUtils.width(text.c
odePoint
At(position));
+ position
+= Character.charCount(keypress.getKey().getChar())
;
} else {
if (position == text.length()) {
// Append this character
} else {
if (position == text.length()) {
// Append this character
@@
-407,6
+407,18
@@
public class TField extends TWidget {
// TField -----------------------------------------------------------------
// ------------------------------------------------------------------------
// TField -----------------------------------------------------------------
// ------------------------------------------------------------------------
+ /**
+ * Convert a char (codepoint) to a string.
+ *
+ * @param ch the char
+ * @return the string
+ */
+ private String codePointString(final int ch) {
+ StringBuilder sb = new StringBuilder(1);
+ sb.append(Character.toChars(ch));
+ return sb.toString();
+ }
+
/**
* Get field background character.
*
/**
* Get field background character.
*
@@
-477,7
+489,7
@@
public class TField extends TWidget {
int n = 0;
for (int i = 0; i < text.length(); i++) {
int n = 0;
for (int i = 0; i < text.length(); i++) {
- n += StringUtils.width(text.c
har
At(i));
+ n += StringUtils.width(text.c
odePoint
At(i));
if (n >= screenPosition) {
return i + 1;
}
if (n >= screenPosition) {
return i + 1;
}
@@
-525,15
+537,15
@@
public class TField extends TWidget {
*/
protected void appendChar(final int ch) {
// Append the LAST character
*/
protected void appendChar(final int ch) {
// Append the LAST character
- text += c
h
;
- position
++
;
+ text += c
odePointString(ch)
;
+ position
+= Character.charCount(ch)
;
screenPosition += StringUtils.width(ch);
assert (position == text.length());
if (fixed) {
if (screenPosition >= getWidth()) {
screenPosition += StringUtils.width(ch);
assert (position == text.length());
if (fixed) {
if (screenPosition >= getWidth()) {
- position
--
;
+ position
-= Character.charCount(ch)
;
screenPosition -= StringUtils.width(ch);
}
} else {
screenPosition -= StringUtils.width(ch);
}
} else {
@@
-549,8
+561,9
@@
public class TField extends TWidget {
* @param ch char to append
*/
protected void insertChar(final int ch) {
* @param ch char to append
*/
protected void insertChar(final int ch) {
- text = text.substring(0, position) + ((char) ch) + text.substring(position);
- position++;
+ text = text.substring(0, position) + codePointString(ch)
+ + text.substring(position);
+ position += Character.charCount(ch);
screenPosition += StringUtils.width(ch);
if ((screenPosition - windowStart) == getWidth()) {
assert (!fixed);
screenPosition += StringUtils.width(ch);
if ((screenPosition - windowStart) == getWidth()) {
assert (!fixed);