fix: input keyboard shortcut opt+delete (#685)

This commit is contained in:
Fouad Matin
2025-04-30 17:17:13 -07:00
committed by GitHub
parent bc4e6db749
commit 985fd44ec0
2 changed files with 67 additions and 8 deletions

View File

@@ -43,18 +43,17 @@ describe("TextBuffer wordwise navigation & deletion", () => {
expect(tb.getText()).toBe("foo bar ");
});
test("Option/Alt+Delete deletes next word", () => {
test("Option/Alt+Delete deletes previous word (matches shells)", () => {
const tb = new TextBuffer("foo bar baz");
const vp = { height: 10, width: 80 } as const;
// Move caret between first and second word (after space)
tb.move("wordRight"); // after foo
tb.move("right"); // skip space -> start of bar
// Place caret at end so we can test backward deletion.
tb.move("end");
// Option+Delete
// Simulate Option+Delete (parsed as alt-modified Delete on some terminals)
tb.handleInput(undefined, { delete: true, alt: true }, vp);
expect(tb.getText()).toBe("foo baz"); // note double space removed later maybe
expect(tb.getText()).toBe("foo bar ");
});
test("wordLeft eventually reaches column 0", () => {
@@ -121,4 +120,18 @@ describe("TextBuffer wordwise navigation & deletion", () => {
const [, col] = tb.getCursor();
expect(col).toBe(6);
});
test("Shift+Option/Alt+Delete deletes next word", () => {
const tb = new TextBuffer("foo bar baz");
const vp = { height: 10, width: 80 } as const;
// Move caret between first and second word (after space)
tb.move("wordRight"); // after foo
tb.move("right"); // skip space -> start of bar
// Shift+Option+Delete should now remove "bar "
tb.handleInput(undefined, { delete: true, alt: true, shift: true }, vp);
expect(tb.getText()).toBe("foo baz");
});
});