Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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.
///
/// When `nil`, then there is no tab being dragged.
Expand Down Expand Up @@ -193,6 +195,22 @@ struct EditorTabView: View {
}
}
}
.onAppear {
keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .otherMouseDown) { event in
if self.isHovering && event.type == .otherMouseDown && event.buttonNumber == 2 {
DispatchQueue.main.async {
editor.closeTab(file: tabFile)
}
}
return event
}
}
.onDisappear {
if let keyMonitor = keyMonitor {
NSEvent.removeMonitor(keyMonitor)
self.keyMonitor = nil
}
}
}

var body: some View {
Expand Down
Loading