Skip to content

Commit 4113096

Browse files
committed
Optional draggable rows
1 parent 4269237 commit 4113096

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

Source/Yasba/Views/Sieve Script/Row Token/RowToken.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,11 @@ enum RowToken: Identifiable, Equatable {
2525
default: return true
2626
}
2727
}
28+
29+
var canDrag: Bool {
30+
switch self {
31+
case .elseMarker, .endIf: return false
32+
default: return true
33+
}
34+
}
2835
}

Source/Yasba/Views/Sieve Script/SieveScriptView.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ struct SieveScriptView: View {
156156
.padding(.leading, CGFloat(indents[index]) * 24)
157157
.contentShape(Rectangle())
158158
.onHover { hovering in hoveredRow = hovering ? index : nil }
159-
.onDrag {
160-
let span = viewModel.dragSpan(at: index, in: tokens)
161-
draggedRange = span
162-
dropGapIndex = span.lowerBound
163-
return NSItemProvider(object: token.id.uuidString as NSString)
159+
.applyIf(token.canDrag) { view in
160+
view.onDrag {
161+
let span = viewModel.dragSpan(at: index, in: tokens)
162+
draggedRange = span
163+
dropGapIndex = span.lowerBound
164+
return NSItemProvider(object: token.id.uuidString as NSString)
165+
}
164166
}
165167
.onDrop(of: [UTType.utf8PlainText],
166168
delegate: UnifiedDropDelegate(target: .row(index),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import SwiftUI
2+
3+
extension View {
4+
@ViewBuilder
5+
func applyIf<T: View>(_ condition: Bool, transform: (Self) -> T) -> some View {
6+
if condition { transform(self) } else { self }
7+
}
8+
}

0 commit comments

Comments
 (0)