Sha256: 0009be07af3f5abc6ba9381cb7982b0272bd0ecfd5380e6e7c150b53d4612ff9

Contents?: true

Size: 1.18 KB

Versions: 36

Compression:

Stored size: 1.18 KB

Contents

module Redcar
  class Snippets
    class Explorer < FilterListDialog
      def initialize(document)
        @document = document
        super()
      end
      
      def update_list(query)
        return [] if query == ""
        matching_snippets = filter_and_rank_by(all_snippets, query, 1000) do |s| 
          display(s)
        end
        current_scope = @document.cursor_scope
        @last_list = matching_snippets.select do |snippet|
          if snippet.scope
            !!JavaMateView::ScopeMatcher.get_match(snippet.scope, current_scope)
          else
            true
          end
        end
        @last_list.map {|s| display(s) }
      end
      
      def selected(_, ix)
        if @last_list
          close
          insert_snippet(@last_list[ix])
        end
      end
      
      private
      
      def display(snippet)
        "#{snippet.bundle_name} / #{snippet.name} (#{snippet.tab_trigger}↦)"
      end
      
      def all_snippets
        Snippets.registry.snippets
      end
      
      def insert_snippet(snippet)
        controller = @document.controllers(Snippets::DocumentController).first
        controller.start_snippet!(snippet)
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
redcar-0.9.2 plugins/snippets/lib/snippets/explorer.rb
redcar-0.9.1 plugins/snippets/lib/snippets/explorer.rb
redcar-0.9.0 plugins/snippets/lib/snippets/explorer.rb
redcar-0.8.1 plugins/snippets/lib/snippets/explorer.rb
redcar-0.8 plugins/snippets/lib/snippets/explorer.rb
redcar-0.7 plugins/snippets/lib/snippets/explorer.rb
redcar-0.6.1 plugins/snippets/lib/snippets/explorer.rb
redcar-0.6 plugins/snippets/lib/snippets/explorer.rb
redcar-0.6.1dev plugins/snippets/lib/snippets/explorer.rb
redcar-0.5.1 plugins/snippets/lib/snippets/explorer.rb
redcar-0.5 plugins/snippets/lib/snippets/explorer.rb
redcar-0.5.6dev plugins/snippets/lib/snippets/explorer.rb
redcar-0.5.5dev plugins/snippets/lib/snippets/explorer.rb
redcar-0.5.4dev plugins/snippets/lib/snippets/explorer.rb
redcar-0.5.3dev plugins/snippets/lib/snippets/explorer.rb
redcar-0.5.2dev plugins/snippets/lib/snippets/explorer.rb
redcar-0.5.1dev plugins/snippets/lib/snippets/explorer.rb
redcar-0.4.1 plugins/snippets/lib/snippets/explorer.rb
redcar-0.4 plugins/snippets/lib/snippets/explorer.rb
redcar-0.3.10.1dev plugins/snippets/lib/snippets/explorer.rb