/********************************************************************************
 * Copyright (C) 2017 TypeFox and others.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the Eclipse
 * Public License v. 2.0 are satisfied: GNU General Public License, version 2
 * with the GNU Classpath Exception which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 ********************************************************************************/ /**
 * A Keybinding binds a specific key sequence ( Keybinding ) to trigger a command ( Keybinding ). A Keybinding optionally may
 * define a "when clause" ( Keybinding ) to specify in which context it becomes active.
 *  see KeyBindingRegistry export interface Keybinding { /**
     * Unique command identifier of the command to be triggered by this keybinding.
     */ command : string ; /**
     * The key sequence for the keybinding as defined in packages/keymaps/README.md.
     */ keybinding : string ; deprecated context ? : string ; /**
     * An optional clause defining the condition when the keybinding is active, e.g. based on the current focus.
     * See  https for more details.
      when ? : string ; /**
     * Optional arguments that will be passed to the command when it gets triggered via this keybinding.
     * Needs to be specified when the triggered command expects arguments to be passed to the command handler.
     */ args ? : any ; } export namespace Keybinding { param a param b param ignoreKeybinding param ignoreArgs export function equals ( a , b , ignoreKeybinding = false , ignoreArgs = false ) { if ( a . command === b . command && ( a . context || '' ) === ( b . context || '' ) && ( a . when || '' ) === ( b . when || '' ) && ( ignoreKeybinding || a . keybinding === b . keybinding ) && ( ignoreArgs || ( a . args || '' ) === ( b . args || '' ) ) ) { return true ; } return false ; } param binding export function apiObjectify ( binding ) { return { command : binding . command , keybinding : retrieveKeybinding ( binding ) , context : binding . context , when : binding . when , args : binding . args } ; } export function retrieveKeybinding ( binding ) { return binding . keybinding ?? binding . key ?? '' ; } param binding export function stringify ( binding ) { return JSON . stringify ( apiObjectify ( binding ) ) ; } export function is ( arg ) { return ! ! arg && arg === Object ( arg ) && 'command' in arg && 'keybinding' in arg ; } } internal export interface RawKeybinding extends Omit < Keybinding , 'keybinding' > { key : string ; } export namespace RawKeybinding { export function is ( candidate ) { return typeof candidate === 'object' && ! ! candidate && 'command' in candidate && 'key' in candidate ; } }