|
2 | 2 |
|
3 | 3 | import * as fs from 'fs';
|
4 | 4 | import * as path from 'path';
|
5 |
| -import { window, Uri, workspace, WorkspaceConfiguration, commands, ConfigurationTarget, env, ExtensionContext, TextEditor, Range, Disposable, WorkspaceFolder } from 'vscode'; |
| 5 | +import { window, Uri, workspace, WorkspaceConfiguration, commands, ConfigurationTarget, env, ExtensionContext, TextEditor, Range, Disposable, WorkspaceFolder, TextDocument, Position, SnippetString, TextLine } from 'vscode'; |
6 | 6 | import { Commands } from './commands';
|
7 | 7 | import { cleanWorkspaceFileName } from './extension';
|
8 | 8 | import { ensureExists, getJavaConfiguration } from './utils';
|
@@ -287,3 +287,35 @@ function unregisterGradleWrapperPromptDialog(sha256: string) {
|
287 | 287 | gradleWrapperPromptDialogs.splice(index, 1);
|
288 | 288 | }
|
289 | 289 | }
|
| 290 | + |
| 291 | +export function handleTextBlockClosing(document: TextDocument, changes: readonly import("vscode").TextDocumentContentChangeEvent[]): any { |
| 292 | + const activeTextEditor = window.activeTextEditor; |
| 293 | + const activeDocument = activeTextEditor && activeTextEditor.document; |
| 294 | + if (document !== activeDocument || changes.length === 0 || document.languageId !== 'java') { |
| 295 | + return; |
| 296 | + } |
| 297 | + const lastChange = changes[changes.length - 1]; |
| 298 | + if (lastChange.text === null || lastChange.text.length <= 0) { |
| 299 | + return; |
| 300 | + } |
| 301 | + if (lastChange.text !== '"""";') { |
| 302 | + return; |
| 303 | + } |
| 304 | + const selection = activeTextEditor.selection.active; |
| 305 | + if (selection !== null) { |
| 306 | + const start = new Position(selection.line, selection.character - 2); |
| 307 | + const end = new Position(selection.line, selection.character + 4); |
| 308 | + const range = new Range(start, end); |
| 309 | + const activeText = activeDocument.getText(range); |
| 310 | + if (activeText === '""""""') { |
| 311 | + const tabSize = <number>activeTextEditor.options.tabSize!; |
| 312 | + const tabSpaces = <boolean>activeTextEditor.options.insertSpaces!; |
| 313 | + const indentLevel = 2; |
| 314 | + const indentSize = tabSpaces ? indentLevel * tabSize : indentLevel; |
| 315 | + const repeatChar = tabSpaces ? ' ' : '\t'; |
| 316 | + const text = `\n${repeatChar.repeat(indentSize)}\$\{0\}\n${repeatChar.repeat(indentSize)}`; |
| 317 | + const position = new Position(selection.line, selection.character + 1); |
| 318 | + activeTextEditor.insertSnippet(new SnippetString(text), position); |
| 319 | + } |
| 320 | + } |
| 321 | +} |
0 commit comments