diff --git a/README.md b/README.md index d8531de40..6368cc6bd 100644 --- a/README.md +++ b/README.md @@ -260,10 +260,11 @@ The following settings are supported: * `java.completion.engine`: [Experimental] Select code completion engine. Defaults to `ecj`. * `java.references.includeDeclarations`: Include declarations when finding references. Defaults to `true` * `java.jdt.ls.appcds.enabled` : [Experimental] Enable Java AppCDS (Application Class Data Sharing) for improvements to extension activation. When set to `auto`, AppCDS will be enabled in Visual Studio Code - Insiders, and for pre-release versions. - -New in 1.50.0 * `java.hover.javadoc.enabled` : Enable/disable displaying Javadoc on hover. Defaults to `true`. +New in 1.53.0 +* `java.updateImportsOnPaste.enabled` : Enable/disable auto organize imports when pasting code. Defaults to `true`. + Semantic Highlighting =============== [Semantic Highlighting](https://github.com/redhat-developer/vscode-java/wiki/Semantic-Highlighting) fixes numerous syntax highlighting issues with the default Java Textmate grammar. However, you might experience a few minor issues, particularly a delay when it kicks in, as it needs to be computed by the Java Language server, when opening a new file or when typing. Semantic highlighting can be disabled for all languages using the `editor.semanticHighlighting.enabled` setting, or for Java only using [language-specific editor settings](https://code.visualstudio.com/docs/getstarted/settings#_languagespecific-editor-settings). diff --git a/package.json b/package.json index 7dc9181c9..c7f902c98 100644 --- a/package.json +++ b/package.json @@ -1387,6 +1387,13 @@ "scope": "window", "order": 20 }, + "java.updateImportsOnPaste.enabled": { + "type": "boolean", + "default": true, + "description": "Enable/disable auto organize imports when pasting code", + "scope": "window", + "order": 25 + }, "java.sources.organizeImports.starThreshold": { "type": "integer", "description": "Specifies the number of imports added before a star-import declaration is used.", diff --git a/src/pasteAction.ts b/src/pasteAction.ts index d50755601..e5e03d9d7 100644 --- a/src/pasteAction.ts +++ b/src/pasteAction.ts @@ -14,6 +14,7 @@ export function registerCommands(languageClient: LanguageClient, context: Extens } export async function registerOrganizeImportsOnPasteCommand(): Promise { + const clipboardText: string = await env.clipboard.readText(); const editor: TextEditor = window.activeTextEditor; const documentText: string = editor.document.getText(); @@ -40,6 +41,10 @@ export async function registerOrganizeImportsOnPasteCommand(): Promise { action.then((wasApplied) => { if (wasApplied && editor.document.languageId === "java") { + const updateImportsOnPasteEnabled = workspace.getConfiguration().get("java.updateImportsOnPaste.enabled", true); + if (!updateImportsOnPasteEnabled) { + return; + } const fileURI = editor.document.uri.toString(); const hasText: boolean = documentText !== null && /\S/.test(documentText); if (hasText) {