Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update insert constructor command #67

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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