mirror of
https://github.com/keith/swift.vim.git
synced 2025-12-12 20:35:53 +01:00
Fixed indentation in block which is different from Xcode's (#159)
This commit is contained in:
@@ -54,13 +54,13 @@ class MainViewController: UIViewController, UITableViewDataSource {
|
||||
self.tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: .Fade)
|
||||
self.refreshControl.endRefreshing()
|
||||
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
|
||||
})
|
||||
})
|
||||
} else {
|
||||
println("Could not fetch posts!")
|
||||
self.refreshControl.endRefreshing()
|
||||
UIApplication.sharedApplication().networkActivityIndicatorVisible = false;
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func stylePostCellAsRead(cell: UITableViewCell) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import PlaygroundSupport
|
||||
|
||||
struct ExampleView: View {
|
||||
@State var isShowingSheet = false
|
||||
@State var isShowingSheet2 = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@@ -38,12 +39,24 @@ struct ExampleView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
Button(action: {
|
||||
print("clicked")
|
||||
isShowingSheet2 = true
|
||||
}) {
|
||||
Text("click me")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
}
|
||||
.padding(12)
|
||||
.frame(width: 200, height: 400)
|
||||
.sheet(isPresented: $isShowingSheet) {
|
||||
Text("sheet")
|
||||
}
|
||||
.sheet(isPresented: Binding(get: { isShowingSheet2 },
|
||||
set: { v in isShowingSheet2 = v }
|
||||
)) {
|
||||
Text("sheet2")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +132,6 @@ struct ViewModifierPatternView: View {
|
||||
}
|
||||
|
||||
PlaygroundPage.current.setLiveView(VStack {
|
||||
ViewModifierPatternView()
|
||||
ExampleView()
|
||||
})
|
||||
ViewModifierPatternView()
|
||||
ExampleView()
|
||||
})
|
||||
|
||||
@@ -353,10 +353,10 @@ let data = NSData(contentsOfFile: path) else
|
||||
}
|
||||
|
||||
UIView.animateWithDuration(duration, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .CurveEaseInOut, animations: {
|
||||
view.backgroundColor = UIColor.redColor()
|
||||
}, completion: { finished in
|
||||
print("indent?")
|
||||
})
|
||||
view.backgroundColor = UIColor.redColor()
|
||||
}, completion: { finished in
|
||||
print("indent?")
|
||||
})
|
||||
|
||||
// Indent last line should hold
|
||||
self.init(className: "Item", dictionary: [
|
||||
@@ -378,11 +378,11 @@ public func find(closure: @noescape Element throws -> Bool) rethrows -> Element?
|
||||
}
|
||||
|
||||
UIView.animate(withDuration: 0.2, animations: {
|
||||
self.foo.alpha = 1.0
|
||||
self.bar.alpha = 1.0
|
||||
}, completion: { _ in
|
||||
completion()
|
||||
})
|
||||
self.foo.alpha = 1.0
|
||||
self.bar.alpha = 1.0
|
||||
}, completion: { _ in
|
||||
completion()
|
||||
})
|
||||
|
||||
A.b().application(
|
||||
application, didFinishLaunchingWithOptions: launchOptions)
|
||||
@@ -397,26 +397,48 @@ struct Foo {
|
||||
}
|
||||
func caller1() {
|
||||
callee(delegate1: {
|
||||
print("caller1 delegate1")
|
||||
}) {
|
||||
print("caller1 delegate2")
|
||||
print("caller1 delegate1")
|
||||
}) {
|
||||
print("caller1 delegate2")
|
||||
}
|
||||
}
|
||||
func caller2() {
|
||||
callee(delegate1: {
|
||||
print("caller1 delegate1")
|
||||
}, delegate2: {
|
||||
print("caller1 delegate2")
|
||||
})
|
||||
print("caller1 delegate1")
|
||||
}, delegate2: {
|
||||
print("caller1 delegate2")
|
||||
})
|
||||
}
|
||||
func caller3() {
|
||||
callee(delegate1: {
|
||||
print("caller1 delegate1")
|
||||
}, delegate2: {
|
||||
print([0, 1].map {
|
||||
$0 + 1
|
||||
})
|
||||
print("caller1 delegate2")
|
||||
})
|
||||
print("caller1 delegate1")
|
||||
}, delegate2: {
|
||||
print([0, 1].map {
|
||||
$0 + 1
|
||||
})
|
||||
print("caller1 delegate2")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
func f(title: String, delegate: (Int) -> Void) {
|
||||
print(title)
|
||||
delegate(42)
|
||||
}
|
||||
}
|
||||
|
||||
Bar().f(
|
||||
title: "the title"
|
||||
) { n in
|
||||
print("n")
|
||||
}
|
||||
|
||||
func createDelegate() -> ((Int) -> Void) {
|
||||
return { n in
|
||||
print("n")
|
||||
}
|
||||
}
|
||||
|
||||
Bar().f(title: "the title", delegate: createDelegate(
|
||||
))
|
||||
|
||||
@@ -281,12 +281,7 @@ function! SwiftIndent(...)
|
||||
let numOpenParensBracketLine = s:NumberOfMatches("(", bracketLine, openingBracket)
|
||||
let numCloseParensBracketLine = s:NumberOfMatches(")", bracketLine, openingBracket)
|
||||
if numOpenParensBracketLine > numCloseParensBracketLine
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(openingParen, column)
|
||||
let openingParenCol = searchpairpos("(", "", ")", "bWn", "s:IsExcludedFromIndent()")[1]
|
||||
call cursor(line, column)
|
||||
return openingParenCol
|
||||
return indent(openingBracket)
|
||||
endif
|
||||
if numOpenParensBracketLine == 0 && numCloseParensBracketLine == 0
|
||||
return indent(openingBracket) + shiftwidth()
|
||||
@@ -309,17 +304,26 @@ function! SwiftIndent(...)
|
||||
return indent(openingParenPos[0])
|
||||
elseif numOpenParensBracketLine > numCloseParensBracketLine
|
||||
let openingParenPos = s:SearchOpeningParenPos([line("."), col(".")])
|
||||
return openingParenPos[1]
|
||||
return indent(openingParenPos[0])
|
||||
endif
|
||||
|
||||
return indent(openingBracket)
|
||||
elseif line =~ '^\s*)$'
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(line, 1)
|
||||
call cursor(clnum, 1)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
call cursor(clnum, column)
|
||||
return indent(openingParen)
|
||||
elseif line =~ '^\s*).*'
|
||||
let firstCloseParenCol = stridx(line, ')')
|
||||
let openingParenPos = s:SearchOpeningParenPos([clnum, firstCloseParenCol])
|
||||
if s:SearchOpeningParenPos(openingParenPos)[0] == 0
|
||||
return indent(openingParenPos[0])
|
||||
elseif getline(openingParenPos[0]) =~ '($'
|
||||
return indent(openingParenPos[0])
|
||||
else
|
||||
return openingParenPos[1] - 1
|
||||
endif
|
||||
else
|
||||
let dotIndent = DotIndent(line, previous, previousNum, previousIndent, numCloseBrackets, numOpenBrackets, numCloseParens, numOpenParens, clnum)
|
||||
if dotIndent != -1
|
||||
@@ -344,9 +348,9 @@ function! SwiftIndent(...)
|
||||
endif
|
||||
|
||||
if numCloseParens > numOpenParens
|
||||
let line = line(".")
|
||||
let line = previousNum
|
||||
let column = col(".")
|
||||
call cursor(line - 1, column)
|
||||
call cursor(line, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return indent(openingParen)
|
||||
@@ -370,7 +374,11 @@ function! SwiftIndent(...)
|
||||
|
||||
let previousParen = match(previous, '\v\($')
|
||||
if previousParen != -1
|
||||
return previousIndent + shiftwidth()
|
||||
if line =~ '^\s*).*'
|
||||
return previousIndent
|
||||
else
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
endif
|
||||
|
||||
let line = line(".")
|
||||
@@ -384,12 +392,8 @@ function! SwiftIndent(...)
|
||||
endif
|
||||
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(previousNum, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return openingParen + 1
|
||||
let nearestBlockStartLnum = s:SearchBackwardLineOrBlock(previousNum, '\s*[^ \t]\+')
|
||||
return indent(nearestBlockStartLnum) + shiftwidth()
|
||||
endif
|
||||
|
||||
" - Previous line has close then open braces, indent previous + 1 'sw'
|
||||
@@ -426,11 +430,14 @@ function! SwiftIndent(...)
|
||||
|
||||
" The previous line opens a closure and doesn't close it
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
return previousParen + shiftwidth()
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
call setpos(".", savePosition)
|
||||
return previousParen
|
||||
|
||||
elseif line =~ '^\s*)$'
|
||||
return previousIndent
|
||||
endif
|
||||
|
||||
return cindent
|
||||
|
||||
Reference in New Issue
Block a user