、私は(getRange()
、 アンドゥを見つける)、など)(やり直し、と私はカット見つけることができません()、コピー()とペーストAPI、 とより多くの私はeditor.execCommand("cut")
を実行しようとすると、私を得ますエラー。 私を助けることができますか?ありがとう!codemerrorはCut、Copy、Paste APIを提供していますか? <a href="http://codemirror.net/doc/manual.html" rel="nofollow">http://codemirror.net/doc/manual.html</a>から
答えて
カット/コピー/ペースト用のCodeMirror APIはありません。これは、ブラウザのセキュリティ制限により、JavaScriptがプログラムによってクリップボードにアクセスすることが禁止されているためです。ペーストはプライベートデータを盗むために使用され、カット/コピーはmore elaborate attack vectorとして使用できます。
ブラウザの独自のネイティブコードがユーザーのみ、現在選択しているテキストや集中テキストフィールドに基づいて、クリップボード(キーボードショートカットやコンテキストメニュー項目)にアクセスジェスチャーを処理します。
This SO threadには、これらの制限を回避するための試行の概要があります。 CodeMirrorのアプローチは、最初の弾丸です。ユーザーのクリップボードジェスチャーが確実に機能するように非表示のテキストエリアを使用しますが、それでもプログラマティックなAPIはサポートしていません。
ただし、はです。部分的な回避策:小さなFlashウィジェットを使用してください(これは上記のスレッドの2番目の箇条書きです)。 Flash relaxes the restrictionsをコピー/カット(貼り付けはしません)してください。それでもユーザイベントによってトリガされなければなりませんが、HTML UIのボタンをクリックするようなものかもしれません。 ZeroClipboardやClippyのようなラッパーは、Flashを知らなくてもこれらの機能に簡単にアクセスできます。コピーするときにCodeMirrorから適切な文字列を引き出すために小さなグルーコードを書く必要がありますが、それほど悪くはありません。
残念ながら、CodeMirrorはAndroid/Chromeとうまく連携していないようです。具体的には、選択するロングタップが機能しないため、テキストをコピーすることはできません。 – Michael
clipboard.jsを使用すると、text()
関数を定義してCodeMirrorの内部ドキュメントの値を取得できます。
便宜上、(<textarea>
)エディタのセレクタへの参照を保存してください。
var editorSelector = '#editor' // or '#editor + .CodeMirror';
ボタンを参照して新しいClipBoard
オブジェクトをインスタンス化します。
new Clipboard('.clip-btn-native', {
text: function(trigger) {
return getCodeMirrorNative(editorSelector).getDoc().getValue();
}
});
CodeMirror
ネイティブJavaScriptを使用してインスタンスを取得します。
function getCodeMirrorNative(target) {
var _target = target;
if (typeof _target === 'string') {
_target = document.querySelector(_target);
}
if (_target === null || !_target.tagName === undefined) {
throw new Error('Element does not reference a CodeMirror instance.');
}
if (_target.className.indexOf('CodeMirror') > -1) {
return _target.CodeMirror;
}
if (_target.tagName === 'TEXTAREA') {
return _target.nextSibling.CodeMirror;
}
return null;
};
デモ
完全な参照してください。詳細なデモはJSFiddleです。
- 1. iOSのCut | Copy | Pasteメニューをローカライズする
- 2. は<a href="http://www.pygame.org/docs/ref/rect.html" rel="nofollow">documentation</a>から何か
- 3. VSTSノードAPI - 、特に<a href="https://github.com/Microsoft/vsts-node-api/blob/master/api/IdentitiesApi.ts" rel="nofollow noreferrer">Identities API</a> - 私は<a href="https://github.com/Microsoft/vsts-node-api/" rel="nofollow noreferrer">VSTS Node Api</a>といくつかの問題を抱えているアイデンティティAPI
- 4. なぜwebpack-devミドルウェアが `publicPath`設定を提供するのですか? <a href="https://github.com/webpack/webpack-dev-middleware" rel="nofollow">readme of webpack-dev-middleware</a>から
- 5. 私は<a href="https://www.primefaces.org/primeng/#/" rel="nofollow noreferrer">PrimeNG</a><p> </p><a href="https://www.primefaces.org/" rel="nofollow noreferrer">primefaces.org</a>からすべてがうまく機能している使用しています
- 6. が<a href="https://developers.google.com/awareness" rel="nofollow">official documentation</a>からの案内に従い、Googleの啓発API
- 7. ハッシュをプリセットするのはいつですか? <a href="http://perldoc.perl.org/perldata.html" rel="nofollow">perldata</a>から
- 8. @Componentデコレータは何をしていますか? <a href="https://angular.io/docs/ts/latest/api/core/index/Component-decorator.html" rel="nofollow noreferrer">official docs</a>から
- 9. はどのように正しく<a href="https://documentation.mailgun.com/api-sending.html#examples" rel="nofollow noreferrer">https://documentation.mailgun.com/api-sending.html#examples</a></p> <p>でAPIの例を提供し、私はMIMEメッセージbody.Mailgunでmailgun APIをテストしていFormDataMultiPart
- 10. Tensorflow:mnist_inference_2.cc - 署名は、私は<a href="https://tensorflow.github.io/serving/serving_advanced.html" rel="nofollow">https://tensorflow.github.io/serving/serving_advanced.html</a></p> <p>から提供例をtensorflow複製しようとしています。しかし、私はエラーを次取得
- 11. 例<a href="http://people.iola.dk/olau/flot/examples/interacting.html" rel="noreferrer">here</a>からFLOT
- 12. ruby -aコマンドラインスイッチとは何ですか? <a href="https://linux.die.net/man/1/ruby" rel="noreferrer">man</a>ページから
- 13. Appcelerator IDEを起動できませんか? <a href="http://platform.appcelerator.com" rel="nofollow noreferrer">platform.appcelerator.com</a>によって提供さ
- 14. スラックAPI(files.upload)私はスラックを介して提供さ<a href="https://api.slack.com/methods/files.upload" rel="nofollow">files.upload() API</a>を構築しようとしているが、正しい形式を理解するに苦労していますNodeJS
- 15. Akkaの俳優システムでtell()はどのように機能しますか?ドキュメント<a href="http://doc.akka.io/api/akka/2.4/#akka.actor.Actor" rel="nofollow noreferrer">here</a>と<a href="http://doc.akka.io/api/akka/2.4/#akka.actor.ActorRef" rel="nofollow noreferrer">here</a></p> <p>を見
- 16. copy paste in iterm、vim
- 17. は、私は<a href="https://redom.js.org" rel="nofollow noreferrer">redom</a>ライブラリをインポートしようとしています
- 18. の理解jQueryのAPIドキュメント構文<a href="http://api.jquery.com/on/" rel="nofollow">http://api.jquery.com/on/</a>から
- 19. は、私はPythonとSQLでc.executeからPPRINTしたいが、私は<a href="https://docs.python.org/2/library/sqlite3.html" rel="nofollow noreferrer">API documentation</a>からの
- 20. が正しくアッカは<a href="https://www.playframework.com/documentation/2.5.x/JavaStream#Chunked-responses" rel="nofollow noreferrer">Play! Framework documentation</a>で提供例を使用して
- 21. は<a href="http://developer.android.com/training/camera/photobasics.html" rel="nofollow">http://developer.android.com/training/camera/photobasics.html</a></p> <p>コードから私は、コードを使用しています
- 22. は<a href="https://openthread.io/certification/prerequisites" rel="nofollow noreferrer">OpenThread Certification Prerequisites</a>オン
- 23. PaStreamCallbackTimeInfoメンバーは<a href="http://portaudio.com/docs/v19-doxydocs/api_overview.html" rel="nofollow noreferrer">PortAudio docs</a>からすべて0
- 24. GoogleクラウドスピーチAPI Pythonのコードサンプルは、私はGoogleのスピーチAPI、<a href="https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/cloud-client/transcribe.py" rel="nofollow noreferrer">found here</a>から提供されたコードスニペットを通じて働いている可能バグ
- 25. Firefoxの/ jQueryのは、だから私は2つの画像ギャラリー、<a href="http://devkick.com/lab/galleria/" rel="nofollow noreferrer">Galleria</a>と<a href="http://leandrovieira.com/projects/jquery/lightbox/" rel="nofollow noreferrer">Lightbox</a>を結合しようとしていますimg要素
- 26. LinkedInはオフラインアクセス用のAPIを提供していますか?
- 27. React NativeはダイアログのAPIを提供していますか?
- 28. OpenWrtはパケットフィルタAPIを提供していますか?
- 29. 在庫管理システムはAPIを提供していますか?
- 30. GoogleコードはAPIを提供していますか?
いいえ、それはありません。 – Hoque
http://stackoverflow.com/questions/13929371/copy-and-paste-in-codemirror-js-embeded-in-javafx-application –