Skip to content

Commit 7f7541a

Browse files
committed
GroupNumericInput: it used to be that typing "0.0" would render "0." and then if
you typed "1", it would change to "0.01" which was pretty ugly. This now works as expected
1 parent 6415306 commit 7f7541a

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

Sources/SwiftTerm/Terminal.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,21 +1239,29 @@ open class Terminal {
12391239
let lastx = last.x >= cols ? cols-1 : last.x
12401240
var cd = existingLine [lastx]
12411241

1242-
// Attemp the combination
1242+
// Attempt the combination
12431243
let newStr = String ([cd.getCharacter (), ch])
12441244

12451245
// If the resulting string is 1 grapheme cluster, then it combined properly
12461246
if newStr.count == 1 {
1247+
let oldSize = cd.width
1248+
let newSize: Int8
1249+
12471250
if let newCh = newStr.first {
12481251
switch firstScalar.value {
12491252
// This is the "This should use color modifier" on the previous item
12501253
// and we are going to take this to mean two columns
12511254
// See https://github.com/migueldeicaza/SwiftTerm/pull/412
12521255
case 0xFE0F:
12531256
cd.setValue(char: newCh, size: 2)
1254-
1257+
if oldSize != 2 {
1258+
buffer.x += 1
1259+
}
12551260
default:
12561261
cd.setValue(char: newCh, size: Int32 (cd.width))
1262+
if cd.width != oldSize {
1263+
buffer.x += 1
1264+
}
12571265
}
12581266
existingLine [lastx] = cd
12591267
updateRange (last.y)

Tests/SwiftTermTests/UnicodeTests.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,57 @@ final class SwiftTermUnicode: XCTestCase {
6161
XCTAssertEqual(char2_0?.width, 1)
6262
}
6363

64+
func testCombinedPositioning() {
65+
let h = HeadlessTerminal (queue: SwiftTermTests.queue) { exitCode in }
66+
let t = h.terminal!
67+
68+
// Baseline, we know that "\u{1100}" will always use 2-columns
69+
// This inserts a simple 2-column value, and then a 1-column value
70+
t.feed (text: "\u{1100}x\n\r")
71+
let char0_0 = t.getCharacter (col: 0, row: 0)
72+
let char1_0 = t.getCharacter (col: 1, row: 0)
73+
let char2_0 = t.getCharacter (col: 2, row: 0)
74+
XCTAssertEqual(char0_0, "\u{1100}")
75+
XCTAssertEqual(char1_0, "\u{0}")
76+
XCTAssertEqual(char2_0, "x")
77+
78+
// Here we insert a value that upgrades from 1-column to 2-column when we see the
79+
// \u{fe0f}, so we need to make sure that the character after that has its position updated.
80+
t.feed (text: "\u{026e9}\u{0fe0f}x")
81+
let char0_1 = t.getCharacter (col: 0, row: 1)
82+
let char1_1 = t.getCharacter (col: 1, row: 1)
83+
let char2_1 = t.getCharacter (col: 2, row: 1)
84+
print("Got \(char0_1) \(char1_1) \(char2_1)")
85+
XCTAssertEqual(char0_1, "\u{026e9}\u{0fe0f}")
86+
XCTAssertEqual(char1_1, "\u{0}")
87+
XCTAssertEqual(char2_1, "x")
88+
89+
}
90+
6491
func testEmoji ()
6592
{
6693
let h = HeadlessTerminal (queue: SwiftTermTests.queue) { exitCode in }
6794
let t = h.terminal!
6895

6996
// This sends emoji with skin tone modifiers
7097
// The base emoji and skin tone modifier should combine into a single character
71-
t.feed (text: "👦🏻\r\n👦🏿\r\n")
98+
t.feed (text: "👦🏻x\r\n👦🏿x\r\n")
7299

73100
let char0_0 = t.getCharacter (col:0, row: 0)
101+
let char1_0 = t.getCharacter (col:1, row: 0)
102+
let char2_0 = t.getCharacter (col:2, row: 0)
103+
74104
let char0_1 = t.getCharacter (col:0, row: 1)
105+
let char1_1 = t.getCharacter (col:1, row: 1)
106+
let char2_1 = t.getCharacter (col:2, row: 1)
75107

76108
// Emoji with skin tone modifiers should be combined into a single grapheme cluster
77109
XCTAssertEqual(char0_0, "👦🏻")
110+
XCTAssertEqual(char1_0, "\u{0}")
111+
XCTAssertEqual(char2_0, "x")
78112
XCTAssertEqual(char0_1, "👦🏿")
113+
XCTAssertEqual(char1_1, "\u{0}")
114+
XCTAssertEqual(char2_1, "x")
79115
}
80116

81117
func testEmojiWithModifierBase ()

0 commit comments

Comments
 (0)