I’m sorry. I had confused find_under
with find_under_expand
. As you say, both find_under
and find_under_prev
obey the wrap mode set in the find panel. But find_under_expand
does not, for some reason.
Using find_under
and find_under_prev
as primitives, I was able to write my own wrap-settings-respecting version of find_under_expand
.
I copy-paste here in case anyone has the same issue.
def copy_regions(view):
regions = view.sel()
copy = []
for r in regions:
copy.append(sublime.Region(r.a, r.b))
return copy, regions
class NoWrapFindUnderExpandCommand(sublime_plugin.TextCommand):
def run(self, edit):
def has_proper_start(a, b):
return min(a, b) == 0 or view.substr(min(a, b) - 1) not in alphanumeric
def has_proper_end(a, b):
return view.size() == max(a, b) or view.substr(max(a, b)) not in alphanumeric
def is_standalone_word(a, b):
if not has_proper_start(a, b):
return False
if not has_proper_end(a, b):
return False
return all(c in alphanumeric for c in view.substr(sublime.Region(a, b)))
alphanumeric = string.ascii_letters + '_' + string.digits
view = self.view
copy, regions = copy_regions(view)
if len(copy) > 0:
a, b = copy[-1].a, copy[-1].b
if len(copy) == 1 and a == b:
if view.substr(a - 1) not in alphanumeric:
copy[0].a = a + 1
copy[0].b = b + 1
regions.clear()
regions.add_all(copy)
view.window().run_command('find_under_prev')
return
if len(copy) > 0:
regions.clear()
regions.add(sublime.Region(a, b))
seek_standalone_word = is_standalone_word(a, b)
curx, cury = view.viewport_position()
while True:
old_a = view.sel()[-1].a
view.window().run_command('find_under')
if old_a == view.sel()[-1].a:
view.set_viewport_position((curx, cury))
drop_last_selection(view)
break
last = view.sel()[-1]
if not seek_standalone_word or is_standalone_word(last.a, last.b):
break
view.sel().add_all(copy)
EDIT: Sorry, my initial code was totally buggy… the above should at least be moderately nearer to the mark.