Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. export enum Key {
  21. ArrowLeft = 'ArrowLeft',
  22. ArrowUp = 'ArrowUp',
  23. ArrowRight = 'ArrowRight',
  24. ArrowDown = 'ArrowDown',
  25. Alt = 'Alt',
  26. Option = 'Option',
  27. Backspace = 'Backspace',
  28. CapsLock = 'CapsLock',
  29. Meta = 'Meta',
  30. Control = 'Control',
  31. Command = 'Command',
  32. Delete = 'Delete',
  33. End = 'End',
  34. Enter = 'Enter',
  35. Escape = 'Escape',
  36. Home = 'Home',
  37. PageDown = 'PageDown',
  38. PageUp = 'PageUp',
  39. Shift = 'Shift',
  40. Space = ' ',
  41. Tab = 'Tab',
  42. Click = 'Click',
  43. }
  44. export function isShortcut(event: KeyboardEvent): boolean {
  45. return event.ctrlKey || event.metaKey;
  46. }
  47. const INPUT_TAGS = ['INPUT', 'SELECT', 'TEXTAREA', 'UBCOMMENT'];
  48. export function isInput(event: KeyboardEvent): boolean {
  49. const { tagName } = event.target as HTMLElement;
  50. return INPUT_TAGS.includes(tagName);
  51. }
  52. export function isTextarea(
  53. event: KeyboardEvent,
  54. ): event is KeyboardEvent & { target: HTMLTextAreaElement } {
  55. return event.target instanceof HTMLTextAreaElement;
  56. }