ckeditor / ckeditor4

The best enterprise-grade WYSIWYG editor. Fully customizable with countless features and plugins.
https://ckeditor.com/ckeditor-4
Other
5.8k stars 2.48k forks source link

Keystroke not mapping function keys correctly #1154

Closed agustingrigoriu closed 6 years ago

agustingrigoriu commented 6 years ago

Hi, I have the following plugin:

CKEDITOR.plugins.add("audiorecorder", {
  icons: "rec,play,ff,rew,pause,stop,del",
  init: function(editor) {
    // Rew Command
    var command = editor.addCommand("rew", {
      modes: { wysiwyg: 1, source: 1 },
      exec: function(editor) {
        $(editor).trigger("rew");
      }
    });

    editor.ui.addButton("Rewind", {
      icon: "rew",
      label: "Rewind",
      command: "rew",
      toolbar: "audiorecorder, 0"
    });
    // Rec Command
    var command = editor.addCommand("rec", {
      modes: { wysiwyg: 1, source: 1 },
      exec: function(editor) {
        $(editor).trigger("rec");
      }
    });
    editor.ui.addButton("Rec", {
      icon: "rec",
      label: "Rec",
      command: "rec",
      toolbar: "audiorecorder, 1"
    });
    // Pause Command
    var command_pause = editor.addCommand("pause", {
      modes: { wysiwyg: 1, source: 1 },
      exec: function(editor) {
        $(editor).trigger("pause");
      }
    });
    editor.ui.addButton("Pause", {
      icon: "pause",
      label: "Pause",
      command: "pause",
      toolbar: "audiorecorder, 2"
    });
    // Play Command
    var command = editor.addCommand("play", {
      modes: { wysiwyg: 1, source: 1 },
      exec: function(editor) {
        $(editor).trigger("play");
      }
    });
    editor.ui.addButton("Play", {
      icon: "play",
      label: "Play",
      command: "play",
      toolbar: "audiorecorder, 3"
    });
    // FF Command
    var command = editor.addCommand("ff", {
      modes: { wysiwyg: 1, source: 1 },
      exec: function(editor) {
        $(editor).trigger("ff");
      }
    });
    editor.ui.addButton("FastForward", {
      icon: "ff",
      label: "FastForward",
      command: "ff",
      toolbar: "audiorecorder, 4"
    });
    // Del Command
    var command = editor.addCommand("del", {
      modes: { wysiwyg: 1, source: 1 },
      exec: function(editor) {
        $(editor).trigger("del");
      }
    });
    editor.ui.addButton("Delete", {
      icon: "del",
      label: "Delete",
      command: "del",
      toolbar: "audiorecorder, 5"
    });
    editor.setKeystroke(CKEDITOR.CTRL + 117, "rew");
    editor.setKeystroke(CKEDITOR.CTRL + 118, "ff");
    editor.setKeystroke(CKEDITOR.CTRL + 119, "play");
    editor.setKeystroke(CKEDITOR.CTRL + 116, "pause");
  }
});

As you can see at the end, I set the keystrokes so I can use f6,f7,f8 and f9 to pause, rew, play or pause (it doesn't matter the order). Well, the kestrokes work perfectly, but the tooltip/title for play is, for example, Play (Ctrl+w) instead of Play (Ctrl+F8) . I tried everything but I can't make it print the key correctly.

f1ames commented 6 years ago

Keystrokes are displayed using CKEDITOR.tools.keystrokeToString which uses predefined names for some special buttons and for other keys, it just uses String.fromCharCode (assuming the key is not a sepcial one, just regular alphanumerical sign). So for keycode 118 (which is F7), it simply returns u.

As function keys mapping were never supported and not used, we will treat it as a Feature Request.

f1ames commented 6 years ago

@agustingrigoriu I extracted the issue here: #1338.