オリジナルアスカー...
私はエディタでデフォルトのカット/コピー/ペーストアクションをオーバーライドする必要解決策を考え出しました。ここでextension.jsで「コピー」のコードは、(私はjsのないTSを使用しています)です:
//override the editor.action.clipboardCopyAction with our own
var clipboardCopyDisposable = vscode.commands.registerTextEditorCommand('editor.action.clipboardCopyAction', overriddenClipboardCopyAction);
context.subscriptions.push(clipboardCopyDisposable);
/*
* Function that overrides the default copy behavior. We get the selection and use it, dispose of this registered
* command (returning to the default editor.action.clipboardCopyAction), invoke the default one, and then re-register it after the default completes
*/
function overriddenClipboardCopyAction(textEditor, edit, params) {
//debug
console.log("---COPY TEST---");
//use the selected text that is being copied here
getCurrentSelectionEvents(); //not shown for brevity
//dispose of the overridden editor.action.clipboardCopyAction- back to default copy behavior
clipboardCopyDisposable.dispose();
//execute the default editor.action.clipboardCopyAction to copy
vscode.commands.executeCommand("editor.action.clipboardCopyAction").then(function(){
console.log("After Copy");
//add the overridden editor.action.clipboardCopyAction back
clipboardCopyDisposable = vscode.commands.registerTextEditorCommand('editor.action.clipboardCopyAction', overriddenClipboardCopyAction);
context.subscriptions.push(clipboardCopyDisposable);
});
}
これは間違いなくは、しかし、動作するようには思えない...最善の解決策のようにを感じることはありません。コメント/提案はありますか?繰り返し登録や登録解除が発生する問題はありますか?
はい、これは私の役に立つでしょう。あなたはoverrideCommand()のドキュメントを知っていますか? 私はまだデフォルト動作を実行する必要があります:vscode.commands.executeCommand( "default:editor.action.clipboardPaste Action"); ? –