Skip to content

Commit

Permalink
Fix incorrect codepoint index usage as byte offset in input handling
Browse files Browse the repository at this point in the history
Fixes unicode inputs
  • Loading branch information
alimpfard committed Jun 1, 2024
1 parent f88d45b commit 58e37e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
33 changes: 22 additions & 11 deletions src/example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,29 @@ pub fn main() Editor.Error!void {
self.editor.stripStyles();
const buf = self.editor.getBuffer();
for (buf, 0..) |c, i| {
self.editor.stylize(.{
.begin = i,
.end = i + 1,
}, .{
.foreground = .{
.rgb = [3]u8{
@intCast(c % 26 * 10),
@intCast(c / 26 * 10),
@intCast(c % 10 * 10 + 150),
if (c > 0x7F) {
self.editor.stylize(.{
.begin = i,
.end = i + 1,
}, .{
.foreground = .{
.rgb = [3]u8{ 255, 0, 0 },
},
},
}) catch unreachable;
}) catch unreachable;
} else {
self.editor.stylize(.{
.begin = i,
.end = i + 1,
}, .{
.foreground = .{
.rgb = [3]u8{
@intCast(c % 26 * 10),
@intCast(c / 26 * 10),
@intCast(c % 10 * 10 + 150),
},
},
}) catch unreachable;
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ pub const Editor = struct {
self.prohibit_input_processing = true;
defer self.prohibit_input_processing = false;

var keybuf = [16]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var keybuf = [_]u8{0} ** 32;

var stdin = std.io.getStdIn();

Expand Down Expand Up @@ -1997,11 +1997,11 @@ pub const Editor = struct {
self.insertCodePoint(code_point);
}

if (consumed_code_points == self.incomplete_data.container.items.len) {
if (input_it.i == self.incomplete_data.container.items.len) {
self.incomplete_data.container.clearAndFree();
} else {
for (consumed_code_points..self.incomplete_data.container.items.len) |_| {
_ = self.incomplete_data.container.orderedRemove(consumed_code_points);
for (input_it.i..self.incomplete_data.container.items.len) |_| {
_ = self.incomplete_data.container.orderedRemove(input_it.i);
}
}

Expand Down Expand Up @@ -2042,7 +2042,7 @@ pub const Editor = struct {
}

fn vtDSR(self: *Self) ![2]usize {
var buf = [16]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var buf = [_]u8{0} ** 32;
var more_junk_to_read = false;
var stdin = std.io.getStdIn();
var pollfds = [1]std.posix.pollfd{undefined};
Expand Down

0 comments on commit 58e37e6

Please sign in to comment.