【问题标题】:Atom change default treeview and editor context menusAtom 更改默认树视图和编辑器上下文菜单
【发布时间】:2016-03-17 13:04:45
【问题描述】:

我正在使用 Atom 文本编辑器。我查看了配置,但没有看到可以编辑文件树和编辑器的默认上下文菜单的任何地方。

我想去掉诸如剪切、复制、粘贴和全选之类的选项。他们使我的菜单膨胀,而且我总是使用键盘。

如何从 Atom 的上下文菜单中删除项目?

【问题讨论】:

    标签: contextmenu atom-editor


    【解决方案1】:

    让我们破解 Atom!

    Atom 将编辑器的上下文菜单选项存储在atom.contextMenu.itemSets 中。我们需要做的就是在启动时循环遍历这个数组并删除我们不需要的元素。

    将此添加到您的初始化脚本 (Edit -> Open Your Init Script):

    # itemsToRemove contains commands to remove organized by menu selector
    itemsToRemove = {
        'atom-text-editor, .overlayer': [
            'core:cut',
            'core:copy',
            'core:paste',
            'core:select-all',
        ],
        '.tree-view.full-menu': [
            'tree-view:cut',
            'tree-view:copy',
            'tree-view:paste',
        ],
    }
    
    menus = atom.contextMenu.itemSets
    
    for menu in menus
        if !itemsToRemove[menu.selector]
            # This is not the menu we're looking for
            continue
    
        items = menu.items
        evilItems = itemsToRemove[menu.selector]
        i = items.length
    
        # Loop backwards because we're changing the array we're looping through
        while i--
            item = items[i]
    
            # Is it an evil item?
            if evilItems.indexOf(item.command) > -1
                console.log 'Removing: ' + item.label + ' >> ' + item.command
                # Die, evil item, DIE!
                items.splice(i, 1)
    

    【讨论】:

      猜你喜欢
      • 2022-06-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2016-02-17
      • 2012-05-06
      • 2019-11-21
      • 1970-01-01
      相关资源
      最近更新 更多