Skip to content

Commit

Permalink
Fix typo & warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ASHIJANKEN committed Apr 6, 2020
1 parent fba85d9 commit 4e3bda8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions japanesewordseparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
jp_pattern = u'[一-龠々〆ヵヶぁ-んァ-ヴア-ン゙]'
reg = re.compile(jp_pattern)


# This class detects mouse move while dragging.
# It finds the closest point in the view to the mouse location, then expands a region you selecting now.
class MouseMoveListener(sublime_plugin.EventListener):
Expand All @@ -23,7 +24,7 @@ def on_hover(self, view, point, hover_zone):
# print("point : {}".format(point))
# print("pressing : {}".format(pressing))

if pressing == True:
if pressing is True:
self.expand_region(view, point)

def expand_region(self, view, point):
Expand All @@ -50,6 +51,7 @@ def expand_region(self, view, point):
view.sel().add_all(regions)
view.add_regions("override", view.sel())


# Find a region
class DragSelectJp(sublime_plugin.TextCommand):
def run(self, edit, additive=False, subtractive=False):
Expand All @@ -58,7 +60,7 @@ def run(self, edit, additive=False, subtractive=False):

point = self.view.sel()[-1].b

if additive == False:
if additive is False:
self.view.sel().clear()

# Select a word using API
Expand All @@ -68,6 +70,7 @@ def run(self, edit, additive=False, subtractive=False):
start_region = point_seg
self.view.sel().add(point_seg)


# Find region, move cursor by arrow keys.
class KeySelectJp(sublime_plugin.TextCommand):
def run(self, edit, additive=False, subtractive=False, key='none'):
Expand All @@ -82,14 +85,14 @@ def run(self, edit, additive=False, subtractive=False, key='none'):
elif key == 'right':
tmp_cursor_pos = min(region.b + 1, self.view.size())

# Sleect a word using API
# Select a word using API
# With this way, we can use "word_separators" in "Preferences.sublime-settings."
canditate_region = self.view.word(tmp_cursor_pos)

point_seg = find_seg_en_jp(self.view, canditate_region, tmp_cursor_pos)

# if aditive is true, expand/shrink selected regions.
if additive == True:
# if additive is true, expand/shrink selected regions.
if additive is True:

if key == 'left':
region.b -= abs(point_seg.a - region.b)
Expand All @@ -109,12 +112,14 @@ def run(self, edit, additive=False, subtractive=False, key='none'):
self.view.sel().add_all(regions)
self.view.add_regions("override", self.view.sel())


# This is called when a mouse button is released.
class Released(sublime_plugin.TextCommand):
def run(self, edit):
global pressing
pressing = False


# This method finds a segment which cursor position is within, and return it.
def find_seg_en_jp(view, canditate_region, point):

Expand All @@ -138,4 +143,4 @@ def find_seg_en_jp(view, canditate_region, point):
sum_chars += len(seg)
if sum_chars >= point - canditate_region.begin():
point_seg = sublime.Region((sum_chars - len(seg)) + canditate_region.begin(), canditate_region.begin() + sum_chars)
return point_seg
return point_seg

0 comments on commit 4e3bda8

Please sign in to comment.