File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
CodeEdit/Features/Editor/TabBar/Tabs/Tab Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ struct EditorTabView: View {
4545 ///
4646 /// By default, this value is `false`. When the root view is appeared, it turns `true`.
4747 @State private var isAppeared : Bool = false
48+
49+ @State private var keyMonitor : Any ?
4850
4951 /// The id associating with the tab that is currently being dragged.
5052 ///
@@ -194,7 +196,7 @@ struct EditorTabView: View {
194196 }
195197 }
196198 . onAppear {
197- NSEvent . addLocalMonitorForEvents ( matching: . otherMouseDown) { event in
199+ keyMonitor = NSEvent . addLocalMonitorForEvents ( matching: . otherMouseDown) { event in
198200 if self . isHovering && event. type == . otherMouseDown && event. buttonNumber == 2 {
199201 DispatchQueue . main. async {
200202 editor. closeTab ( file: tabFile)
@@ -203,6 +205,12 @@ struct EditorTabView: View {
203205 return event
204206 }
205207 }
208+ . onDisappear {
209+ if let keyMonitor = keyMonitor {
210+ NSEvent . removeMonitor ( keyMonitor)
211+ self . keyMonitor = nil
212+ }
213+ }
206214 }
207215
208216 var body : some View {
You can’t perform that action at this time.
0 commit comments