Skip to content

Commit

Permalink
updated insert constructor property. idea for issue erichard#64
Browse files Browse the repository at this point in the history
  • Loading branch information
kkiernan committed Mar 4, 2016
1 parent e2b7b82 commit 53b8d6f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions php_companion/commands/insert_constructor_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,22 @@ def add_constructor(self, prop_name):
self.add_region(cursor_start, cursor_end)

def find_class_opening_bracket(self):
'Find the position of the opening bracket of the class block.'
pos = self.view.find(r'class\s+[0-9A-Za-z_]+', 0).end()
return self.view.find(r'\{', pos).end()
'Get current cursor position'
cursorRegion = self.view.sel()[0]

'Find all classes in this file'
classRegions = self.view.find_all(r'class\s+[0-9A-Za-z_]+', 0);

'Loop through the class regions and save their distances from the cursor'
distances = [];
for classRegion in classRegions:
distances.append(abs(cursorRegion.end() - classRegion.end()))

'Get the class region that is closest to the cursor'
closestClassRegion = classRegions[distances.index(min(distances))]

'Return the opening bracket position'
return self.view.find(r'\{', closestClassRegion.end()).end()

def find_properties(self):
'Find all the class properties defined in the current view.'
Expand Down

0 comments on commit 53b8d6f

Please sign in to comment.