2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WebView内でCommand+aなどが効かない

Last updated at Posted at 2015-08-30

素のWebViewを使うと、テキストフィールド内でのCommand+aなどが効かないらしい。

なので、WebViewを継承して、Command+aなどをハンドリングできるようにしたクラスを利用する。

import Cocoa
import WebKit

class MyWebView: WebView {
  override func performKeyEquivalent(theEvent: NSEvent) -> Bool {
    if let string = theEvent.characters {
      switch string {
      case "a":
        selectAll(self)
      case "c":
        copy(self)
      case "v":
        paste(self)
      case "x":
        cut(self)
      default:
        return super.performKeyEquivalent(theEvent)
      }
      
      return true
    }
    return super.performKeyEquivalent(theEvent)
  }
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?