【问题标题】:Disable Jupyter Keyboard Shortcuts禁用 Jupyter 键盘快捷键
【发布时间】:2023-04-02 10:53:01
【问题描述】:

我的一个 Jupyter 笔记本使用 html <input> 标记,该标记需要输入的用户输入,但每当我在文本框中输入时,命令模式键盘快捷键就会激活。

是否可以关闭单个单元格或笔记本的键盘快捷键?

【问题讨论】:

    标签: html ipython ipython-notebook jupyter


    【解决方案1】:

    您可以使用Jupyter.keyboard_manager.disable()暂时禁用快捷键,然后使用Jupyter.keyboard_manager.enable()重新激活。

    【讨论】:

    • 这是正确答案。只需确保在调用 Jupyter.keyboard_manager.disable() 之前添加 JS 魔法(%%javascript)
    • 也可以绑定到包含html输入的(父)元素的onfocusin事件:htmlContainer.onfocusin = () => Jupyter.keyboard_manager.disable();
    • 不幸的是,重命名笔记本似乎重新启用了keyboard_manager
    • 这在小部件中无法始终如一地工作。难道我不能在文本输入小部件上设置一个简单的属性来在我输入时关闭快捷方式吗?我不明白为什么默认情况下还没有发生这种情况。
    • 我将它与 jquery 的焦点和模糊功能一起用于自定义文本区域输入(在扩展程序内),它解决了问题。
    【解决方案2】:

    您可以将此行复制粘贴到您的 custom.js 中:

    $([IPython.events]).on("app_initialized.NotebookApp", function () {
        ...
        // Starting from this line, replace 'Shift-k' with whatever 
        // shortcut you're trying to remove.
        IPython.keyboard_manager.command_shortcuts.remove_shortcut('Shift-k')
        ...
    });
    

    或者你想删除的任何快捷方式。

    来源: http://akuederle.com/customize-ipython-keymap/

    如果你想要我的 github 上的示例 custom.jsthis is mine

    【讨论】:

      【解决方案3】:

      根据the current 'Customize keymaps' docuemntation,现在可以使用~/.jupyter/nbconfig/notebook.json 文件比hlin117 的回答更简单:

      例如,要取消绑定在光标位置拆分单元格的快捷方式(Ctrl-Shift-Minus),请使用以下命令:

      // file ~/.jupyter/nbconfig/notebook.json
      {
        "keys": {
          "edit": {
            "unbind": [
              "Ctrl-Shift-Minus"
            ]
          },
        },
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-08
        • 2014-05-15
        • 2021-02-02
        相关资源
        最近更新 更多