Home Download Buy Blog Forum Support

find_all_under not working as expected

find_all_under not working as expected

Postby johngallagher on Thu Nov 22, 2012 7:17 pm

Here's a little plugin I'm working on to extract a line into it's own method in ruby:

Code: Select all
import sublime, sublime_plugin

class ExtractMethodCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      s = self.view.sel()
      line = self.view.line(s[0])
      line_text = self.view.substr(line)
      self.view.erase(edit, line)
      self.view.insert(edit, line.a, "method_name__")

      method = "\ndef method_name__\n"
      method += line_text
      method += "\nend\n"
      
      last_end = self.view.find_all("^end")[-1]
      self.view.insert(edit, last_end.a, method)
      self.view.run_command("reindent", {"single_line": False})

      first_method_name = self.view.find_all("method_name__")[0]
      
      self.view.sel().clear
      self.view.sel().add(first_method_name)
      
      self.view.find_all_under


for some reason find_all_under highlights other occurrences, but when I type to replace, it only replaces the first occurrence.

I'm pretty sure I'm using the right command for this - I captured it using sublime.log_commands(True) and that's what appeared when I hit Ctrl-G

Any ideas why it's not working for me?

Build 2217
johngallagher
 
Posts: 1
Joined: Thu Nov 22, 2012 7:11 pm

Re: find_all_under not working as expected

Postby bizoo on Thu Nov 22, 2012 7:59 pm

Code: Select all
self.view.window().run_command("find_all_under")
bizoo
 
Posts: 879
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland


Return to Plugin Development

Who is online

Users browsing this forum: Exabot [Bot] and 3 guests