mirror of
https://github.com/keith/swift.vim.git
synced 2025-12-17 12:00:25 +01:00
Fix SwiftUI indentation issues (#154)
This commit is contained in:
@@ -54,13 +54,13 @@ class MainViewController: UIViewController, UITableViewDataSource {
|
|||||||
self.tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: .Fade)
|
self.tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: .Fade)
|
||||||
self.refreshControl.endRefreshing()
|
self.refreshControl.endRefreshing()
|
||||||
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
|
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
println("Could not fetch posts!")
|
println("Could not fetch posts!")
|
||||||
self.refreshControl.endRefreshing()
|
self.refreshControl.endRefreshing()
|
||||||
UIApplication.sharedApplication().networkActivityIndicatorVisible = false;
|
UIApplication.sharedApplication().networkActivityIndicatorVisible = false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func stylePostCellAsRead(cell: UITableViewCell) {
|
func stylePostCellAsRead(cell: UITableViewCell) {
|
||||||
|
|||||||
50
example/SwiftUIView.swift
Normal file
50
example/SwiftUIView.swift
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import PlaygroundSupport
|
||||||
|
|
||||||
|
struct ExampleView: View {
|
||||||
|
@State var isShowingSheet = false
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
Text("Hello, World!")
|
||||||
|
// comment
|
||||||
|
.font(.caption)
|
||||||
|
.monospaced()
|
||||||
|
// red font
|
||||||
|
.foregroundStyle(.red)
|
||||||
|
Button(action: { print("clicked") }) {
|
||||||
|
Text("click me")
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
|
||||||
|
Button(action: { isShowingSheet = true }) {
|
||||||
|
Text("show sheet")
|
||||||
|
}
|
||||||
|
Text("sample")
|
||||||
|
.overlay {
|
||||||
|
Circle()
|
||||||
|
.fill(.gray.opacity(0.25))
|
||||||
|
}
|
||||||
|
.lineLimit(2)
|
||||||
|
Text("sample2")
|
||||||
|
HStack {
|
||||||
|
ForEach(0...5, id: \.self) { n in
|
||||||
|
if n % 2 == 0 {
|
||||||
|
Text(n.description)
|
||||||
|
.foregroundStyle(.green)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Text(n.description)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(12)
|
||||||
|
.frame(width: 200, height: 400)
|
||||||
|
.sheet(isPresented: $isShowingSheet) {
|
||||||
|
Text("sheet")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PlaygroundPage.current.setLiveView(ExampleView())
|
||||||
@@ -147,6 +147,9 @@ function! SwiftIndent(...)
|
|||||||
call cursor(line, column)
|
call cursor(line, column)
|
||||||
return openingParenCol
|
return openingParenCol
|
||||||
endif
|
endif
|
||||||
|
if numOpenParensBracketLine == 0 && numCloseParensBracketLine == 0
|
||||||
|
return indent(openingBracket) + shiftwidth()
|
||||||
|
endif
|
||||||
|
|
||||||
return indent(openingBracket)
|
return indent(openingBracket)
|
||||||
elseif currentCloseBrackets > currentOpenBrackets
|
elseif currentCloseBrackets > currentOpenBrackets
|
||||||
@@ -184,6 +187,16 @@ function! SwiftIndent(...)
|
|||||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||||
call cursor(line, column)
|
call cursor(line, column)
|
||||||
return indent(openingParen)
|
return indent(openingParen)
|
||||||
|
elseif line =~ '^\s*\.' && previous !~ '^\s*\.' && numOpenParens > 0
|
||||||
|
return previousIndent + shiftwidth()
|
||||||
|
elseif previous =~ '^\s*\.'
|
||||||
|
if s:IsCommentLine(clnum) != 0
|
||||||
|
return previousIndent - shiftwidth()
|
||||||
|
elseif line =~ '^\s*\.'
|
||||||
|
return previousIndent
|
||||||
|
else
|
||||||
|
return previousIndent - shiftwidth()
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
" - Current line is blank, and the user presses 'o'
|
" - Current line is blank, and the user presses 'o'
|
||||||
return previousIndent
|
return previousIndent
|
||||||
|
|||||||
Reference in New Issue
Block a user