mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Revert "Introduce share links in more places via a contrib" (#177328)
Revert "Introduce share links in more places via a contrib (#177311)"
This reverts commit e9ff97aa0f
.
This commit is contained in:
parent
4c53c189a1
commit
1db217a0e2
|
@ -194,10 +194,6 @@
|
|||
"name": "vs/workbench/contrib/searchEditor",
|
||||
"project": "vscode-workbench"
|
||||
},
|
||||
{
|
||||
"name": "vs/workbench/contrib/share",
|
||||
"project": "vscode-workbench"
|
||||
},
|
||||
{
|
||||
"name": "vs/workbench/contrib/snippets",
|
||||
"project": "vscode-workbench"
|
||||
|
|
|
@ -38,13 +38,16 @@
|
|||
},
|
||||
{
|
||||
"command": "github.copyVscodeDevLink",
|
||||
"enablement": "github.hasGitHubRepo && resourceScheme != untitled && remoteName != 'codespaces'",
|
||||
"title": "Copy vscode.dev Link"
|
||||
},
|
||||
{
|
||||
"command": "github.copyVscodeDevLinkFile",
|
||||
"title": "Copy vscode.dev Link"
|
||||
},
|
||||
{
|
||||
"command": "github.copyVscodeDevLinkWithoutRange",
|
||||
"title": "Copy vscode.dev Link"
|
||||
},
|
||||
{
|
||||
"command": "github.openOnVscodeDev",
|
||||
"title": "Open in vscode.dev",
|
||||
|
@ -74,24 +77,56 @@
|
|||
"command": "github.copyVscodeDevLinkFile",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "github.copyVscodeDevLinkWithoutRange",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "github.openOnVscodeDev",
|
||||
"when": "false"
|
||||
}
|
||||
],
|
||||
"share": [
|
||||
{
|
||||
"command": "github.copyVscodeDevLink",
|
||||
"title": "Copy vscode.dev Link"
|
||||
}
|
||||
],
|
||||
"file/share": [
|
||||
{
|
||||
"command": "github.copyVscodeDevLinkFile",
|
||||
"when": "github.hasGitHubRepo && remoteName != 'codespaces'",
|
||||
"group": "0_vscode@0"
|
||||
}
|
||||
],
|
||||
"editor/context/share": [
|
||||
{
|
||||
"command": "github.copyVscodeDevLink",
|
||||
"when": "github.hasGitHubRepo && resourceScheme != untitled && remoteName != 'codespaces'",
|
||||
"group": "0_vscode@0"
|
||||
}
|
||||
],
|
||||
"explorer/context/share": [
|
||||
{
|
||||
"command": "github.copyVscodeDevLinkWithoutRange",
|
||||
"when": "github.hasGitHubRepo && resourceScheme != untitled && remoteName != 'codespaces'",
|
||||
"group": "0_vscode@0"
|
||||
}
|
||||
],
|
||||
"editor/lineNumber/context": [
|
||||
{
|
||||
"command": "github.copyVscodeDevLink",
|
||||
"when": "github.hasGitHubRepo && resourceScheme != untitled && activeEditor == workbench.editors.files.textFileEditor && config.editor.lineNumbers == on && remoteName != 'codespaces'",
|
||||
"group": "1_cutcopypaste@2"
|
||||
},
|
||||
{
|
||||
"command": "github.copyVscodeDevLink",
|
||||
"when": "github.hasGitHubRepo && resourceScheme != untitled && activeEditor == workbench.editor.notebook && remoteName != 'codespaces'",
|
||||
"group": "1_cutcopypaste@2"
|
||||
}
|
||||
],
|
||||
"editor/title/context/share": [
|
||||
{
|
||||
"command": "github.copyVscodeDevLinkWithoutRange",
|
||||
"when": "github.hasGitHubRepo && resourceScheme != untitled && remoteName != 'codespaces'",
|
||||
"group": "0_vscode@0"
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
"configuration": [
|
||||
{
|
||||
|
|
|
@ -45,10 +45,7 @@ export function registerCommands(gitAPI: GitAPI): vscode.Disposable {
|
|||
}
|
||||
}));
|
||||
|
||||
disposables.add(vscode.commands.registerCommand('github.copyVscodeDevLink', async (context: LinkContext, ranges?: vscode.Range[]) => {
|
||||
if (Array.isArray(ranges) && ranges.every((range) => 'start' in range && 'end' in range) && context instanceof vscode.Uri) {
|
||||
context = { uri: context, ranges };
|
||||
}
|
||||
disposables.add(vscode.commands.registerCommand('github.copyVscodeDevLink', async (context: LinkContext) => {
|
||||
return copyVscodeDevLink(gitAPI, true, context);
|
||||
}));
|
||||
|
||||
|
@ -56,6 +53,10 @@ export function registerCommands(gitAPI: GitAPI): vscode.Disposable {
|
|||
return copyVscodeDevLink(gitAPI, false, context);
|
||||
}));
|
||||
|
||||
disposables.add(vscode.commands.registerCommand('github.copyVscodeDevLinkWithoutRange', async (context: LinkContext) => {
|
||||
return copyVscodeDevLink(gitAPI, true, context, false);
|
||||
}));
|
||||
|
||||
disposables.add(vscode.commands.registerCommand('github.openOnVscodeDev', async () => {
|
||||
return openVscodeDevLink(gitAPI);
|
||||
}));
|
||||
|
|
|
@ -40,41 +40,27 @@ interface INotebookPosition {
|
|||
range: vscode.Range | undefined;
|
||||
}
|
||||
|
||||
interface EditorContext {
|
||||
uri: vscode.Uri;
|
||||
ranges: vscode.Range[];
|
||||
}
|
||||
|
||||
interface EditorLineNumberContext {
|
||||
uri: vscode.Uri;
|
||||
lineNumber: number;
|
||||
}
|
||||
export type LinkContext = vscode.Uri | EditorLineNumberContext | undefined;
|
||||
|
||||
interface ScmResourceContext {
|
||||
resourceUri: vscode.Uri;
|
||||
}
|
||||
|
||||
export type LinkContext = vscode.Uri | EditorContext | EditorLineNumberContext | undefined | ScmResourceContext;
|
||||
|
||||
function extractContext(context: LinkContext): { fileUri: vscode.Uri | undefined; ranges: vscode.Range[] | undefined } {
|
||||
function extractContext(context: LinkContext): { fileUri: vscode.Uri | undefined; lineNumber: number | undefined } {
|
||||
if (context instanceof vscode.Uri) {
|
||||
return { fileUri: context, ranges: undefined };
|
||||
} else if (context !== undefined && 'ranges' in context && 'uri' in context) {
|
||||
return { fileUri: context.uri, ranges: context.ranges };
|
||||
return { fileUri: context, lineNumber: undefined };
|
||||
} else if (context !== undefined && 'lineNumber' in context && 'uri' in context) {
|
||||
return { fileUri: context.uri, ranges: [new vscode.Range(context.lineNumber - 1, 0, context.lineNumber - 1, 1)] };
|
||||
} else if (context !== undefined && 'resourceUri' in context) {
|
||||
return { fileUri: context.resourceUri, ranges: undefined };
|
||||
return { fileUri: context.uri, lineNumber: context.lineNumber };
|
||||
} else {
|
||||
return { fileUri: undefined, ranges: undefined };
|
||||
return { fileUri: undefined, lineNumber: undefined };
|
||||
}
|
||||
}
|
||||
|
||||
function getFileAndPosition(context: LinkContext): IFilePosition | INotebookPosition | undefined {
|
||||
let range: vscode.Range | undefined;
|
||||
|
||||
const { fileUri, ranges: selections } = extractContext(context);
|
||||
const uri = fileUri;
|
||||
const { fileUri, lineNumber } = extractContext(context);
|
||||
const uri = fileUri ?? vscode.window.activeTextEditor?.document.uri;
|
||||
|
||||
if (uri) {
|
||||
if (uri.scheme === 'vscode-notebook-cell' && vscode.window.activeNotebookEditor?.notebook.uri.fsPath === uri.fsPath) {
|
||||
|
@ -83,11 +69,11 @@ function getFileAndPosition(context: LinkContext): IFilePosition | INotebookPosi
|
|||
const cell = vscode.window.activeNotebookEditor.notebook.getCells().find(cell => cell.document.uri.fragment === uri?.fragment);
|
||||
const cellIndex = cell?.index ?? vscode.window.activeNotebookEditor.selection.start;
|
||||
|
||||
const range = selections?.[0];
|
||||
const range = getRangeOrSelection(lineNumber);
|
||||
return { type: LinkType.Notebook, uri, cellIndex, range };
|
||||
} else {
|
||||
// the active editor is a text editor
|
||||
range = selections?.[0];
|
||||
range = getRangeOrSelection(lineNumber);
|
||||
return { type: LinkType.File, uri, range };
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +86,12 @@ function getFileAndPosition(context: LinkContext): IFilePosition | INotebookPosi
|
|||
return undefined;
|
||||
}
|
||||
|
||||
function getRangeOrSelection(lineNumber: number | undefined) {
|
||||
return lineNumber !== undefined && (!vscode.window.activeTextEditor || vscode.window.activeTextEditor.selection.isEmpty || !vscode.window.activeTextEditor.selection.contains(new vscode.Position(lineNumber - 1, 0)))
|
||||
? new vscode.Range(lineNumber - 1, 0, lineNumber - 1, 1)
|
||||
: vscode.window.activeTextEditor?.selection;
|
||||
}
|
||||
|
||||
function rangeString(range: vscode.Range | undefined) {
|
||||
if (!range) {
|
||||
return '';
|
||||
|
@ -130,7 +122,10 @@ export function notebookCellRangeString(index: number | undefined, range: vscode
|
|||
export function getLink(gitAPI: GitAPI, useSelection: boolean, hostPrefix?: string, linkType: 'permalink' | 'headlink' = 'permalink', context?: LinkContext, useRange?: boolean): string | undefined {
|
||||
hostPrefix = hostPrefix ?? 'https://github.com';
|
||||
const fileAndPosition = getFileAndPosition(context);
|
||||
const uri = fileAndPosition?.uri;
|
||||
if (!fileAndPosition) {
|
||||
return;
|
||||
}
|
||||
const uri = fileAndPosition.uri;
|
||||
|
||||
// Use the first repo if we cannot determine a repo from the uri.
|
||||
const gitRepo = (uri ? getRepositoryForFile(gitAPI, uri) : gitAPI.repositories[0]) ?? gitAPI.repositories[0];
|
||||
|
@ -155,10 +150,9 @@ export function getLink(gitAPI: GitAPI, useSelection: boolean, hostPrefix?: stri
|
|||
}
|
||||
|
||||
const blobSegment = (gitRepo.state.HEAD?.ahead === 0) ? `/blob/${linkType === 'headlink' ? gitRepo.state.HEAD.name : gitRepo.state.HEAD?.commit}` : '';
|
||||
const fileSegments = fileAndPosition && uri ? (fileAndPosition.type === LinkType.File
|
||||
const fileSegments = fileAndPosition.type === LinkType.File
|
||||
? (useSelection ? `${uri.path.substring(gitRepo.rootUri.path.length)}${useRange ? rangeString(fileAndPosition.range) : ''}` : '')
|
||||
: (useSelection ? `${uri.path.substring(gitRepo.rootUri.path.length)}${useRange ? notebookCellRangeString(fileAndPosition.cellIndex, fileAndPosition.range) : ''}` : ''))
|
||||
: '';
|
||||
: (useSelection ? `${uri.path.substring(gitRepo.rootUri.path.length)}${useRange ? notebookCellRangeString(fileAndPosition.cellIndex, fileAndPosition.range) : ''}` : '');
|
||||
|
||||
return `${hostPrefix}/${repo.owner}/${repo.repo}${blobSegment
|
||||
}${fileSegments}`;
|
||||
|
|
|
@ -16,6 +16,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
|||
import * as nls from 'vs/nls';
|
||||
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
|
||||
|
@ -107,6 +108,9 @@ export const CopyAction = supportsCopy ? registerCommand(new MultiCommand({
|
|||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarEditMenu, { submenu: MenuId.MenubarCopy, title: { value: nls.localize('copy as', "Copy As"), original: 'Copy As', }, group: '2_ccp', order: 3 });
|
||||
MenuRegistry.appendMenuItem(MenuId.EditorContext, { submenu: MenuId.EditorContextCopy, title: { value: nls.localize('copy as', "Copy As"), original: 'Copy As', }, group: CLIPBOARD_CONTEXT_MENU_GROUP, order: 3 });
|
||||
MenuRegistry.appendMenuItem(MenuId.EditorContext, { submenu: MenuId.EditorContextShare, title: { value: nls.localize('share', "Share"), original: 'Share', }, group: '11_share', order: -1, when: ContextKeyExpr.and(ContextKeyExpr.notEquals('resourceScheme', 'output'), EditorContextKeys.editorTextFocus) });
|
||||
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { submenu: MenuId.EditorTitleContextShare, title: { value: nls.localize('share', "Share"), original: 'Share', }, group: '11_share', order: -1 });
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, { submenu: MenuId.ExplorerContextShare, title: { value: nls.localize('share', "Share"), original: 'Share', }, group: '11_share', order: -1 });
|
||||
|
||||
export const PasteAction = supportsPaste ? registerCommand(new MultiCommand({
|
||||
id: 'editor.action.clipboardPasteAction',
|
||||
|
|
|
@ -161,18 +161,7 @@ export class ContextMenuController implements IEditorContribution {
|
|||
|
||||
// get menu groups
|
||||
const menu = this._menuService.createMenu(menuId, this._contextKeyService);
|
||||
const groups = menu.getActions({
|
||||
arg: [model.uri, this._editor.getSelections()?.map((selection) => ({
|
||||
start: {
|
||||
line: selection.getStartPosition().lineNumber - 1,
|
||||
character: selection.getStartPosition().column
|
||||
},
|
||||
end: {
|
||||
line: selection.getEndPosition().lineNumber - 1,
|
||||
character: selection.getEndPosition().column
|
||||
}
|
||||
}))]
|
||||
});
|
||||
const groups = menu.getActions({ arg: model.uri });
|
||||
menu.dispose();
|
||||
|
||||
// translate them into other actions
|
||||
|
|
|
@ -98,18 +98,15 @@ export class MenuId {
|
|||
static readonly MenubarViewMenu = new MenuId('MenubarViewMenu');
|
||||
static readonly MenubarHomeMenu = new MenuId('MenubarHomeMenu');
|
||||
static readonly OpenEditorsContext = new MenuId('OpenEditorsContext');
|
||||
static readonly OpenEditorsContextShare = new MenuId('OpenEditorsContextShare');
|
||||
static readonly ProblemsPanelContext = new MenuId('ProblemsPanelContext');
|
||||
static readonly SCMChangeContext = new MenuId('SCMChangeContext');
|
||||
static readonly SCMResourceContext = new MenuId('SCMResourceContext');
|
||||
static readonly SCMResourceContextShare = new MenuId('SCMResourceContextShare');
|
||||
static readonly SCMResourceFolderContext = new MenuId('SCMResourceFolderContext');
|
||||
static readonly SCMResourceGroupContext = new MenuId('SCMResourceGroupContext');
|
||||
static readonly SCMSourceControl = new MenuId('SCMSourceControl');
|
||||
static readonly SCMTitle = new MenuId('SCMTitle');
|
||||
static readonly SearchContext = new MenuId('SearchContext');
|
||||
static readonly SearchActionMenu = new MenuId('SearchActionContext');
|
||||
static readonly Share = new MenuId('Share');
|
||||
static readonly StatusBarWindowIndicatorMenu = new MenuId('StatusBarWindowIndicatorMenu');
|
||||
static readonly StatusBarRemoteIndicatorMenu = new MenuId('StatusBarRemoteIndicatorMenu');
|
||||
static readonly StickyScrollContext = new MenuId('StickyScrollContext');
|
||||
|
@ -480,9 +477,7 @@ export class MenuItemAction implements IAction {
|
|||
run(...args: any[]): Promise<void> {
|
||||
let runArgs: any[] = [];
|
||||
|
||||
if (this._options?.arg && Array.isArray(this._options.arg)) {
|
||||
runArgs = [...runArgs, ...this._options.arg];
|
||||
} else if (this._options?.arg) {
|
||||
if (this._options?.arg) {
|
||||
runArgs = [...runArgs, this._options.arg];
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,9 @@ export class EditorLineNumberContextMenu extends Disposable implements IEditorCo
|
|||
actions.push(collectedActions);
|
||||
}
|
||||
|
||||
const menuActions = menu.getActions({ arg: { lineNumber, uri: model.uri }, shouldForwardArgs: true });
|
||||
actions.push(...menuActions.map(a => a[1]));
|
||||
|
||||
// if the current editor selections do not contain the target line number,
|
||||
// set the selection to the clicked line number
|
||||
if (e.target.type === MouseTargetType.GUTTER_LINE_NUMBERS) {
|
||||
|
@ -104,24 +107,11 @@ export class EditorLineNumberContextMenu extends Disposable implements IEditorCo
|
|||
}
|
||||
}
|
||||
|
||||
const ranges = this.editor.getSelections()?.map((selection) => ({
|
||||
start: {
|
||||
line: selection.getStartPosition().lineNumber - 1,
|
||||
character: selection.getStartPosition().column
|
||||
},
|
||||
end: {
|
||||
line: selection.getEndPosition().lineNumber - 1,
|
||||
character: selection.getEndPosition().column
|
||||
}
|
||||
}));
|
||||
const menuActions = menu.getActions({ arg: { lineNumber, uri: model.uri, ranges } });
|
||||
actions.push(...menuActions.map(a => a[1]));
|
||||
|
||||
this.contextMenuService.showContextMenu({
|
||||
getAnchor: () => anchor,
|
||||
getActions: () => Separator.join(...actions),
|
||||
menuActionOptions: { shouldForwardArgs: true },
|
||||
getActionsContext: () => ({ lineNumber, uri: model.uri, ranges }),
|
||||
getActionsContext: () => ({ lineNumber, uri: model.uri }),
|
||||
onHide: () => menu.dispose(),
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { IMenuService, MenuId, MenuRegistry, SubmenuItemAction } from 'vs/platform/actions/common/actions';
|
||||
import { ContextKeyExpr, ContextKeyExpression, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { Extensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
|
||||
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
|
||||
import * as nls from 'vs/nls';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
|
||||
const menuIds: [MenuId, MenuId | undefined, ContextKeyExpression | undefined][] = [
|
||||
[MenuId.EditorContext, MenuId.EditorContextShare, ContextKeyExpr.and(ContextKeyExpr.notEquals('resourceScheme', 'output'), EditorContextKeys.editorTextFocus)],
|
||||
[MenuId.EditorTitleContext, MenuId.EditorTitleContextShare, undefined],
|
||||
[MenuId.ExplorerContext, MenuId.ExplorerContextShare, undefined],
|
||||
[MenuId.OpenEditorsContext, MenuId.OpenEditorsContextShare, undefined],
|
||||
[MenuId.SCMResourceContext, MenuId.SCMResourceContextShare, undefined],
|
||||
[MenuId.EditorLineNumberContext, undefined, undefined],
|
||||
];
|
||||
|
||||
for (const [menuId, submenuId, when] of menuIds) {
|
||||
if (submenuId !== undefined) {
|
||||
MenuRegistry.appendMenuItem(menuId, { submenu: submenuId, title: { value: nls.localize('share', "Share"), original: 'Share', }, group: '11_share', order: -1, when });
|
||||
}
|
||||
}
|
||||
|
||||
class ShareContribution {
|
||||
|
||||
private readonly disposableStore = new DisposableStore();
|
||||
private readonly menu = this.menuService.createMenu(MenuId.Share, this.contextKeyService);
|
||||
|
||||
constructor(
|
||||
@IMenuService private readonly menuService: IMenuService,
|
||||
@IContextKeyService private readonly contextKeyService: IContextKeyService,
|
||||
) {
|
||||
this.ensureActions();
|
||||
this.menu.onDidChange(() => this.ensureActions());
|
||||
}
|
||||
|
||||
private ensureActions(): void {
|
||||
this.disposableStore.clear();
|
||||
|
||||
const allActions = this.menu.getActions();
|
||||
|
||||
for (const [_, actions] of allActions) {
|
||||
for (const action of actions) {
|
||||
if (action instanceof SubmenuItemAction || !action.enabled) {
|
||||
continue;
|
||||
}
|
||||
for (const [menuId, submenuId] of menuIds) {
|
||||
this.disposableStore.add(MenuRegistry.appendMenuItem(
|
||||
submenuId ?? menuId,
|
||||
{ command: action.item }
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(ShareContribution, LifecyclePhase.Eventually);
|
|
@ -129,11 +129,6 @@ const apiMenus: IAPIMenu[] = [
|
|||
id: MenuId.SCMResourceContext,
|
||||
description: localize('menus.resourceStateContext', "The Source Control resource state context menu")
|
||||
},
|
||||
{
|
||||
key: 'scm/resourceState/context/share',
|
||||
id: MenuId.SCMResourceContextShare,
|
||||
description: localize('menus.resourceStateContextShare', "The Share submenu in the Source Control resource state context menu")
|
||||
},
|
||||
{
|
||||
key: 'scm/resourceFolder/context',
|
||||
id: MenuId.SCMResourceFolderContext,
|
||||
|
@ -300,13 +295,6 @@ const apiMenus: IAPIMenu[] = [
|
|||
description: localize('menus.share', "Share submenu shown in the top level File menu."),
|
||||
proposed: 'contribShareMenu'
|
||||
},
|
||||
{
|
||||
key: 'share',
|
||||
id: MenuId.Share,
|
||||
description: localize('share', "Share submenus in all relevant context menus."),
|
||||
supportsSubmenus: false,
|
||||
proposed: 'contribShareMenu'
|
||||
},
|
||||
{
|
||||
key: 'editor/inlineCompletions/actions',
|
||||
id: MenuId.InlineCompletionsActions,
|
||||
|
|
|
@ -358,6 +358,4 @@ import 'vs/workbench/contrib/deprecatedExtensionMigrator/browser/deprecatedExten
|
|||
// Bracket Pair Colorizer 2 Telemetry
|
||||
import 'vs/workbench/contrib/bracketPairColorizer2Telemetry/browser/bracketPairColorizer2Telemetry.contribution';
|
||||
|
||||
import 'vs/workbench/contrib/share/browser/share.contribution';
|
||||
|
||||
//#endregion
|
||||
|
|
Loading…
Reference in a new issue