You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. const UserAgent = require("fbjs/lib/UserAgent");
  13. const isSoftNewlineEvent = require("./isSoftNewlineEvent");
  14. const isOSX = UserAgent.isPlatform('Mac OS X');
  15. const KeyBindingUtil = {
  16. /**
  17. * Check whether the ctrlKey modifier is *not* being used in conjunction with
  18. * the altKey modifier. If they are combined, the result is an `altGraph`
  19. * key modifier, which should not be handled by this set of key bindings.
  20. */
  21. isCtrlKeyCommand: function (e: SyntheticKeyboardEvent<>): boolean {
  22. return !!e.ctrlKey && !e.altKey;
  23. },
  24. isOptionKeyCommand: function (e: SyntheticKeyboardEvent<>): boolean {
  25. return isOSX && e.altKey;
  26. },
  27. usesMacOSHeuristics: function (): boolean {
  28. return isOSX;
  29. },
  30. hasCommandModifier: function (e: SyntheticKeyboardEvent<>): boolean {
  31. return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
  32. },
  33. isSoftNewlineEvent
  34. };
  35. module.exports = KeyBindingUtil;