-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize smart-paste prompt and add actions for tmp file
- Loading branch information
1 parent
0144cce
commit 9a57c03
Showing
32 changed files
with
617 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { t } from '@/i18n' | ||
import * as vscode from 'vscode' | ||
|
||
export const handleCopyFileText = async (uri?: vscode.Uri) => { | ||
const targetUri = uri || vscode.window.activeTextEditor?.document.uri | ||
|
||
if (!targetUri) throw new Error(t('error.noActiveEditor')) | ||
|
||
const document = await vscode.workspace.openTextDocument(targetUri) | ||
await vscode.env.clipboard.writeText(document.getText()) | ||
vscode.window.showInformationMessage(t('info.copied')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { t } from '@/i18n' | ||
import * as vscode from 'vscode' | ||
|
||
export const handleQuickCloseFileWithoutSave = async (uri?: vscode.Uri) => { | ||
const targetUri = uri || vscode.window.activeTextEditor?.document.uri | ||
if (!targetUri) throw new Error(t('error.noActiveEditor')) | ||
|
||
const targetEditor = vscode.window.visibleTextEditors.find( | ||
editor => editor.document.uri.toString() === targetUri.toString() | ||
) | ||
|
||
let documentToClose: vscode.TextDocument | undefined | ||
|
||
if (targetEditor) { | ||
documentToClose = targetEditor.document | ||
} else { | ||
documentToClose = vscode.workspace.textDocuments.find( | ||
doc => doc.uri.toString() === targetUri.toString() | ||
) | ||
} | ||
|
||
if (!documentToClose) throw new Error(t('error.noActiveEditor')) | ||
|
||
await vscode.window.showTextDocument(documentToClose) | ||
|
||
const command = documentToClose.isDirty | ||
? 'workbench.action.revertAndCloseActiveEditor' | ||
: 'workbench.action.closeActiveEditor' | ||
|
||
await vscode.commands.executeCommand(command) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { VsCodeFS } from '@/file-utils/vscode-fs' | ||
import { t } from '@/i18n' | ||
import * as vscode from 'vscode' | ||
|
||
/** | ||
* Handles the replacement of a file with another file. | ||
* | ||
* @param fromFileUri - The file will not removed, but its content will be replaced. | ||
* @param toFileUri - The file will be removed. | ||
* @throws An error if either `fromFileUri` or `toFileUri` is not provided. | ||
*/ | ||
export const handleReplaceFile = async ( | ||
fromFileUri: vscode.Uri, | ||
toFileUri: vscode.Uri | ||
) => { | ||
if (!fromFileUri || !toFileUri) throw new Error(t('error.fileNotFound')) | ||
|
||
const toFileDocument = await vscode.workspace.openTextDocument(toFileUri) | ||
|
||
await VsCodeFS.writeFile(fromFileUri.fsPath, toFileDocument.getText(), 'utf8') | ||
|
||
vscode.window.showInformationMessage(t('info.fileReplaceSuccess')) | ||
|
||
// close the toFileUri | ||
await vscode.commands.executeCommand( | ||
'aide.quickCloseFileWithoutSave', | ||
toFileUri | ||
) | ||
|
||
// if fromFileUri is not opened, open it | ||
const fromFileDocument = await vscode.workspace.openTextDocument(fromFileUri) | ||
await vscode.window.showTextDocument(fromFileDocument) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.