Skip to content

Commit

Permalink
Create SmartSpace.py
Browse files Browse the repository at this point in the history
  • Loading branch information
slynch8 committed Jul 23, 2024
1 parent 33d4076 commit 7687255
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions PythonScripts/SmartSpace/SmartSpace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#------------------------------------------------------------------------
import N10X
import os

#------------------------------------------------------------------------
def IsSkipChar(c):
return c == " " or c == "\t"

#------------------------------------------------------------------------
# Skip the largest possible number of spaces or tabs.
#
# @Cleanup: Merge both cases
def OnInterceptKey(key, shift, control, alt):
if key == "Left":
(x, y) = N10X.Editor.GetCursorPos()

line = N10X.Editor.GetLine(y).rstrip()
count = len(line)

if count > 0 and x > count:
N10X.Editor.SetCursorPos((0, y))
elif count > 0 and x < count and x-1 > -1 and IsSkipChar(line[x-1]):
move = True
a = 0

# Look backward, but at least 2 spaces in row
for i in range(int(x), -1, -1):
a += 1;
if not IsSkipChar(line[i-1]):
if a < 2:
move = False
break

if move:
N10X.Editor.SetCursorPos((i, y))
return True

elif key == "Right":
(x, y) = N10X.Editor.GetCursorPos()

line = N10X.Editor.GetLine(y).rstrip()
count = len(line)

if count > 0 and x < count and x+1 < count and IsSkipChar(line[x+1]):
move = True
a = 0

# Look forward, but at least 2 spaces in row
for i in range(int(x), count, 1):
a += 1;
if not IsSkipChar(line[i]):
if a < 2:
move = False
break

if move:
N10X.Editor.SetCursorPos((i, y))
return True


#------------------------------------------------------------------------
N10X.Editor.AddOnInterceptKeyFunction(OnInterceptKey)

0 comments on commit 7687255

Please sign in to comment.