Sublime Forum

find_all_under not working as expected

#1

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

[code]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

[/code]

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

0 Likes

#2
self.view.window().run_command("find_all_under")
0 Likes