From 2701e6b74cbc01f298522d5b5f2cee8c7bc2bb28 Mon Sep 17 00:00:00 2001 From: Kirill Gusev Date: Sat, 6 Sep 2025 20:15:56 +0300 Subject: [PATCH 1/3] Added closing tabs with middle click --- .../Editor/TabBar/Tabs/Tab/EditorTabView.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift b/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift index 5ba88387be..9e900646f1 100644 --- a/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift +++ b/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift @@ -193,6 +193,16 @@ struct EditorTabView: View { } } } + .onAppear { + NSEvent.addLocalMonitorForEvents(matching: .otherMouseDown) { event in + if self.isHovering && event.type == .otherMouseDown && event.buttonNumber == 2 { + DispatchQueue.main.async { + editor.closeTab(file: tabFile) + } + } + return event + } + } } var body: some View { From f6c9e540d70bc32952575c4ac9ac35f15c58a8f1 Mon Sep 17 00:00:00 2001 From: Kirill Gusev Date: Wed, 10 Sep 2025 21:52:12 +0300 Subject: [PATCH 2/3] clean monitor onDisappear --- .../Editor/TabBar/Tabs/Tab/EditorTabView.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift b/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift index 9e900646f1..c974e2ff32 100644 --- a/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift +++ b/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift @@ -45,6 +45,8 @@ struct EditorTabView: View { /// /// By default, this value is `false`. When the root view is appeared, it turns `true`. @State private var isAppeared: Bool = false + + @State private var keyMonitor: Any? /// The id associating with the tab that is currently being dragged. /// @@ -194,7 +196,7 @@ struct EditorTabView: View { } } .onAppear { - NSEvent.addLocalMonitorForEvents(matching: .otherMouseDown) { event in + keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .otherMouseDown) { event in if self.isHovering && event.type == .otherMouseDown && event.buttonNumber == 2 { DispatchQueue.main.async { editor.closeTab(file: tabFile) @@ -203,6 +205,12 @@ struct EditorTabView: View { return event } } + .onDisappear { + if let keyMonitor = keyMonitor { + NSEvent.removeMonitor(keyMonitor) + self.keyMonitor = nil + } + } } var body: some View { From fbc47d0f846eb7150c520113c143caa1ee8c72cb Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Thu, 11 Sep 2025 12:59:00 -0500 Subject: [PATCH 3/3] fix:lint --- CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift b/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift index c974e2ff32..073ceb757e 100644 --- a/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift +++ b/CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift @@ -45,7 +45,7 @@ struct EditorTabView: View { /// /// By default, this value is `false`. When the root view is appeared, it turns `true`. @State private var isAppeared: Bool = false - + @State private var keyMonitor: Any? /// The id associating with the tab that is currently being dragged.