Skip to content

Commit

Permalink
Show only git change toggle.
Browse files Browse the repository at this point in the history
  • Loading branch information
long.chau.ext committed Nov 25, 2020
1 parent 72964db commit 3f49ad4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions src/source/sources/file/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
}
10 changes: 10 additions & 0 deletions src/source/sources/file/fileSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -84,6 +85,7 @@ export class FileSource extends ExplorerSource<FileNode> {
scheme = 'file';
hlSrcId = workspace.createNameSpace('coc-explorer-file');
showHidden: boolean = this.config.get<boolean>('file.showHiddenFiles')!;
showOnlyGitChange: boolean = false;
copiedNodes: Set<FileNode> = new Set();
cutNodes: Set<FileNode> = new Set();
rootNode: FileNode = {
Expand Down Expand Up @@ -140,6 +142,10 @@ export class FileSource extends ExplorerSource<FileNode> {
);
}

isGitChange(parentNode: FileNode, filename: string): boolean {
return !!gitManager.getMixedStatus(parentNode.fullpath + '/' + filename, false);
}

getColumnConfig<T>(name: string, defaultValue?: T): T {
return this.config.get('file.column.' + name, defaultValue)!;
}
Expand Down Expand Up @@ -401,6 +407,10 @@ export class FileSource extends ExplorerSource<FileNode> {
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;
Expand Down

0 comments on commit 3f49ad4

Please sign in to comment.