Skip to content

Commit

Permalink
Improve contextual menu items for previewer (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanzhong authored Jul 22, 2023
1 parent e2fea00 commit f30139a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion MarkEditMac/Modules/Sources/Previewer/Previewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class Previewer: NSViewController {
let config: WKWebViewConfiguration = .newConfig()
config.userContentController = controller

let webView = WKWebView(frame: .zero, configuration: config)
let webView = PreviewWebView(frame: .zero, configuration: config)
webView.allowsMagnification = true
return webView
}()
Expand Down Expand Up @@ -130,3 +130,26 @@ private extension Previewer {
}
}
}

// MARK: - PreviewWebView

private final class PreviewWebView: WKWebView {
override func willOpenMenu(_ menu: NSMenu, with event: NSEvent) {
menu.items.forEach { item in
// Hide the "Reload" item because it makes the content empty
if item.identifier?.rawValue == "WKMenuItemIdentifierReload" {
item.isHidden = true
}

#if !DEBUG
// Hide the "Inspect Element" item for release builds,
// because as soon as the popover dismisses, the inspector will be closed.
if item.identifier?.rawValue == "WKMenuItemIdentifierInspectElement" {
item.isHidden = true
}
#endif
}

super.willOpenMenu(menu, with: event)
}
}

0 comments on commit f30139a

Please sign in to comment.