Skip to content

Commit 4cea129

Browse files
committed
Add check So that selection With an offset of 0 Does not result in a node like ast.Store
these came up during the Re-factoring for issue #19
1 parent bc3c542 commit 4cea129

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

library/selection_node.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ def node_from_range_old(root,atok, r ):
3737

3838

3939
def node_from_range_new(root,atok,r,special = False,lenient = False):
40-
# print(" inside the new note from range\n",root)
41-
inside = lambda x,y: (y[0]<=x[0]<y[1] and y[0]<x[1]<=y[1])
40+
# notes like ast.Store result in (0,0) with atok.get_text_range()
41+
# which causes problems if the cursor is right at the beginning of the file
42+
inside = lambda x,y: (y[0]<=x[0]<y[1] and y[0]<x[1]<=y[1] and not y[0]==y[1]==0)
4243
if lenient:
43-
inside = lambda x,y: (y[0]<=x[0]<=y[1] and y[0]<=x[1]<=y[1])
44+
inside = lambda x,y: (y[0]<=x[0]<=y[1] and y[0]<=x[1]<=y[1] and not y[0]==y[1]==0)
4445
generic_fix(root,atok)
4546
# print(" the fields are now",root._fields)
4647
for child in ast.iter_child_nodes(root):

0 commit comments

Comments
 (0)