How to use is-hotkey - 10 common examples

To help you get started, we’ve selected a few is-hotkey examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github howtocards / frontend / src / lib / rich-text / extensions / code-plugin / handlers / on-key-down.js View on Github external
import { isKeyHotkey } from "is-hotkey"
import { getCurrentCode } from "../utils"
import { onTab } from "./on-tab"
import { onShiftTab } from "./on-shift-tab"
import { onEnter } from "./on-enter"
import { onModEnter } from "./on-mod-enter"
import { onBackspace } from "./on-backspace"
import { onSelectAll } from "./on-select-all"

const isModA = isKeyHotkey("mod+a")
const isShiftTab = isKeyHotkey("shift+tab")
const isTab = isKeyHotkey("tab")
const isModZ = isKeyHotkey("mod+z")
const isModEnter = isKeyHotkey("mod+enter")
const isEnter = isKeyHotkey("enter")
const isBackspace = isKeyHotkey("backspace")

/**
 * User is pressing a key in the editor
 */
export function onKeyDown(opts, event, change, editor) {
  const { value } = change
  const currentCode = getCurrentCode(opts, value)

  // Inside code ?

  if (!currentCode) {
    return editor()
  }
github GitbookIO / slate-edit-code / lib / handlers / onKeyDown.js View on Github external
// @flow
import { isKeyHotkey } from 'is-hotkey';
import { type Change } from '@gitbook/slate';

import { getCurrentCode } from '../utils';
import type Options from '../options';

import onTab from './onTab';
import onShiftTab from './onShiftTab';
import onEnter from './onEnter';
import onModEnter from './onModEnter';
import onBackspace from './onBackspace';
import onSelectAll from './onSelectAll';

const isModA = isKeyHotkey('mod+a');
const isShiftTab = isKeyHotkey('shift+tab');
const isTab = isKeyHotkey('tab');
const isModEnter = isKeyHotkey('mod+enter');
const isEnter = isKeyHotkey('enter');
const isBackspace = isKeyHotkey('backspace');

/**
 * User is pressing a key in the editor
 */
function onKeyDown(
    opts: Options,
    event: *,
    change: Change,
    editor: *
): void | Change {
    const { value } = change;
github Malvid / Malvid / src / client.js View on Github external
// Parse the initial location
	parseLocation(history.location)

	// Reparse the location when the user navigates
	history.listen(parseLocation)

	const html = h(Provider, { store }, h(Main))
	const root = document.querySelector('#main')

	render(html, root)

	// Curry the hotkey string for better performance
	const isClearKey = isHotkey('esc')
	const isConfirmKey = isHotkey('enter')
	const isPrevKey = isHotkey('up')
	const isNextKey = isHotkey('down')

	const navigateTo = (nextComponent, nextTab) => {

		if (nextComponent == null) return

		location.href = createRoute(nextComponent.id, nextTab.id)

	}

	const clearFilter = () => store.dispatch(setFilter(''))
	const focusFilter = () => document.querySelector('#filter').focus()

	document.documentElement.onkeydown = (e) => {

		const state = store.getState()
		const { components, filter, currentComponent, currentTab } = enhanceState(state)
github Malvid / Malvid / src / client.js View on Github external
}

	// Parse the initial location
	parseLocation(history.location)

	// Reparse the location when the user navigates
	history.listen(parseLocation)

	const html = h(Provider, { store }, h(Main))
	const root = document.querySelector('#main')

	render(html, root)

	// Curry the hotkey string for better performance
	const isClearKey = isHotkey('esc')
	const isConfirmKey = isHotkey('enter')
	const isPrevKey = isHotkey('up')
	const isNextKey = isHotkey('down')

	const navigateTo = (nextComponent, nextTab) => {

		if (nextComponent == null) return

		location.href = createRoute(nextComponent.id, nextTab.id)

	}

	const clearFilter = () => store.dispatch(setFilter(''))
	const focusFilter = () => document.querySelector('#filter').focus()

	document.documentElement.onkeydown = (e) => {
github Malvid / Malvid / src / client.js View on Github external
// Parse the initial location
	parseLocation(history.location)

	// Reparse the location when the user navigates
	history.listen(parseLocation)

	const html = h(Provider, { store }, h(Main))
	const root = document.querySelector('#main')

	render(html, root)

	// Curry the hotkey string for better performance
	const isClearKey = isHotkey('esc')
	const isConfirmKey = isHotkey('enter')
	const isPrevKey = isHotkey('up')
	const isNextKey = isHotkey('down')

	const navigateTo = (nextComponent, nextTab) => {

		if (nextComponent == null) return

		location.href = createRoute(nextComponent.id, nextTab.id)

	}

	const clearFilter = () => store.dispatch(setFilter(''))
	const focusFilter = () => document.querySelector('#filter').focus()

	document.documentElement.onkeydown = (e) => {

		const state = store.getState()
github Malvid / Malvid / src / client.js View on Github external
}

	// Parse the initial location
	parseLocation(history.location)

	// Reparse the location when the user navigates
	history.listen(parseLocation)

	const html = h(Provider, { store }, h(Main))
	const root = document.querySelector('#main')

	render(html, root)

	// Curry the hotkey string for better performance
	const isClearKey = isHotkey('esc')
	const isConfirmKey = isHotkey('enter')
	const isPrevKey = isHotkey('up')
	const isNextKey = isHotkey('down')

	const navigateTo = (nextComponent, nextTab) => {

		if (nextComponent == null) return

		location.href = createRoute(nextComponent.id, nextTab.id)

	}

	const clearFilter = () => store.dispatch(setFilter(''))
	const focusFilter = () => document.querySelector('#filter').focus()

	document.documentElement.onkeydown = (e) => {
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / plugins / SetMarksOnKeyComboPlugin.ts View on Github external
import isKeyHotkey, {toKeyName} from 'is-hotkey'
import {SlateEditor} from '../typeDefs'

type Options = {
  decorators?: string[]
}

// This plugin makes keyboard shortcuts for decorators

const isStrongHotkey = isKeyHotkey('mod+b')
const isEmphasisHotkey = isKeyHotkey('mod+i')
const isUnderlinedHotkey = isKeyHotkey('mod+u')
const isCodeHotKey = isKeyHotkey("mod+'")

const modKeyPlatformName = toKeyName('mod')

export const keyMaps = {
  strong: `${modKeyPlatformName} + b`,
  em: `${modKeyPlatformName} + i`,
  underline: `${modKeyPlatformName} + u`,
  code: `${modKeyPlatformName} + '`
}

export default function SetMarksOnKeyComboPlugin(options: Options = {}) {
  const decorators = options.decorators || []
  return {
    onKeyDown(event: React.KeyboardEvent, editor: SlateEditor, next: (arg0: void) => void) {
      let mark
      if (isStrongHotkey(event)) {
        mark = 'strong'
      } else if (isEmphasisHotkey(event)) {
github grafana / grafana / packages / grafana-ui / src / slate-plugins / indentation.ts View on Github external
import { RangeJSON, Range as SlateRange, Editor as CoreEditor } from 'slate';
import { Plugin } from '@grafana/slate-react';
import { isKeyHotkey } from 'is-hotkey';

const isIndentLeftHotkey = isKeyHotkey('mod+[');
const isShiftTabHotkey = isKeyHotkey('shift+tab');
const isIndentRightHotkey = isKeyHotkey('mod+]');

const SLATE_TAB = '  ';

const handleTabKey = (event: KeyboardEvent, editor: CoreEditor, next: Function): void => {
  const {
    startBlock,
    endBlock,
    selection: {
      start: { offset: startOffset, key: startKey },
      end: { offset: endOffset, key: endKey },
    },
  } = editor.value;

  const first = startBlock.getFirstText();
github ianstormtaylor / slate / packages / slate-react / src / constants / hotkeys.js View on Github external
const COLLAPSE_LINE_BACKWARD_MAC = isKeyHotkey('option+up')
const COLLAPSE_LINE_FORWARD_MAC = isKeyHotkey('option+down')
const COLLAPSE_LINE_BACKWARD = e => IS_APPLE && COLLAPSE_LINE_BACKWARD_MAC(e)
const COLLAPSE_LINE_FORWARD = e => IS_APPLE && COLLAPSE_LINE_FORWARD_MAC(e)

const EXTEND_CHAR_FORWARD = isKeyHotkey('shift+right')
const EXTEND_CHAR_BACKWARD = isKeyHotkey('shift+left')

const EXTEND_LINE_BACKWARD_MAC = isKeyHotkey('option+shift+up')
const EXTEND_LINE_FORWARD_MAC = isKeyHotkey('option+shift+down')
const EXTEND_LINE_BACKWARD = e => IS_APPLE && EXTEND_LINE_BACKWARD_MAC(e)
const EXTEND_LINE_FORWARD = e => IS_APPLE && EXTEND_LINE_FORWARD_MAC(e)

const UNDO = isKeyHotkey('mod+z')
const REDO_MAC = isKeyHotkey('mod+shift+z')
const REDO_PC = isKeyHotkey('mod+y')
const REDO = e => (IS_APPLE ? REDO_MAC(e) : REDO_PC(e))

const TRANSPOSE_CHARACTER_MAC = isKeyHotkey('ctrl+t')
const TRANSPOSE_CHARACTER = e => IS_APPLE && TRANSPOSE_CHARACTER_MAC(e)

const CONTENTEDITABLE = e =>
  BOLD(e) ||
  DELETE_CHAR_BACKWARD(e) ||
  DELETE_CHAR_FORWARD(e) ||
  DELETE_LINE_BACKWARD(e) ||
  DELETE_LINE_FORWARD(e) ||
  DELETE_WORD_BACKWARD(e) ||
  DELETE_WORD_FORWARD(e) ||
  ITALIC(e) ||
  REDO(e) ||
  SPLIT_BLOCK(e) ||
github ianstormtaylor / slate / packages / slate-react / src / constants / hotkeys.js View on Github external
const DELETE_WORD_FORWARD_MAC = e =>
  isKeyHotkey('shift+option+delete', e) || isKeyHotkey('option+delete', e)
const DELETE_WORD_FORWARD_PC = isKeyHotkey('ctrl+delete')

is-hotkey

Check whether a browser event matches a hotkey.

MIT
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis