Skip to content

Commit

Permalink
add extra closing brace if inside quotes - closes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
austenc committed Jul 6, 2017
1 parent eb82b44 commit 91fdef6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions BladeSpacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def validSequence(self, tag, char, check='{'):
return (tag == check * 2 and (char == check or char == '-'))


# Handles {!! !!} style entries
class BladeSpacerFiveCommand(sublime_plugin.TextCommand):

def run(self, edit):
Expand Down Expand Up @@ -159,7 +160,7 @@ def run(self, edit):
self.view.insert(edit, begin - 1, ' ')
self.view.insert(edit, end, ' ')


# Handles the general {{ }} and {{{ }}}
class BladeSpacerCommand(sublime_plugin.TextCommand):

def run(self, edit):
Expand All @@ -175,6 +176,7 @@ def run(self, edit):
lastChar = self.view.substr(last - 1)
charBeforeLast = self.view.substr(last - 2)
charBeforeThat = self.view.substr(last - 3)
charAfter = self.view.substr(last + 1)

# did we type two curly braces?
if(lastChar == '{' and charBeforeLast == '{'):
Expand All @@ -198,6 +200,12 @@ def run(self, edit):
edit, last + (nextCurly - firstCurly), '}')

else:
# If we're typing this in the middle of some quotes,
# add an additional end curly brace, since sublime
# doesn't auto-close braces inside quotes all the time
if (charBeforeThat == '"' and charAfter == '"'):
self.view.insert(edit, last + 1, '}')

self.addSpaces(edit, last)

# triple {{{ }}}
Expand Down Expand Up @@ -248,7 +256,8 @@ def run(self, edit):
self.view.insert(edit, end, ' ')

def addSpaces(self, edit, pos):
# subtract current region from selection
# subtract current region from selection so we don't end up with
# two selections in some cases
self.view.sel().subtract(sublime.Region(pos, pos))

# add 2 spaces
Expand Down
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

## [Unreleased]

## v2.4.2
- Fixed automatic braces when inside a quote i.e. `<h1 class="|">` - #5

## v2.4.1
- Added support for wrapping a selection with `{!! !!}`
- Added support for wrapping a selection with `{!! !!}` - #12

## v2.4.0
- Restrict plugin keybinds to only take effect in PHP and blade files #9
Expand Down

0 comments on commit 91fdef6

Please sign in to comment.