Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(views): preserve IME input in filters, title rename and find (MUL-8509) (#9829)

沙雕的小鱼儿 boyfeiyuc681f71791e3
diff --git a/packages/views/issues/components/advanced-filter-panel.tsx b/packages/views/issues/components/advanced-filter-panel.tsx
index 58089aec1f..ceb280df4a 100644
--- a/packages/views/issues/components/advanced-filter-panel.tsx
+++ b/packages/views/issues/components/advanced-filter-panel.tsx
@@ -57,6 +57,7 @@ import {
} from "@multica/core/issues/stores/filter-operators";
import { useViewStore } from "@multica/core/issues/stores/view-store-context";
import { useWorkspaceId } from "@multica/core/hooks";
+import { isImeComposing } from "@multica/core/utils";
import { propertyListOptions } from "@multica/core/properties";
import { memberListOptions } from "@multica/core/workspace/queries";
import {
@@ -302,7 +303,7 @@ function TypedValueInput({
onChange={(event) => setDraft(event.target.value)}
onBlur={commit}
onKeyDown={(event) => {
- if (event.key === "Enter") commit();
+ if (event.key === "Enter" && !isImeComposing(event)) commit();
}}
className="h-7 min-w-0 flex-1 rounded-md px-2 text-caption md:text-caption"
/>
diff --git a/packages/views/issues/components/find-bar.test.tsx b/packages/views/issues/components/find-bar.test.tsx
new file mode 100644
index 0000000000..bfde01b06c
--- /dev/null
+++ b/packages/views/issues/components/find-bar.test.tsx
@@ -0,0 +1,82 @@
+// @vitest-environment jsdom
+
+import { useState } from "react";
+import { fireEvent, screen } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+import { renderWithI18n } from "../../test/i18n";
+import { FindBar } from "./find-bar";
+
+function renderFindBar() {
+ const goNext = vi.fn();
+ const goPrev = vi.fn();
+ const closeFind = vi.fn();
+
+ function Harness() {
+ const [query, setQuery] = useState("");
+ return (
+ <FindBar
+ find={{
+ open: true,
+ query,
+ matchCount: 2,
+ activeIndex: 0,
+ supported: false,
+ inputRef: { current: null },
+ setQuery,
+ openFind: vi.fn(),
+ closeFind,
+ goNext,
+ goPrev,
+ }}
+ />
+ );
+ }
+
+ renderWithI18n(<Harness />);
+ return { goNext, goPrev, closeFind };
+}
+
+describe("FindBar", () => {
+ it.each([
+ ["standard Enter", { key: "Enter", isComposing: true, keyCode: 13 }],
+ ["Safari Enter", { key: "Enter", isComposing: false, keyCode: 229 }],
+ ["standard Shift+Enter", { key: "Enter", shiftKey: true, isComposing: true, keyCode: 13 }],
+ ["Safari Shift+Enter", { key: "Enter", shiftKey: true, isComposing: false, keyCode: 229 }],
+ ["standard Escape", { key: "Escape", isComposing: true, keyCode: 27 }],
+ ["Safari Escape", { key: "Escape", isComposing: false, keyCode: 229 }],
+ ])("leaves %s to the IME without navigating or closing", (_label, event) => {
+ const { goNext, goPrev, closeFind } = renderFindBar();
+ const input = screen.getByRole("textbox");
+ fireEvent.compositionStart(input);
+ fireEvent.change(input, { target: { value: "zhong" } });
+
+ expect(fireEvent.keyDown(input, event)).toBe(true);
+ expect(goNext).not.toHaveBeenCalled();
+ expect(goPrev).not.toHaveBeenCalled();
+ expect(closeFind).not.toHaveBeenCalled();
+ expect(input).toHaveValue("zhong");
+ expect(input).toHaveFocus();
+
+ fireEvent.compositionEnd(input, { data: "中" });
+ fireEvent.change(input, { target: { value: "中" } });
+ expect(input).toHaveValue("中");
+ expect(fireEvent.keyDown(input, { key: "Enter" })).toBe(false);
+ expect(goNext).toHaveBeenCalledExactlyOnceWith();
+ });
+
+ it("keeps ordinary Enter, Shift+Enter and Escape actions", () => {
+ const { goNext, goPrev, closeFind } = renderFindBar();
+ const input = screen.getByRole("textbox");
+
+ expect(fireEvent.keyDown(input, { key: "Enter" })).toBe(false);
+ expect(goNext).toHaveBeenCalledExactlyOnceWith();
+ expect(goPrev).not.toHaveBeenCalled();
+ expect(closeFind).not.toHaveBeenCalled();
+
+ expect(fireEvent.keyDown(input, { key: "Enter", shiftKey: true })).toBe(false);
+ expect(goPrev).toHaveBeenCalledExactlyOnceWith();
+
+ expect(fireEvent.keyDown(input, { key: "Escape" })).toBe(false);
+ expect(closeFind).toHaveBeenCalledExactlyOnceWith();
+ });
+});
diff --git a/packages/views/issues/components/find-bar.tsx b/packages/views/issues/components/find-bar.tsx
index 96091184f5..ce859c5ab9 100644
--- a/packages/views/issues/components/find-bar.tsx
+++ b/packages/views/issues/components/find-bar.tsx
@@ -1,6 +1,7 @@
"use client";
import type { KeyboardEvent } from "react";
+import { isImeComposing } from "@multica/core/utils";
import { ChevronDown, ChevronUp, Search, X } from "@multica/ui/icons";
import { Input } from "@multica/ui/components/ui/input";
import { IconButton } from "@multica/ui/components/common/icon-button";
@@ -44,6 +45,7 @@ export function FindBar({
const noMatches = matchCount === 0;
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
+ if (isImeComposing(e)) return;
if (e.key === "Enter") {
e.preventDefault();
if (e.shiftKey) goPrev();
diff --git a/packages/views/issues/components/issues-header.advanced-filter.test.tsx b/packages/views/issues/components/issues-header.advanced-filter.test.tsx
index 005b207168..8ea77e2597 100644
--- a/packages/views/issues/components/issues-header.advanced-filter.test.tsx
+++ b/packages/views/issues/components/issues-header.advanced-filter.test.tsx
@@ -27,11 +27,11 @@ vi.mock("../../common/actor-avatar", () => ({
ActorAvatar: () => null,
}));
-function renderFilterMenu(setup?: (store: StoreApi<IssueViewState>) => void, withProperty = false) {
+function renderFilterMenu(setup?: (store: StoreApi<IssueViewState>) => void, withProperty = false, propertyType = "number") {
setApiInstance({
listIssueStatuses: async () => ({ statuses: [], categories: [], total: 0 }),
listProperties: async () => ({ properties: withProperty ? [{
- id: "estimate", workspace_id: "ws-1", name: "Estimate", type: "number",
+ id: "estimate", workspace_id: "ws-1", name: "Estimate", type: propertyType,
config: {}, position: 1, archived: false, created_at: "", updated_at: "",
}] : [] }),
listMembers: async () => [],
@@ -128,6 +128,31 @@ describe("IssueFilterMenu advanced mode", () => {
expect(screen.getByRole("button", { name: "Clear all" })).toBeDisabled();
});
+ it.each([
+ ["standard", { key: "Enter", isComposing: true, keyCode: 13 }],
+ ["Safari", { key: "Enter", isComposing: false, keyCode: 229 }],
+ ])("keeps the advanced text condition unchanged on %s IME confirmation", async (_label, event) => {
+ const store = renderFilterMenu((s) => s.getState().setAdvancedFilter(
+ createFilterGroup("all", [createFilterCondition("property:estimate", ["original"])]),
+ ), true, "text");
+ fireEvent.click(screen.getByRole("button", { name: "Filter" }));
+ const input = await screen.findByRole("textbox", { name: "Values" });
+ fireEvent.compositionStart(input);
+ fireEvent.change(input, { target: { value: "zhong" } });
+ fireEvent.keyDown(input, event);
+ expect(store.getState().advancedFilter?.children).toMatchObject([{ values: ["original"] }]);
+ expect(input).toHaveValue("zhong");
+ expect(screen.getByTestId("advanced-filter-panel")).toBeInTheDocument();
+
+ fireEvent.compositionEnd(input, { data: "中" });
+ fireEvent.change(input, { target: { value: "中" } });
+ fireEvent.keyDown(input, { key: "Enter" });
+ expect(store.getState().advancedFilter?.children).toMatchObject([{ values: ["中"] }]);
+ fireEvent.change(input, { target: { value: "blurred" } });
+ fireEvent.blur(input);
+ expect(store.getState().advancedFilter?.children).toMatchObject([{ values: ["blurred"] }]);
+ });
+
it("edits a number property with a typed value and its own operators", async () => {
const store = renderFilterMenu(
(s) =>
diff --git a/packages/views/issues/components/issues-header.property-filter.test.tsx b/packages/views/issues/components/issues-header.property-filter.test.tsx
index 0973d80568..8481fd58a3 100644
--- a/packages/views/issues/components/issues-header.property-filter.test.tsx
+++ b/packages/views/issues/components/issues-header.property-filter.test.tsx
@@ -44,7 +44,7 @@ function textProperty(id: string, name: string): IssueProperty {
};
}
-function renderFilterMenu(props: IssueProperty[], propertyFilters: IssueViewState["propertyFilters"] = {}) {
+function renderFilterMenu(props: IssueProperty[], propertyFilters: IssueViewState["propertyFilters"] = {}, onKeyDown?: React.KeyboardEventHandler) {
setApiInstance({
listIssueStatuses: async () => ({ statuses: [], categories: [], total: 0 }),
listProperties: async () => ({ properties: props }),
@@ -72,7 +72,9 @@ function renderFilterMenu(props: IssueProperty[], propertyFilters: IssueViewStat
const view = renderWithI18n(
<QueryClientProvider client={qc}>
<ViewStoreProvider store={store}>
- <IssueFilterMenu trigger={<button type="button">Filter</button>} />
+ <div onKeyDown={onKeyDown}>
+ <IssueFilterMenu trigger={<button type="button">Filter</button>} />
+ </div>
</ViewStoreProvider>
</QueryClientProvider>,
);
@@ -147,6 +149,37 @@ describe("IssueFilterMenu select property filter", () => {
describe("IssueFilterMenu scalar property filter", () => {
const PROP = "prop-note";
+ it.each([
+ ["standard", { key: "Enter", isComposing: true, keyCode: 13 }],
+ ["Safari", { key: "Enter", isComposing: false, keyCode: 229 }],
+ ])("keeps the draft and menu intact on %s IME confirmation", async (_label, event) => {
+ const onKeyDown = vi.fn();
+ const { store } = renderFilterMenu([textProperty(PROP, "Note")], {}, onKeyDown);
+ await openPropertySubmenu("Note");
+ const input = valueInput();
+ const noValue = screen.getByRole("menuitemcheckbox", { name: "No value" });
+ // Highlight the menu action before returning to the input: Enter must
+ // neither apply the draft nor reach the menu's selection handlers.
+ fireEvent.pointerMove(noValue, { pointerType: "mouse" });
+ fireEvent.focus(input);
+ fireEvent.compositionStart(input);
+ fireEvent.change(input, { target: { value: "zhong" } });
+ // Consume propagation without cancelling the IME default action.
+ expect(fireEvent.keyDown(input, event)).toBe(true);
+ expect(onKeyDown).not.toHaveBeenCalled();
+ expect(store.getState().propertyFilters).toEqual({});
+ expect(input).toHaveValue("zhong");
+ expect(input).toBeInTheDocument();
+ expect(noValue).toHaveAttribute("aria-checked", "false");
+
+ fireEvent.compositionEnd(input, { data: "中" });
+ fireEvent.change(input, { target: { value: "中" } });
+ fireEvent.keyDown(input, { key: "Enter" });
+ expect(store.getState().propertyFilters).toEqual({ [PROP]: ["中"] });
+ expect(noValue).toHaveAttribute("aria-checked", "false");
+ expect(input).toBeInTheDocument();
+ });
+
it("types into the scalar value input", async () => {
const { store } = renderFilterMenu([textProperty(PROP, "Note")]);
await openPropertySubmenu("Note");
diff --git a/packages/views/issues/components/property-filter-options.tsx b/packages/views/issues/components/property-filter-options.tsx
index 37e13a5979..55921c1be4 100644
--- a/packages/views/issues/components/property-filter-options.tsx
+++ b/packages/views/issues/components/property-filter-options.tsx
@@ -6,6 +6,7 @@ import { Input } from "@multica/ui/components/ui/input";
import { DropdownMenuCheckboxItem } from "@multica/ui/components/ui/dropdown-menu";
import { useAuthStore } from "@multica/core/auth";
import { useWorkspaceId } from "@multica/core/hooks";
+import { isImeComposing } from "@multica/core/utils";
import { memberListOptions } from "@multica/core/workspace/queries";
import {
formatActorRef,
@@ -328,7 +329,7 @@ export function PropertyFilterOptions({
// focus; Enter commits and still needs stopPropagation so it does
// not bubble up and activate the highlighted "No value" item.
if (event.key === "Escape" || event.key === "Tab") return;
- if (event.key === "Enter") commitValue(draft);
+ if (event.key === "Enter" && !isImeComposing(event)) commitValue(draft);
event.stopPropagation();
}}
disabled={locked}
diff --git a/packages/views/issues/components/table-inline-title.test.tsx b/packages/views/issues/components/table-inline-title.test.tsx
index ea8830f1ea..020f9c325e 100644
--- a/packages/views/issues/components/table-inline-title.test.tsx
+++ b/packages/views/issues/components/table-inline-title.test.tsx
@@ -138,6 +138,37 @@ describe("InlineTitle", () => {
expect(screen.queryByRole("textbox")).toBeNull();
});
+ it.each([
+ ["standard Enter", { key: "Enter", isComposing: true, keyCode: 13 }],
+ ["Safari Enter", { key: "Enter", isComposing: false, keyCode: 229 }],
+ ["standard Escape", { key: "Escape", isComposing: true, keyCode: 27 }],
+ ["Safari Escape", { key: "Escape", isComposing: false, keyCode: 229 }],
+ ])("preserves the title draft during %s IME composition", (_label, event) => {
+ const onUpdate = vi.fn();
+ const onEditingChange = vi.fn();
+ render(<Harness title="Original" onUpdate={onUpdate} onEditingChange={onEditingChange} />);
+
+ fireEvent.click(screen.getByRole("button", { name: "Rename issue" }));
+ onEditingChange.mockClear();
+ const input = screen.getByRole("textbox");
+ fireEvent.compositionStart(input);
+ fireEvent.change(input, { target: { value: "zhong" } });
+
+ expect(fireEvent.keyDown(input, event)).toBe(true);
+ expect(onUpdate).not.toHaveBeenCalled();
+ expect(onEditingChange).not.toHaveBeenCalled();
+ expect(screen.getByRole("textbox")).toBe(input);
+ expect(input).toHaveValue("zhong");
+
+ fireEvent.compositionEnd(input, { data: "中" });
+ fireEvent.change(input, { target: { value: "中" } });
+ fireEvent.keyDown(input, { key: "Enter" });
+
+ expect(onUpdate).toHaveBeenCalledExactlyOnceWith({ title: "中" });
+ expect(onEditingChange).toHaveBeenCalledExactlyOnceWith(false);
+ expect(screen.queryByRole("textbox")).toBeNull();
+ });
+
it("opens sub-issue creation without also navigating into the issue", () => {
const onCreateSubIssue = vi.fn();
const rowClick = vi.fn();
diff --git a/packages/views/issues/components/table-view.tsx b/packages/views/issues/components/table-view.tsx
index 6f706a4dc2..0aa30229b6 100644
--- a/packages/views/issues/components/table-view.tsx
+++ b/packages/views/issues/components/table-view.tsx
@@ -75,6 +75,7 @@ import { Skeleton } from "@multica/ui/components/ui/skeleton";
import { cn } from "@multica/ui/lib/utils";
import { ApiError } from "@multica/core/api";
import { useWorkspaceId } from "@multica/core/hooks";
+import { isImeComposing } from "@multica/core/utils";
import { useIssueStatuses } from "@multica/core/issue-statuses/hooks";
import { useModalStore } from "@multica/core/modals";
import {
@@ -754,6 +755,7 @@ export function InlineTitle({
onChange={(event) => setDraft(event.target.value)}
onBlur={commit}
onKeyDown={(event) => {
+ if (isImeComposing(event)) return;
if (event.key === "Enter") commit();
if (event.key === "Escape") {
setDraft(row.issue.title);