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 23, 2020
1 parent 72964db commit 052bc37
Show file tree
Hide file tree
Showing 5 changed files with 40 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
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,10 @@ Type: <pre><code>string</code></pre>Default: <pre><code>"!"</code></pre>
Type: <pre><code>boolean</code></pre>Default: <pre><code>false</code></pre>
</details>
<details>
<summary><code>explorer.git.showOnlyGitChange</code>: Default show only git changed files. type: <code>boolean</code></summary>
Default: <pre><code>false</code></pre>
</details>
<details>
<summary><code>explorer.debug</code>: Enable debug.</summary>
Type: <pre><code>boolean</code></pre>Default: <pre><code>false</code></pre>
</details>
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 = this.config.get<boolean>('git.showOnlyGitChange')!;
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
4 changes: 4 additions & 0 deletions src/types/pkg-config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 052bc37

Please sign in to comment.