Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

input_pill: Highlight previous pill after backspace deletion.

evykassirer261f01ede84d
diff --git a/web/src/input_pill.ts b/web/src/input_pill.ts
index 683287ba8ae..07b7cd1dd91 100644
--- a/web/src/input_pill.ts
+++ b/web/src/input_pill.ts
@@ -375,9 +375,14 @@ export function create<ItemType extends {type: string}>(
$pill.next().trigger("focus");
break;
case "Backspace": {
+ const $prev = $pill.prev();
const $next = $pill.next();
funcs.removePill(util.the($pill), "backspace");
- $next.trigger("focus");
+ if ($prev.length) {
+ $prev.trigger("focus");
+ } else {
+ $next.trigger("focus");
+ }
// the "Backspace" key in Firefox will go back a page if you do
// not prevent it.
e.preventDefault();
diff --git a/web/tests/input_pill.test.js b/web/tests/input_pill.test.js
index 8dbf5b93960..30329113aeb 100644
--- a/web/tests/input_pill.test.js
+++ b/web/tests/input_pill.test.js
@@ -437,15 +437,15 @@ run_test("insert_remove", ({mock_template}) => {
const yellow_pill = pills.find((pill) => pill.item.color_name === "YELLOW");
$container.set_find_results(".pill:focus", yellow_pill.$element);
- let next_pill_focused = false;
- const $next_pill_stub = {
- trigger(type) {
- if (type === "focus") {
- next_pill_focused = true;
- }
- },
+ let prev_pill_focused = false;
+ const $prev_pill_stub = $("<prev-stub>");
+ $prev_pill_stub.trigger = (type) => {
+ if (type === "focus") {
+ prev_pill_focused = true;
+ }
};
- yellow_pill.$element.next = () => $next_pill_stub;
+ yellow_pill.$element.prev = () => $prev_pill_stub;
+ yellow_pill.$element.next = () => $("<next-stub>");
key_handler = $container.get_on_handler("keydown", ".pill");
key_handler.call(
@@ -457,14 +457,15 @@ run_test("insert_remove", ({mock_template}) => {
);
assert.ok(removed);
assert.equal(color_removed, "YELLOW");
- assert.ok(next_pill_focused);
+ assert.ok(prev_pill_focused);
- next_pill_focused = false;
+ prev_pill_focused = false;
assert.deepEqual(widget.items(), [items.blue, items.red]);
const $focus_pill_stub = {
- next: () => $next_pill_stub,
- [0]: "<pill-stub BLUE>",
+ prev: () => $prev_pill_stub,
+ next: () => $("<next-stub>"),
+ [0]: "<pill-stub RED>",
length: 1,
};
@@ -476,8 +477,8 @@ run_test("insert_remove", ({mock_template}) => {
preventDefault: noop,
});
- assert.equal(color_removed, "BLUE");
- assert.ok(next_pill_focused);
+ assert.equal(color_removed, "RED");
+ assert.ok(prev_pill_focused);
});
run_test("exit button on pill", ({mock_template}) => {