Skip to content

Commit

Permalink
#8594 - Fix Copy Path on folder nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Apr 4, 2018
1 parent c8a6ce9 commit e9262fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/vs/workbench/parts/search/browser/searchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService
import { ICommandHandler } from 'vs/platform/commands/common/commands';
import { Schemas } from 'vs/base/common/network';
import { getPathLabel } from 'vs/base/common/labels';
import URI from 'vs/base/common/uri';

export function isSearchViewFocused(viewletService: IViewletService, panelService: IPanelService): boolean {
let searchView = getSearchView(viewletService, panelService);
Expand Down Expand Up @@ -635,15 +636,14 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
}
}

function fileMatchUriToString(fileMatch: FileMatch): string {
const resource = fileMatch.resource();
function uriToClipboardString(resource: URI): string {
return resource.scheme === Schemas.file ? getPathLabel(resource) : resource.toString();
}

export const copyPathCommand: ICommandHandler = (accessor, fileMatch: FileMatch) => {
export const copyPathCommand: ICommandHandler = (accessor, fileMatch: FileMatch | FolderMatch) => {
const clipboardService = accessor.get(IClipboardService);

const text = fileMatchUriToString(fileMatch);
const text = uriToClipboardString(fileMatch.resource());
clipboardService.writeText(text);
};

Expand All @@ -659,7 +659,7 @@ function fileMatchToString(fileMatch: FileMatch, maxMatches: number): { text: st
.map(matchText => ' ' + matchText);

return {
text: `${fileMatchUriToString(fileMatch)}${lineDelimiter}${matchTextRows.join(lineDelimiter)}`,
text: `${uriToClipboardString(fileMatch.resource())}${lineDelimiter}${matchTextRows.join(lineDelimiter)}`,
count: matchTextRows.length
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/parts/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
private inputPatternIncludesFocused: IContextKey<boolean>;
private firstMatchFocused: IContextKey<boolean>;
private fileMatchOrMatchFocused: IContextKey<boolean>;
private fileMatchOrFolderMatchFocus: IContextKey<boolean>;
private fileMatchFocused: IContextKey<boolean>;
private folderMatchFocused: IContextKey<boolean>;
private matchFocused: IContextKey<boolean>;
Expand Down Expand Up @@ -137,6 +138,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this.inputPatternIncludesFocused = Constants.PatternIncludesFocusedKey.bindTo(this.contextKeyService);
this.firstMatchFocused = Constants.FirstMatchFocusKey.bindTo(contextKeyService);
this.fileMatchOrMatchFocused = Constants.FileMatchOrMatchFocusKey.bindTo(contextKeyService);
this.fileMatchOrFolderMatchFocus = Constants.FileMatchOrFolderMatchFocusKey.bindTo(contextKeyService);
this.fileMatchFocused = Constants.FileFocusKey.bindTo(contextKeyService);
this.folderMatchFocused = Constants.FolderFocusKey.bindTo(contextKeyService);
this.matchFocused = Constants.MatchFocusKey.bindTo(this.contextKeyService);
Expand Down Expand Up @@ -535,6 +537,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this.fileMatchFocused.set(focus instanceof FileMatch);
this.folderMatchFocused.set(focus instanceof FolderMatch);
this.matchFocused.set(focus instanceof Match);
this.fileMatchOrFolderMatchFocus.set(focus instanceof FileMatch || focus instanceof FolderMatch);
}
}));

Expand All @@ -545,9 +548,8 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this.fileMatchFocused.reset();
this.folderMatchFocused.reset();
this.matchFocused.reset();
this.fileMatchOrFolderMatchFocus.reset();
}));


});
}

Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/parts/search/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const ReplaceActiveKey = new RawContextKey<boolean>('replaceActive', fals
export const HasSearchResults = new RawContextKey<boolean>('hasSearchResult', false);

export const FirstMatchFocusKey = new RawContextKey<boolean>('firstMatchFocus', false);
export const FileMatchOrMatchFocusKey = new RawContextKey<boolean>('fileMatchOrMatchFocus', false);
export const FileMatchOrMatchFocusKey = new RawContextKey<boolean>('fileMatchOrMatchFocus', false); // This is actually, Match or File or Folder
export const FileMatchOrFolderMatchFocusKey = new RawContextKey<boolean>('fileMatchOrFolderMatchFocus', false);
export const FileFocusKey = new RawContextKey<boolean>('fileMatchFocus', false);
export const FolderFocusKey = new RawContextKey<boolean>('folderMatchFocus', false);
export const MatchFocusKey = new RawContextKey<boolean>('matchFocus', false);
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ MenuRegistry.appendMenuItem(MenuId.SearchContext, {
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: Constants.CopyPathCommandId,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: Constants.FileFocusKey,
when: Constants.FileMatchOrFolderMatchFocusKey,
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_C,
win: {
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_C
Expand All @@ -269,7 +269,7 @@ MenuRegistry.appendMenuItem(MenuId.SearchContext, {
id: Constants.CopyPathCommandId,
title: nls.localize('copyPathLabel', "Copy Path")
},
when: Constants.FileFocusKey,
when: Constants.FileMatchOrFolderMatchFocusKey,
group: 'search_2',
order: 4
});
Expand Down

0 comments on commit e9262fb

Please sign in to comment.