Skip to content

Commit 465115a

Browse files
committed
feat: fixedGitStageFile
1 parent e7d91b2 commit 465115a

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@
319319
{
320320
"command": "newUntitledEditor",
321321
"title": "New Untitled Editor"
322+
},
323+
{
324+
"command": "fixedGitStageFile",
325+
"title": "Fixed Git Stage File"
322326
}
323327
],
324328
"configuration": {

src/features/gitMisc.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as vscode from 'vscode'
2+
import { registerExtensionCommand } from 'vscode-framework'
3+
import { getGitActiveRepoOrThrow } from '../git-api'
4+
5+
export default () => {
6+
registerExtensionCommand('fixedGitStageFile', async () => {
7+
const repo = getGitActiveRepoOrThrow()
8+
if (!repo) return
9+
const currentUrl = vscode.window.activeTextEditor?.document.uri
10+
if (!currentUrl) return
11+
if ([...repo.state.indexChanges, ...repo.state.workingTreeChanges, ...repo.state.mergeChanges].some(x => x.uri.fsPath === currentUrl.fsPath)) {
12+
await vscode.commands.executeCommand('git.stage')
13+
return
14+
}
15+
16+
const paths = [currentUrl.fsPath]
17+
await repo.add(paths)
18+
})
19+
}

src/features/trackPositions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default () => {
3131
let lastPosition: vscode.Position | undefined
3232

3333
const pushPosition = (kind?: OurKind, forceAdd = false) => {
34-
if (dontWriteTillNextChange) return
34+
if (dontWriteTillNextChange || !(history as any)) return
3535
const position = kind === 'focus-out' ? lastPosition : vscode.window.activeTextEditor?.selection.active
3636
const lastHistoryPos = history.at(-1)?.[0]
3737
if (!position) return

0 commit comments

Comments
 (0)