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: Fix implicit use of any.

Anders Kaseorgfe6744ae548d
diff --git a/web/src/input_pill.ts b/web/src/input_pill.ts
index b6dc3a1ea54..ae5d4af91d7 100644
--- a/web/src/input_pill.ts
+++ b/web/src/input_pill.ts
@@ -309,7 +309,7 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
};
{
- store.$parent.on("keydown", ".input", (e) => {
+ store.$parent.on("keydown", ".input", function (this: HTMLElement, e) {
if (keydown_util.is_enter_event(e)) {
// regardless of the value of the input, the ENTER keyword
// should be ignored in favor of keeping content to one line
@@ -318,7 +318,7 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
// if there is input, grab the input, make a pill from it,
// and append the pill, then clear the input.
- const value = funcs.value(e.target).trim();
+ const value = funcs.value(this).trim();
if (value.length > 0) {
// append the pill and by proxy create the pill object.
const ret = funcs.appendPill(value);
@@ -328,7 +328,7 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
// incorrect.
if (ret) {
// clear the input.
- funcs.clear(e.target);
+ funcs.clear(this);
e.stopPropagation();
}
}
@@ -341,7 +341,7 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
// input), then backspace deletes the last pill.
if (
e.key === "Backspace" &&
- (funcs.value(e.target).length === 0 ||
+ (funcs.value(this).length === 0 ||
(selection?.anchorOffset === 0 && selection?.toString()?.length === 0))
) {
e.preventDefault();
@@ -428,7 +428,7 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
// when the "×" is clicked on a pill, it should delete that pill and then
// select the next pill (or input).
- store.$parent.on("click", ".exit", function (e) {
+ store.$parent.on("click", ".exit", function (this: HTMLElement, e) {
e.stopPropagation();
const $pill = $(this).closest(".pill");
const $next = $pill.next();
@@ -443,9 +443,8 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
}
});
- store.$parent.on("copy", ".pill", (e) => {
- const element: HTMLElement = e.currentTarget;
- const {item} = funcs.getByElement(element)!;
+ store.$parent.on("copy", ".pill", function (this: HTMLElement, e) {
+ const {item} = funcs.getByElement(this)!;
assert(e.originalEvent instanceof ClipboardEvent);
e.originalEvent.clipboardData?.setData("text/plain", store.get_text_from_item(item));
e.preventDefault();
diff --git a/web/tests/input_pill.test.js b/web/tests/input_pill.test.js
index c9970c07bf6..4748c65e3bb 100644
--- a/web/tests/input_pill.test.js
+++ b/web/tests/input_pill.test.js
@@ -162,12 +162,11 @@ run_test("copy from pill", ({mock_template}) => {
},
};
const e = {
- currentTarget: $pill_stub,
originalEvent,
preventDefault: noop,
};
- copy_handler(e);
+ copy_handler.call($pill_stub, e);
assert.equal(copied_text, "RED");
});
@@ -362,14 +361,16 @@ run_test("Enter key with text", ({mock_template}) => {
const key_handler = $container.get_on_handler("keydown", ".input");
- key_handler({
- key: "Enter",
- preventDefault: noop,
- stopPropagation: noop,
- target: {
+ key_handler.call(
+ {
textContent: " yellow ",
},
- });
+ {
+ key: "Enter",
+ preventDefault: noop,
+ stopPropagation: noop,
+ },
+ );
assert.deepEqual(widget.items(), [items.blue, items.red, items.yellow]);
});
@@ -441,13 +442,15 @@ run_test("insert_remove", ({mock_template}) => {
let key_handler = $container.get_on_handler("keydown", ".input");
- key_handler({
- key: "Backspace",
- target: {
+ key_handler.call(
+ {
textContent: "",
},
- preventDefault: noop,
- });
+ {
+ key: "Backspace",
+ preventDefault: noop,
+ },
+ );
assert.ok(removed);
assert.equal(color_removed, "YELLOW");