diff --git a/package.json b/package.json index 85bd1550..4f423092 100644 --- a/package.json +++ b/package.json @@ -887,6 +887,11 @@ "type": "boolean", "default": true }, + "explorer.git.showOnlyGitChange": { + "description": "Default show only git changed files", + "type": "boolean", + "default": false + }, "explorer.debug": { "description": "Enable debug", "type": "boolean", diff --git a/readme.md b/readme.md index a1166bfb..cd3b8493 100644 --- a/readme.md +++ b/readme.md @@ -1137,6 +1137,10 @@ Type:
string
Default:
"!"
Type:
boolean
Default:
false
+explorer.git.showOnlyGitChange: Default show only git changed files. type: boolean +Default:
false
+
+
explorer.debug: Enable debug. Type:
boolean
Default:
false
diff --git a/src/source/sources/file/fileActions.ts b/src/source/sources/file/fileActions.ts index e2091305..c02c5b30 100644 --- a/src/source/sources/file/fileActions.ts +++ b/src/source/sources/file/fileActions.ts @@ -614,4 +614,21 @@ export function initFileActions(file: FileSource) { }, 'reset file from git index', ); + + file.addNodeAction( + 'toggleOnlyGitChange', + async () => { + file.showOnlyGitChange = !file.showOnlyGitChange; + const loadNotifier = await file.loadNotifier(file.rootNode, { + force: true, + }); + + file.nvim.pauseNotification(); + file.clearHighlightsNotify(); + loadNotifier?.notify(); + await file.nvim.resumeNotification(); + }, + 'toggle visibility of git change node', + { reload: true }, + ); } diff --git a/src/source/sources/file/fileSource.ts b/src/source/sources/file/fileSource.ts index 648ce9de..64ec948e 100644 --- a/src/source/sources/file/fileSource.ts +++ b/src/source/sources/file/fileSource.ts @@ -6,6 +6,7 @@ import { argOptions } from '../../../argOptions'; import { diagnosticHighlights } from '../../../diagnostic/highlights'; import { onBufEnter } from '../../../events'; import { gitHighlights } from '../../../git/highlights'; +import { gitManager } from '../../../git/manager'; import { fileList } from '../../../lists/files'; import { fsAccess, @@ -84,6 +85,7 @@ export class FileSource extends ExplorerSource { scheme = 'file'; hlSrcId = workspace.createNameSpace('coc-explorer-file'); showHidden: boolean = this.config.get('file.showHiddenFiles')!; + showOnlyGitChange: boolean = this.config.get('git.showOnlyGitChange')!; copiedNodes: Set = new Set(); cutNodes: Set = new Set(); rootNode: FileNode = { @@ -140,6 +142,10 @@ export class FileSource extends ExplorerSource { ); } + isGitChange(parentNode: FileNode, filename: string): boolean { + return !!gitManager.getMixedStatus(parentNode.fullpath + '/' + filename, false); + } + getColumnConfig(name: string, defaultValue?: T): T { return this.config.get('file.column.' + name, defaultValue)!; } @@ -401,6 +407,10 @@ export class FileSource extends ExplorerSource { const files = await Promise.all( filenames.map(async (filename) => { try { + if (this.showOnlyGitChange && !this.isGitChange(parentNode, filename)) { + return; + } + const hidden = this.isHidden(filename); if (!this.showHidden && hidden) { return; diff --git a/src/types/pkg-config.d.ts b/src/types/pkg-config.d.ts index 4d07db78..d90e7ab1 100644 --- a/src/types/pkg-config.d.ts +++ b/src/types/pkg-config.d.ts @@ -557,6 +557,10 @@ export interface Explorer { * Show ignored files in git */ 'explorer.git.showIgnored'?: boolean; + /** + * Default show only git changed files + */ + 'explorer.git.showOnlyGitChange'?: boolean; /** * Enable debug */