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 backspace with selected text.

Tim Abbott67dbaaff913c
diff --git a/web/src/input_pill.ts b/web/src/input_pill.ts
index 754d763ef94..76de9ff1963 100644
--- a/web/src/input_pill.ts
+++ b/web/src/input_pill.ts
@@ -339,11 +339,14 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
return;
}
- // if the user backspaces and there is input, just do normal char
- // deletion, otherwise delete the last pill in the sequence.
+ const selection = window.getSelection();
+ // If no text is selected, and the cursor is just to the
+ // right of the last pill (with or without text in the
+ // input), then backspace deletes the last pill.
if (
+ selection?.type !== "range" &&
e.key === "Backspace" &&
- (funcs.value(e.target).length === 0 || window.getSelection()?.anchorOffset === 0)
+ (funcs.value(e.target).length === 0 || selection?.anchorOffset === 0)
) {
e.preventDefault();
funcs.removeLastPill();
@@ -355,7 +358,7 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
// should switch to focus the last pill in the list.
// the rest of the events then will be taken care of in the function
// below that handles events on the ".pill" class.
- if (e.key === "ArrowLeft" && window.getSelection()?.anchorOffset === 0) {
+ if (e.key === "ArrowLeft" && selection?.anchorOffset === 0) {
store.$parent.find(".pill").last().trigger("focus");
}