diff --git a/terminal/src/main/java/org/jline/utils/AttributedCharSequence.java b/terminal/src/main/java/org/jline/utils/AttributedCharSequence.java index 540110112..950539be5 100644 --- a/terminal/src/main/java/org/jline/utils/AttributedCharSequence.java +++ b/terminal/src/main/java/org/jline/utils/AttributedCharSequence.java @@ -293,7 +293,7 @@ public AttributedString columnSubSequence(int start, int stop) { if (col + w > start) { break; } - begin++; + begin += Character.charCount(cp); col += w; } int end = begin; @@ -305,7 +305,7 @@ public AttributedString columnSubSequence(int start, int stop) { if (col + w > stop) { break; } - end++; + end += Character.charCount(cp); col += w; } return subSequence(begin, end); diff --git a/terminal/src/test/java/org/jline/utils/AttributedStringTest.java b/terminal/src/test/java/org/jline/utils/AttributedStringTest.java index 090ea94a6..02b4b4a5a 100644 --- a/terminal/src/test/java/org/jline/utils/AttributedStringTest.java +++ b/terminal/src/test/java/org/jline/utils/AttributedStringTest.java @@ -135,4 +135,14 @@ public void testColors() { .toAnsi(); assertEquals("This i\u001B[34ms\u001B[33m a\u001B[31m Test.\u001B[0m", ansiStr); } + + @Test + public void testColumns() { + AttributedString message = new AttributedString("👍"); + int messageLength = message.columnLength(); + assertEquals(1, messageLength); + AttributedString messageAgain = message.columnSubSequence(0, messageLength); + assertEquals("👍", messageAgain.toString()); + } + }