Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vscode extensions 在vscode扩展中显示信息消息时,是否将键指定给默认按钮选项?_Vscode Extensions - Fatal编程技术网

Vscode extensions 在vscode扩展中显示信息消息时,是否将键指定给默认按钮选项?

Vscode extensions 在vscode扩展中显示信息消息时,是否将键指定给默认按钮选项?,vscode-extensions,Vscode Extensions,我正在VSCode中创建一个扩展,当您单击VSCode.window.showInformationMessage(“要关闭吗?”、“是”、“否”)中的选项“是”时,它将关闭所有打开的文本文档 按“是”按钮可以正常工作,但我希望键盘上的“回车”键也能这样做?注册命令时,我如何收听击键?可能吗 这是我现在的代码: context.subscriptions.push( vscode.commands.registerCommand( "close-tabs&quo

我正在VSCode中创建一个扩展,当您单击
VSCode.window.showInformationMessage(“要关闭吗?”、“是”、“否”)中的选项“是”时,它将关闭所有打开的文本文档

按“是”按钮可以正常工作,但我希望键盘上的“回车”键也能这样做?注册命令时,我如何收听击键?可能吗

这是我现在的代码:

  context.subscriptions.push(
    vscode.commands.registerCommand(
      "close-tabs",
      async (inputValue?: string) => {
        const { activeTextEditor } = vscode.window;

        if (!activeTextEditor) {
          vscode.window.showInformationMessage("No active text editor");
          return;
        }

        const answer = await vscode.window.showInformationMessage("Want to close tabs?", "Yes", "No");

        if (answer === "Yes") {
          vscode.commands.executeCommand("openEditors.closeAll");
        }
        // ON_ENTER: I was thinking an if case here that checks if enter has been pressed and also executes the command above? 
      }
    )
  );

再次重申。当按下“回车”键时,我如何选择“是”选项?

因为您的
信息框不是模态的,所以当它出现时不会获得焦点

恐怕您必须使其成为模态-在您的情况下,这可能是可以接受的-以获得您想要的行为:

const-answer=wait-vscode.window.showInformationMessage(“要关闭选项卡吗?”,{modal:true},“是”、“否”);

然后消息框的第一个按钮将自动获得焦点,Enter将触发它