textinput: add more readline bindings
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
parent
96f7bd6044
commit
edb1fae2ab
1 changed files with 15 additions and 4 deletions
|
@ -38,19 +38,30 @@ pub fn update(self: *TextInput, event: Event) !void {
|
||||||
if (key.matches(Key.backspace, .{})) {
|
if (key.matches(Key.backspace, .{})) {
|
||||||
if (self.cursor_idx == 0) return;
|
if (self.cursor_idx == 0) return;
|
||||||
self.deleteBeforeCursor();
|
self.deleteBeforeCursor();
|
||||||
} else if (key.matches(Key.delete, .{})) {
|
} else if (key.matches(Key.delete, .{}) or key.matches('d', .{ .ctrl = true })) {
|
||||||
if (self.cursor_idx == self.grapheme_count) return;
|
if (self.cursor_idx == self.grapheme_count) return;
|
||||||
self.deleteAtCursor();
|
self.deleteAtCursor();
|
||||||
} else if (key.matches(Key.left, .{})) {
|
} else if (key.matches(Key.left, .{}) or key.matches('b', .{ .ctrl = true })) {
|
||||||
if (self.cursor_idx > 0) self.cursor_idx -= 1;
|
if (self.cursor_idx > 0) self.cursor_idx -= 1;
|
||||||
} else if (key.matches(Key.right, .{})) {
|
} else if (key.matches(Key.right, .{}) or key.matches('f', .{ .ctrl = true })) {
|
||||||
if (self.cursor_idx < self.grapheme_count) self.cursor_idx += 1;
|
if (self.cursor_idx < self.grapheme_count) self.cursor_idx += 1;
|
||||||
|
} else if (key.matches('a', .{ .ctrl = true })) {
|
||||||
|
self.cursor_idx = 0;
|
||||||
|
} else if (key.matches('e', .{ .ctrl = true })) {
|
||||||
|
self.cursor_idx = self.grapheme_count;
|
||||||
|
} else if (key.matches('k', .{ .ctrl = true })) {
|
||||||
|
while (self.cursor_idx < self.grapheme_count) {
|
||||||
|
self.deleteAtCursor();
|
||||||
|
}
|
||||||
|
} else if (key.matches('u', .{ .ctrl = true })) {
|
||||||
|
while (self.cursor_idx > 0) {
|
||||||
|
self.deleteBeforeCursor();
|
||||||
|
}
|
||||||
} else if (key.text) |text| {
|
} else if (key.text) |text| {
|
||||||
try self.buf.insertSlice(self.byteOffsetToCursor(), text);
|
try self.buf.insertSlice(self.byteOffsetToCursor(), text);
|
||||||
self.cursor_idx += 1;
|
self.cursor_idx += 1;
|
||||||
self.grapheme_count += 1;
|
self.grapheme_count += 1;
|
||||||
}
|
}
|
||||||
// TODO: readline bindings
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue