Skip to content

Commit 5f48f0a

Browse files
authored
Added closing tabs with middle click (#2127)
<!--- IMPORTANT: If this PR addresses multiple unrelated issues, it will be closed until separated. --> ### Description <!--- REQUIRED: Describe what changed in detail --> Added handling middle mouse click for closing tab ### Related Issues * closes #1986 <!--- REQUIRED: Tag all related issues (e.g. * #123) --> <!--- If this PR resolves the issue please specify (e.g. * closes #123) --> <!--- If this PR addresses multiple issues, these issues must be related to one other --> ### Checklist <!--- Add things that are not yet implemented above --> - [X] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [X] The issues this PR addresses are related to each other - [X] My changes generate no new warnings - [X] My code builds and runs on my machine - [X] My changes are all related to the related issue above - [X] I documented my code ### Screenshots <!--- REQUIRED: if issue is UI related --> <!--- IMPORTANT: Fill out all required fields. Otherwise we might close this PR temporarily -->
1 parent 82d39cc commit 5f48f0a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct EditorTabView: View {
4646
/// By default, this value is `false`. When the root view is appeared, it turns `true`.
4747
@State private var isAppeared: Bool = false
4848

49+
@State private var keyMonitor: Any?
50+
4951
/// The id associating with the tab that is currently being dragged.
5052
///
5153
/// When `nil`, then there is no tab being dragged.
@@ -193,6 +195,22 @@ struct EditorTabView: View {
193195
}
194196
}
195197
}
198+
.onAppear {
199+
keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .otherMouseDown) { event in
200+
if self.isHovering && event.type == .otherMouseDown && event.buttonNumber == 2 {
201+
DispatchQueue.main.async {
202+
editor.closeTab(file: tabFile)
203+
}
204+
}
205+
return event
206+
}
207+
}
208+
.onDisappear {
209+
if let keyMonitor = keyMonitor {
210+
NSEvent.removeMonitor(keyMonitor)
211+
self.keyMonitor = nil
212+
}
213+
}
196214
}
197215

198216
var body: some View {

0 commit comments

Comments
 (0)