You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Monaco Editor触发函数文档位置及内置键盘命令查询求助

Monaco Editor手动触发键盘命令汇总

在React项目中使用Monaco Editor时,若需要手动触发键盘命令,官方文档相关内容较为零散,以下整理了除deleteLeft、type外常用的可通过editor.trigger('keyboard', 命令名, 参数)调用的命令:

基础编辑类命令

  • deleteRight:删除光标右侧的字符
    editor.trigger('keyboard', 'deleteRight', null)
    
  • undo:撤销上一步操作
    editor.trigger('keyboard', 'undo', null)
    
  • redo:重做已撤销的操作
    editor.trigger('keyboard', 'redo', null)
    
  • copy:复制选中内容
    editor.trigger('keyboard', 'copy', null)
    
  • paste:粘贴剪贴板内容
    editor.trigger('keyboard', 'paste', null)
    

光标移动类命令

  • cursorUp:光标向上移动一行
    editor.trigger('keyboard', 'cursorUp', null)
    
  • cursorDown:光标向下移动一行
    editor.trigger('keyboard', 'cursorDown', null)
    
  • cursorLeft:光标向左移动一个字符
    editor.trigger('keyboard', 'cursorLeft', null)
    
  • cursorRight:光标向右移动一个字符
    editor.trigger('keyboard', 'cursorRight', null)
    
  • cursorHome:光标移动到当前行开头
    editor.trigger('keyboard', 'cursorHome', null)
    
  • cursorEnd:光标移动到当前行末尾
    editor.trigger('keyboard', 'cursorEnd', null)
    

文本选择类命令

  • selectAll:选中编辑器内全部内容
    editor.trigger('keyboard', 'selectAll', null)
    
  • selectLine:选中光标所在行
    editor.trigger('keyboard', 'selectLine', null)
    

缩进调整类命令

  • indentLine:为当前行增加缩进
    editor.trigger('keyboard', 'indentLine', null)
    
  • outdentLine:为当前行减少缩进
    editor.trigger('keyboard', 'outdentLine', null)
    

注:部分命令可能需要结合编辑器当前状态(如是否有选中内容)生效,若需更全面的命令列表,可查看Monaco Editor源码中KeybindingResolver或相关命令定义文件。

内容的提问来源于stack exchange,提问作者MrBug

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 05:22:13