Ответы пользователя по тегу Горячие клавиши
  • "Горячие клавиши" для копирования url-адреса ссылки?

    Taraflex
    @Taraflex
    Ищу работу. Контакты в профиле.
    var x = null;
    var y = null;
        
    document.addEventListener('mousemove', onMouseUpdate, false);
    document.addEventListener('mouseenter', onMouseUpdate, false);
        
    function onMouseUpdate(e) {
      x = e.clientX;
      y = e.clientY;
    }
    
    
    function contains(x,y, rect){
      return rect.left <= x && x <= rect.right && rect.top <= y && y <= rect.bottom;
    }
    
    hotkeys('ctrl+d',function(event){
    
        for(let link of Array.prototype.slice.call(document.getElementsByTagName('a')) ){
          if(contains(x, y, link.getBoundingClientRect())){
            event.preventDefault();
            event.stopImmediatePropagation();
           
            if(link.href){
              console.log(link.href);
              navigator.clipboard.writeText(link.href);
            }
           
            break;
          }
        }
    })

    https://jsfiddle.net/QW01_01/j3ydxp28/26/

    Использованы библиотеки
    https://github.com/lgarron/clipboard-polyfill
    https://github.com/jaywcjlove/hotkeys
    Ответ написан
    Комментировать
  • Sublime. Как настроить горячие клавиши?

    Taraflex
    @Taraflex Автор вопроса
    Ищу работу. Контакты в профиле.
    Решил доработкой одного маленького плагина

    UPD 17.05.2018
    import sublime
    import sublime_plugin
    
    
    class RunMultipleCommand(sublime_plugin.TextCommand):
    
        def exec_command(self, command, syntax):
            if not 'command' in command:
                raise Exception('No command name provided.')
    
            if 'syntax' in command:
                for s in command['syntax']:
                    if syntax.find(s) > -1:
                        break
                else:
                    return False
    
            args = None
            if 'args' in command:
                args = command['args']
    
            # default context is the view since it's easiest to get the other contexts
            # from the view
            context = self.view
            if 'context' in command:
                context_name = command['context']
                if context_name == 'window':
                    context = context.window()
                elif context_name == 'app':
                    context = sublime
                elif context_name == 'text':
                    pass
                else:
                    raise Exception('Invalid command context "'+context_name+'".')
    
            # skip args if not needed
            if args is None:
                context.run_command(command['command'])
            else:
                context.run_command(command['command'], args)
            return True
    
        def run(self, edit, commands=None):
            if commands is None:
                return  # not an error
            syntax = self.view.settings().get('syntax').split('/')[-1].lower()
            for command in commands:
                if self.exec_command(command, syntax) and command['end']:
                    return


    Добавил возможность обрыва цепочки команд при помощи end:true
    [
    {
        "keys": ["ctrl+d"],
        "command": "run_multiple",
        "args":
        {
            "commands": [
            {
                "syntax": ["python"],
                "command": "auto_pep8",
                "args":
                {
                    "preview": false
                },
                "end": true
            },
            {
                "syntax": ["css", "scss", "less", "sass"],
                "command": "css_comb",
                "end": true
            },
            {
                "syntax": ["php"],
                "command": "code_formatter",
                "end": true
            },
            {
                "syntax": ["html", "xml", "json"],
                "command": "htmlprettify",
                "end": true
            },
            {
                "syntax": ["javascript", "typescript"],
                "command": "typescript_format_document",
                "end": true
            }]
        }
    },
    {
        "keys": ["ctrl+shift+c"],
        "command": "color_highlighter_pick_color",
        "context": [
        {
            "key": "color_highlighter.color_highlighter_pick_color"
        }]
    }]
    Ответ написан
    1 комментарий