-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcommand_replace_region.py
36 lines (27 loc) · 1.12 KB
/
command_replace_region.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import re
import sublime
import sublime_plugin
import FuzzyFilePath.common.settings as settings
class FfpReplaceRegionCommand(sublime_plugin.TextCommand):
# helper: replaces range with string
def run(self, edit, a, b, string, move_cursor=False):
if settings.get("DISABLE_KEYMAP_ACTIONS") is True:
return False
self.view.replace(edit, sublime.Region(a, b), string)
if move_cursor and settings.get("POST_INSERT_MOVE_CHARACTERS"):
self.move_skip(a + len(string))
def move_skip(self, point):
length = 0
word_region = self.view.word(point)
line_region = self.view.line(point)
post_region = sublime.Region(word_region.b, line_region.b)
post = self.view.substr(post_region)
to_move = re.search(settings.get("POST_INSERT_MOVE_CHARACTERS"), post)
if to_move:
length = len(to_move.group(0))
self.move_cursor(point + length)
def move_cursor(self, point):
self.view.sel().clear()
self.view.sel().add(sublime.Region(point))
self.view.window().focus_view(self.view)
self.view.run_command('_enter_insert_mode') # vintageous