、私は(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. ハッシュをプリセットするのはいつですか? <a href="http://perldoc.perl.org/perldata.html" rel="nofollow">perldata</a>から
- 4. 例<a href="http://people.iola.dk/olau/flot/examples/interacting.html" rel="noreferrer">here</a>からFLOT
- 5. の理解jQueryのAPIドキュメント構文<a href="http://api.jquery.com/on/" rel="nofollow">http://api.jquery.com/on/</a>から
- 6. は<a href="http://developer.android.com/training/camera/photobasics.html" rel="nofollow">http://developer.android.com/training/camera/photobasics.html</a></p> <p>コードから私は、コードを使用しています
- 7. 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要素
- 8. は私が<a href="http://livevalidation.com" rel="nofollow">livevalidation</a>プラグインを使用しています
- 9. は、私が<a href="http://apionrails.icalialabs.com/book/chapter_two" rel="nofollow">APIonRails tutorial</a>を使用しています
- 10. 在庫管理システムはAPIを提供していますか?
- 11. GoogleコードはAPIを提供していますか?
- 12. LinkedInはオフラインアクセス用のAPIを提供していますか?
- 13. PHPはSpinxクライアントAPIを提供するようにLucene Client APIを提供していますか?
- 14. Apigeeを使用してreddit JSON APIを学習する。私はどのように物語を提出しますか? <a href="https://github.com/reddit/reddit/wiki/API" rel="noreferrer">https://github.com/reddit/reddit/wiki/API</a>から
- 15. Copy/Paste OneNote 2010のデータ
- 16. <a href="http://www.mysite.com/eblasts/_ire" rel="nofollow">http://www.mysite.com/eblasts/_ire</a></p> <p>からでRewriteBase
- 17. Djangoの良いセキュリティパターンとして、本当に「エスケープ」タグを使用していますか? <a href="http://www.djangobook.com/" rel="nofollow">The Django Book</a>の<a href="http://www.djangobook.com/en/1.0/chapter19/" rel="nofollow">the security chapter</a>で
- 18. プレイタグが<a href="http://www.playframework.org/documentation/1.2.4/templates#Invoketagbody" rel="nofollow">docs</a>から身体
- 19. 一般的なエラーページMVCサービング - 私は、エラーログのELMAHを使用していますMVC2アプリでカスタムエラーページ、(<a href="http://code.google.com/p/elmah/" rel="nofollow">elmah</a>)</p> <p>にサービスを提供しようとしています404
- 20. iOSの<a href="http://developer.apple.com/library/ios/navigation/" rel="nofollow">API</a>でのiOS API
- 21. ReactiveXはリアクティブプログラミングと考えられていますか? <a href="http://reactivex.io/intro.html" rel="noreferrer">ReactiveX introduction page</a>から
- 22. は、私はSFTPを使用してファイルを転送する<a href="http://www.zehon.com/features.htm" rel="nofollow">Zehon SFTP client</a>を使用していZehonのSFTP API
- 23. OpenGL:GL_R11F_G11F_B10Fの精度は8ビットRGBイメージに適していますか? <a href="https://www.opengl.org/wiki/Image_Format" rel="nofollow">"Image Format"</a>から
- 24. 気象APIがUVインデックスを提供していますか?
- 25. 私は<a href="https://github.com/quri/react-bootstrap-datetimepicker" rel="nofollow">react datepicker</a>から日付をフォーマットしようとしています日付ピッカー
- 26. 私は次のリンク <a href="http://www.jquery-steps.com/Examples" rel="nofollow">http://www.jquery-steps.com/Examples</a></p> <p>からフォームウィザードを使用しているフォームウィザード
- 27. DVWAは、私が<a href="http://www.dvwa.co.uk/" rel="nofollow noreferrer">DVWA</a>を設定している
- 28. 私は<a href="http://isotope.metafizzy.co/docs/options.html#onlayout" rel="nofollow">http://isotope.metafizzy.co/docs/options.html#onlayout</a>を使用してい
- 29. Pythonのエラーは、<a href="http://docs.python.org/library/string.html" rel="nofollow">http://docs.python.org/library/string.html</a>から
- 30. は、コンテキストマネージャ上<a href="http://docs.python.org/2/reference/datamodel.html#object.__exit__" rel="nofollow">datamodel docs</a>からコンテキストハンドラ
いいえ、それはありません。 – Hoque
http://stackoverflow.com/questions/13929371/copy-and-paste-in-codemirror-js-embeded-in-javafx-application –