<commit_before>/*
 * Copyright 2020 <NAME> <<EMAIL>>
 *
 * This source code is licensed under the MIT license which is detailed in the LICENSE.txt file.
 */
import Component from 'vue-class-component';
import Vue from 'vue';
import { log, getLogger } from "extraterm-logging";
import { KeybindingsKeyInput, EVENT_SELECTED, EVENT_CANCELED } from './KeyInputUi';
import { KeybindingsSet, KeybindingsBinding, CustomKeybindingsSet, CustomKeybinding } from '../../../keybindings/KeybindingsTypes';
import { TermKeyStroke } from '../../keybindings/KeyBindingsManager';
import { Emulator, Platform } from '../../emulator/Term';
import { trimBetweenTags } from 'extraterm-trim-between-tags';
import { Category, ExtensionCommandContribution } from '../../../ExtensionMetadata';

export const EVENT_START_KEY_INPUT = "start-key-input";
export const EVENT_END_KEY_INPUT = "end-key-input";

type KeybindingsKeyInputState = "read" | "edit" | "conflict";

interface CommandKeybindingInfo {
  command: string;
  baseKeybindingsList: string[];
  baseKeyStrokeList: TermKeyStroke[];

  customKeybinding: CustomKeybinding | null;
  customKeyStrokeList: TermKeyStroke[] | null;
}

const _log = getLogger("KeybindingsCategoryUi");


@Component({
  components: {
    "keybindings-key-input": KeybindingsKeyInput
  },
  props: {
    category: String,
    categoryName: String,
    baseKeybindingsSet: Object,      // KeybindingsSet,
    customKeybindingsSet: Object,   // CustomKeybindingsSet
    commands: Array,          // ExtensionCommandContribution[]
    searchText: String,
  },
  watch: {
    keybindings: {
      deep: true,
      handler: () => {},
    }
  },
  template: trimBetweenTags(`
<div>
  <h3>{{categoryName}}
    <span v-if="commands.length !== filteredCommands.length" class="badge">{{filteredCommands.length}} / {{commands.length}}</span>
  </h3>
  <table v-if="filteredCommands.length !== 0" class="width-100pc table-hover">
    <thead>
      <tr>
        <th width="50%">Command</th>
        <th width="50%">Key</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="command in filteredCommands" v-bind:key="command.command" class="command-row">
        <td :title="'Command code: ' + command.command">{{command.title}}</td>
        <td class="keybindings-key-colomn">

          <button
              v-if="hasCommandCustomKeystrokes(command.command)"
              class="microtool warning"
              title="Revert to default"
              v-on:click="revertKeys(command.command)"
            >
            <i class="fas fa-undo"></i>
          </button>

          <template v-for="(keybinding, index) in getKeystrokesForCommand(command.command)">
            <br v-if="index !== 0" />
            <div class="keycap">
              <span>{{keybinding.formatHumanReadable()}}</span>
            </div>
            &nbsp;
            <i
              v-if="termConflict(keybinding)"
              title="This may override the terminal emulation"
              class="fas fa-exclamation-triangle"
            ></i>

            <button
              v-on:click="deleteKey(command.command, keybinding)"
              class="microtool danger hover"
              title="Remove keybinding"
            >
              <i class="fas fa-times"></i>
            </button>
          </template>

          <button
              v-if="effectiveInputState(command) === 'read'"
              v-on:click="addKey(command.command)"
              class="microtool success hover"
              title="Add keybinding"
            >
            <i class="fas fa-plus"></i>
          </button>

          <keybindings-key-input
            v-if="effectiveInputState(command) === 'edit' && selectedCommand === command.command"
            v-on:${EVENT_SELECTED}="onKeyInputSelected"
            v-on:${EVENT_CANCELED}="onKeyInputCancelled">
          </keybindings-key-input>

          <template v-if="effectiveInputState(command) === 'conflict'"><commit_msg>Tweak the layout of 'conflicts' in keybindings<commit_after>/*
 * Copyright 2020 <NAME> <<EMAIL>>
 *
 * This source code is licensed under the MIT license which is detailed in the LICENSE.txt file.
 */
import Component from 'vue-class-component';
import Vue from 'vue';
import { log, getLogger } from "extraterm-logging";
import { KeybindingsKeyInput, EVENT_SELECTED, EVENT_CANCELED } from './KeyInputUi';
import { KeybindingsSet, KeybindingsBinding, CustomKeybindingsSet, CustomKeybinding } from '../../../keybindings/KeybindingsTypes';
import { TermKeyStroke } from '../../keybindings/KeyBindingsManager';
import { Emulator, Platform } from '../../emulator/Term';
import { trimBetweenTags } from 'extraterm-trim-between-tags';
import { Category, ExtensionCommandContribution } from '../../../ExtensionMetadata';

export const EVENT_START_KEY_INPUT = "start-key-input";
export const EVENT_END_KEY_INPUT = "end-key-input";

type KeybindingsKeyInputState = "read" | "edit" | "conflict";

interface CommandKeybindingInfo {
  command: string;
  baseKeybindingsList: string[];
  baseKeyStrokeList: TermKeyStroke[];

  customKeybinding: CustomKeybinding | null;
  customKeyStrokeList: TermKeyStroke[] | null;
}

const _log = getLogger("KeybindingsCategoryUi");


@Component({
  components: {
    "keybindings-key-input": KeybindingsKeyInput
  },
  props: {
    category: String,
    categoryName: String,
    baseKeybindingsSet: Object,      // KeybindingsSet,
    customKeybindingsSet: Object,   // CustomKeybindingsSet
    commands: Array,          // ExtensionCommandContribution[]
    searchText: String,
  },
  watch: {
    keybindings: {
      deep: true,
      handler: () => {},
    }
  },
  template: trimBetweenTags(`
<div>
  <h3>{{categoryName}}
    <span v-if="commands.length !== filteredCommands.length" class="badge">{{filteredCommands.length}} / {{commands.length}}</span>
  </h3>
  <table v-if="filteredCommands.length !== 0" class="width-100pc table-hover">
    <thead>
      <tr>
        <th width="50%">Command</th>
        <th width="50%">Key</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="command in filteredCommands" v-bind:key="command.command" class="command-row">
        <td :title="'Command code: ' + command.command">{{command.title}}</td>
        <td class="keybindings-key-colomn">

          <button
              v-if="hasCommandCustomKeystrokes(command.command)"
              class="microtool warning"
              title="Revert to default"
              v-on:click="revertKeys(command.command)"
            >
            <i class="fas fa-undo"></i>
          </button>

          <template v-for="(keybinding, index) in getKeystrokesForCommand(command.command)">
            <br v-if="index !== 0" />
            <div class="keycap">
              <span>{{keybinding.formatHumanReadable()}}</span>
            </div>
            &nbsp;
            <i
              v-if="termConflict(keybinding)"
              title="This may override the terminal emulation"
              class="fas fa-exclamation-triangle"
            ></i>

            <button
              v-on:click="deleteKey(command.command, keybinding)"
              class="microtool danger hover"
              title="Remove keybinding"
            >
              <i class="fas fa-times"></i>
            </button>
          </template>

          <button
              v-if="effectiveInputState(command) === 'read'"
              v-on:click="addKey(command.command)"
              class="microtool success hover"
              title="Add keybinding"
            >
            <i class="fas fa-plus"></i>
          </button>

          <keybindings-key-input
            v-if="effectiveInputState(command) === 'edit' && selectedCommand === command.command"
            v-on:${EVENT_SELECTED}="onKeyInputSelected"
            v-on:${EVENT_CANCELED}="onKeyInputCancelled">
          </keybindings-key-input>

          <template v-if="effectiveInputState(command) === 'conflict'">
            <br v-if="getKeystrokesForCommand(command.command).length !== 0"/>
{'fraction_non_alphanumeric': 0.1424295335495136, 'fraction_numerical': 0.003866300823147917, 'mean_word_length': 2.6334390575441775, 'pattern_counts': {'":': 2, '<': 96, '<?xml version=': 0, '>': 98, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2145775', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2325, 'n_words': 466}