-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcomposer-shortcuts.ts
More file actions
26 lines (24 loc) · 884 Bytes
/
Copy pathcomposer-shortcuts.ts
File metadata and controls
26 lines (24 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
interface EnterSubmissionParams {
sendByShiftEnter: boolean;
shiftKey: boolean;
ctrlKey: boolean;
metaKey: boolean;
isComposing: boolean;
}
/**
* Returns true when an Enter keypress should submit the composer.
* Ctrl/Cmd+Enter stays unbound regardless of preference.
*/
export function shouldSubmitOnEnter(params: EnterSubmissionParams): boolean {
if (params.isComposing) return false;
if (params.ctrlKey || params.metaKey) return false;
return params.sendByShiftEnter ? params.shiftKey : !params.shiftKey;
}
/** Shared predicate for whether the composer can submit. Used by both
* the button disabled state and the keyboard/form submit paths so
* they remain identical. */
export function canSubmitComposer(isDisabled: boolean, inputText: string, imageCount: number): boolean {
void imageCount;
if (isDisabled) return false;
return inputText.trim().length > 0;
}