|
1 | 1 | import * as vscode from 'vscode'
|
2 | 2 | import { getActiveRegularEditor } from '@zardoy/vscode-utils'
|
3 | 3 | import { getExtensionCommandId, getExtensionSetting, registerExtensionCommand, VSCodeQuickPickItem } from 'vscode-framework'
|
| 4 | +import { registerTextEditorCommand } from '@zardoy/vscode-utils/build/commands' |
4 | 5 | import { showQuickPick } from '@zardoy/vscode-utils/build/quickPick'
|
5 | 6 | import _ from 'lodash'
|
6 | 7 | import { compact } from '@zardoy/utils'
|
7 | 8 | import { offsetPosition } from '@zardoy/vscode-utils/build/position'
|
| 9 | +import { defaultJsSupersetLangs } from '@zardoy/vscode-utils/build/langs' |
8 | 10 | import { RequestInputTypes, RequestOutputTypes } from '../typescript/src/ipcTypes'
|
9 | 11 | import { sendCommand } from './sendCommand'
|
10 | 12 | import { tsRangeToVscode, tsRangeToVscodeSelection, tsTextChangesToVscodeTextEdits } from './util'
|
@@ -319,6 +321,37 @@ export default () => {
|
319 | 321 | await vscode.workspace.applyEdit(edit)
|
320 | 322 | })
|
321 | 323 |
|
| 324 | + registerTextEditorCommand('wrapIntoNewTag', async (editor, edit, fallbackCommand = 'editor.emmet.action.wrapWithAbbreviation') => { |
| 325 | + const { selection } = editor |
| 326 | + if (selection.start.isEqual(selection.end)) { |
| 327 | + const range = editor.selection |
| 328 | + const selectedText = '$TM_SELECTED_TEXT' |
| 329 | + |
| 330 | + if (!defaultJsSupersetLangs.includes(editor.document.languageId)) { |
| 331 | + if (fallbackCommand) { |
| 332 | + await vscode.commands.executeCommand(fallbackCommand, ...fallbackCommand.split(' ').slice(1)) |
| 333 | + } |
| 334 | + |
| 335 | + return |
| 336 | + } |
| 337 | + |
| 338 | + const data = (await sendCommand('getNodePath', {})) ?? [] |
| 339 | + const jsxElem = [...data].reverse().find(d => ['JsxElement', 'JsxSelfClosingElement', 'JsxFragment'].includes(d.kindName)) |
| 340 | + if (!jsxElem) return |
| 341 | + const { start, end } = jsxElem |
| 342 | + const startPos = editor.document.positionAt(start) |
| 343 | + const startRange = new vscode.Range(startPos, startPos) |
| 344 | + const endPos = editor.document.positionAt(end) |
| 345 | + const endRange = new vscode.Range(endPos, endPos) |
| 346 | + editor.selection = new vscode.Selection(startRange.start, endRange.end) |
| 347 | + } |
| 348 | + |
| 349 | + const line = editor.document.lineAt(editor.selection.start.line) |
| 350 | + const currentIndent = line.text.slice(0, line.firstNonWhitespaceCharacterIndex) |
| 351 | + await editor.insertSnippet(new vscode.SnippetString(`<\${1:div}$0>\n\t$TM_SELECTED_TEXT\n</\${1:div}>`), editor.selection) |
| 352 | + return |
| 353 | + }) |
| 354 | + |
322 | 355 | // registerExtensionCommand('insertImportFlatten', () => {
|
323 | 356 | // // got -> default, got
|
324 | 357 | // type A = ts.Type
|
|
0 commit comments