Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions Source/Yasba/Views/Sieve Script/Row Token/RowToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ enum RowToken: Identifiable, Equatable {
default: return true
}
}

var canDrag: Bool {
switch self {
case .elseMarker, .endIf: return false
default: return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum RowTokenToViewMapper {
case .elseMarker:
TextRowView(icon: "arrow.triangle.branch", title: "Else")
case .endIf:
EmptyView()
TextRowView(icon: "arrow.triangle.branch", title: "Endif")
case .leaf(let command):
registry.makeView(for: command)
}
Expand Down
14 changes: 7 additions & 7 deletions Source/Yasba/Views/Sieve Script/SieveScriptView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ struct SieveScriptView: View {
}
if let range = draggedRange, range.contains(index) {
EmptyView()
} else if case .endIf = token {
EmptyView()
} else {
tokenRow(index: index, token: token)
}
Expand Down Expand Up @@ -158,11 +156,13 @@ struct SieveScriptView: View {
.padding(.leading, CGFloat(indents[index]) * 24)
.contentShape(Rectangle())
.onHover { hovering in hoveredRow = hovering ? index : nil }
.onDrag {
let span = viewModel.dragSpan(at: index, in: tokens)
draggedRange = span
dropGapIndex = span.lowerBound
return NSItemProvider(object: token.id.uuidString as NSString)
.applyIf(token.canDrag) { view in
view.onDrag {
let span = viewModel.dragSpan(at: index, in: tokens)
draggedRange = span
dropGapIndex = span.lowerBound
return NSItemProvider(object: token.id.uuidString as NSString)
}
}
.onDrop(of: [UTType.utf8PlainText],
delegate: UnifiedDropDelegate(target: .row(index),
Expand Down
8 changes: 8 additions & 0 deletions Source/Yasba/Views/View+applyIf.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import SwiftUI

extension View {
@ViewBuilder
func applyIf<T: View>(_ condition: Bool, transform: (Self) -> T) -> some View {
if condition { transform(self) } else { self }
}
}
Loading