Skip to content

Commit 7d1b4cd

Browse files
committed
修复监听点击事件问题
1 parent d82df3b commit 7d1b4cd

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

Sources/Action.swift

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ extension AttributedString {
4444
self.highlights = highlights
4545
self.callback = callback
4646
}
47+
48+
init(_ trigger: Trigger = .click, highlights: [Highlight] = .defalut) {
49+
self.trigger = trigger
50+
self.highlights = highlights
51+
self.callback = { _ in }
52+
}
4753
}
4854
}
4955

Sources/Extension/AppKit/NSTextFieldExtension.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ extension AttributedStringWrapper where Base: NSTextField {
9898

9999
default:
100100
guard let value = observation[type] else { return }
101-
base.actions[range] = .init(.click, highlights: value.0) { _ in value.1(result) }
101+
var action = Action(.click, highlights: value.0)
102+
action.handle = {
103+
value.1(result)
104+
}
105+
base.actions[range] = action
102106
}
103107
}
104108
}

Sources/Extension/UIKit/UILabelExtension.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ extension AttributedStringWrapper where Base: UILabel {
127127

128128
default:
129129
guard let value = observation[type] else { return }
130-
base.actions[range] = .init(.click, highlights: value.0) { _ in value.1(result) }
130+
var action = Action(.click, highlights: value.0)
131+
action.handle = {
132+
value.1(result)
133+
}
134+
base.actions[range] = action
131135
}
132136
}
133137
}

Sources/Extension/UIKit/UITextViewExtension.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ extension AttributedStringWrapper where Base: UITextView {
9797

9898
default:
9999
guard let value = observation[type] else { return }
100-
base.actions[range] = .init(.click, highlights: value.0) { _ in value.1(result) }
100+
var action = Action(.click, highlights: value.0)
101+
action.handle = {
102+
value.1(result)
103+
}
104+
base.actions[range] = action
101105
}
102106
}
103107
}

0 commit comments

Comments
 (0)