the browser-facing portion of osu!
at master 878 B view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 2// See the LICENCE file in the repository root for full licence text. 3 4import core from 'osu-core-singleton'; 5import { KeyboardEvent } from 'react'; 6 7export enum InputEventType { 8 Cancel = 'cancel', 9 Submit = 'submit', 10} 11 12export type TextAreaCallback = (type: InputEventType | null, event: KeyboardEvent<HTMLTextAreaElement>) => void; 13 14export function makeTextAreaHandler(callback: TextAreaCallback) { 15 return (event: KeyboardEvent<HTMLTextAreaElement>) => { 16 let type: InputEventType | null = null; 17 18 if (event.key === 'Escape') { 19 type = InputEventType.Cancel; 20 } else if (event.key === 'Enter' && !event.shiftKey && core.windowSize.isDesktop) { 21 event.preventDefault(); 22 type = InputEventType.Submit; 23 } 24 25 callback(type, event); 26 }; 27}