Skip to content

Commit 2d2c1f7

Browse files
tdknmtsgrd
authored andcommitted
refactor: migrate ime composition handler to dependency injection
Replace direct IMECompositionHandler instantiation with dependency injection pattern to improve modularity and enable better testing. Add IME_COMPOSITION_HANDLER injection token and register singleton instance in bootstrap dependencies. Changes: - Define IME_COMPOSITION_HANDLER injection token in imeHandling.ts - Register singleton IMECompositionHandler instance in deps.ts - Update CommitMessageEditor and ReviewCreation to inject handler instead of creating new instances
1 parent bb30922 commit 2d2c1f7

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

apps/desktop/src/components/CommitMessageEditor.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { WORKTREE_SERVICE } from '$lib/worktree/worktreeService.svelte';
1818
import { inject } from '@gitbutler/core/context';
1919
import { Button, TestId } from '@gitbutler/ui';
20-
import { IMECompositionHandler } from '@gitbutler/ui/utils/imeHandling';
20+
import { IME_COMPOSITION_HANDLER } from '@gitbutler/ui/utils/imeHandling';
2121
2222
import { tick } from 'svelte';
2323
@@ -69,7 +69,7 @@
6969
7070
let composer = $state<ReturnType<typeof MessageEditor>>();
7171
let titleInput = $state<HTMLTextAreaElement>();
72-
const imeHandler = new IMECompositionHandler();
72+
const imeHandler = inject(IME_COMPOSITION_HANDLER);
7373
7474
const suggestionsHandler = new CommitSuggestions(aiService, uiState);
7575
const diffInputArgs = $derived<DiffInputContextArgs>(

apps/desktop/src/components/ReviewCreation.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import { inject } from '@gitbutler/core/context';
3737
import { persisted } from '@gitbutler/shared/persisted';
3838
import { chipToasts, TestId } from '@gitbutler/ui';
39-
import { IMECompositionHandler } from '@gitbutler/ui/utils/imeHandling';
39+
import { IME_COMPOSITION_HANDLER } from '@gitbutler/ui/utils/imeHandling';
4040
import { isDefined } from '@gitbutler/ui/utils/typeguards';
4141
import { tick } from 'svelte';
4242
@@ -92,7 +92,7 @@
9292
9393
let titleInput = $state<HTMLTextAreaElement | undefined>(undefined);
9494
let messageEditor = $state<MessageEditor>();
95-
const imeHandler = new IMECompositionHandler();
95+
const imeHandler = inject(IME_COMPOSITION_HANDLER);
9696
9797
// AI things
9898
const aiGenEnabled = projectAiGenEnabled(projectId);

apps/desktop/src/lib/bootstrap/deps.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
EXTERNAL_LINK_SERVICE,
8383
type ExternalLinkService
8484
} from '@gitbutler/ui/utils/externalLinkService';
85+
import { IMECompositionHandler, IME_COMPOSITION_HANDLER } from '@gitbutler/ui/utils/imeHandling';
8586
import { PUBLIC_API_BASE_URL } from '$env/static/public';
8687

8788
export function initDependencies(args: {
@@ -260,6 +261,7 @@ export function initDependencies(args: {
260261
// ============================================================================
261262

262263
const focusManager = new FocusManager();
264+
const imeHandler = new IMECompositionHandler();
263265
const reorderDropzoneFactory = new ReorderDropzoneFactory(stackService);
264266
const shortcutService = new ShortcutService(backend);
265267
const dragStateService = new DragStateService();
@@ -326,6 +328,7 @@ export function initDependencies(args: {
326328
[HOOKS_SERVICE, hooksService],
327329
[HTTP_CLIENT, httpClient],
328330
[ID_SELECTION, idSelection],
331+
[IME_COMPOSITION_HANDLER, imeHandler],
329332
[IRC_CLIENT, ircClient],
330333
[IRC_SERVICE, ircService],
331334
[MODE_SERVICE, modeService],

packages/ui/src/lib/utils/imeHandling.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import { InjectionToken } from '@gitbutler/core/context';
2+
3+
export const IME_COMPOSITION_HANDLER: InjectionToken<IMECompositionHandler> =
4+
new InjectionToken<IMECompositionHandler>('IMECompositionHandler');
5+
16
/**
27
* IME (Input Method Editor) handling utilities for text input components.
38
* This class provides a unified handler to manage IME composition state

0 commit comments

Comments
 (0)