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:
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)
|
||||
return openingParenCol
|
||||
endif
|
||||
if numOpenParensBracketLine == 0 && numCloseParensBracketLine == 0
|
||||
return indent(openingBracket) + shiftwidth()
|
||||
endif
|
||||
|
||||
return indent(openingBracket)
|
||||
elseif currentCloseBrackets > currentOpenBrackets
|
||||
@@ -184,6 +187,16 @@ function! SwiftIndent(...)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
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
|
||||
" - Current line is blank, and the user presses 'o'
|
||||
return previousIndent
|
||||
|
||||
Reference in New Issue
Block a user