Skip to content

Commit

Permalink
Merge branch 'main' into ben/distinct-manatee
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored Jul 18, 2022
2 parents 399737e + b321896 commit d6452a3
Show file tree
Hide file tree
Showing 58 changed files with 901 additions and 672 deletions.
1 change: 1 addition & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"scmActionButton",
"scmSelectedProvider",
"scmValidation",
"tabInputTextMerge",
"timeline"
],
"categories": [
Expand Down
41 changes: 23 additions & 18 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as os from 'os';
import * as path from 'path';
import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText } from 'vscode';
import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText, TabInputTextMerge } from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';
import * as nls from 'vscode-nls';
import { uniqueNamesGenerator, adjectives, animals, colors, NumberDictionary } from '@joaomoreno/unique-names-generator';
Expand Down Expand Up @@ -1103,21 +1103,26 @@ export class CommandCenter {
return;
}

const { activeTab } = window.tabGroups.activeTabGroup;
if (!activeTab) {
return;
}

// make sure to save the merged document
const doc = workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString());
if (!doc) {
console.log(`FAILED to accept merge because uri ${uri.toString()} doesn't match a document`);
return;
}
if (doc.isDirty) {
await doc.save();
}

await doc.save();

// TODO@jrieken there isn't a `TabInputTextMerge` instance yet, till now the merge editor
// uses the `TabInputText` for the out-resource and we use that to identify and CLOSE the tab
// see https://github.com/microsoft/vscode/issues/153213
const { activeTab } = window.tabGroups.activeTabGroup;
// find the merge editor tabs for the resource in question and close them all
let didCloseTab = false;
if (activeTab && activeTab?.input instanceof TabInputText && activeTab.input.uri.toString() === uri.toString()) {
didCloseTab = await window.tabGroups.close(activeTab, true);
const mergeEditorTabs = window.tabGroups.all.map(group => group.tabs.filter(tab => tab.input instanceof TabInputTextMerge && tab.input.result.toString() === uri.toString())).flat();
if (mergeEditorTabs.includes(activeTab)) {
didCloseTab = await window.tabGroups.close(mergeEditorTabs, true);
}

// Only stage if the merge editor has been successfully closed. That means all conflicts have been
Expand Down Expand Up @@ -1447,7 +1452,7 @@ export class CommandCenter {
private async smartCommit(
repository: Repository,
getCommitMessage: () => Promise<string | undefined>,
opts?: CommitOptions
opts: CommitOptions
): Promise<boolean> {
const config = workspace.getConfiguration('git', Uri.file(repository.root));
let promptToSaveFilesBeforeCommit = config.get<'always' | 'staged' | 'never'>('promptToSaveFilesBeforeCommit');
Expand Down Expand Up @@ -1493,14 +1498,8 @@ export class CommandCenter {
}
}

if (!opts) {
opts = { all: noStagedChanges };
} else if (!opts.all && noStagedChanges && !opts.empty) {
opts = { ...opts, all: true };
}

// no changes, and the user has not configured to commit all in this case
if (!noUnstagedChanges && noStagedChanges && !enableSmartCommit && !opts.empty) {
if (!noUnstagedChanges && noStagedChanges && !enableSmartCommit && !opts.empty && !opts.all) {
const suggestSmartCommit = config.get<boolean>('suggestSmartCommit') === true;

if (!suggestSmartCommit) {
Expand All @@ -1524,6 +1523,12 @@ export class CommandCenter {
}
}

if (opts.all === undefined) {
opts = { all: noStagedChanges };
} else if (!opts.all && noStagedChanges && !opts.empty) {
opts = { ...opts, all: true };
}

// enable signing of commits if configured
opts.signCommit = enableCommitSigning;

Expand Down Expand Up @@ -1637,7 +1642,7 @@ export class CommandCenter {
return true;
}

private async commitWithAnyInput(repository: Repository, opts?: CommitOptions): Promise<void> {
private async commitWithAnyInput(repository: Repository, opts: CommitOptions): Promise<void> {
const message = repository.inputBox.value;
const root = Uri.file(repository.root);
const config = workspace.getConfiguration('git', root);
Expand Down
2 changes: 1 addition & 1 deletion extensions/git/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"../../src/vscode-dts/vscode.proposed.scmActionButton.d.ts",
"../../src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts",
"../../src/vscode-dts/vscode.proposed.scmValidation.d.ts",
"../../src/vscode-dts/vscode.proposed.tabs.d.ts",
"../../src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts",
"../../src/vscode-dts/vscode.proposed.timeline.d.ts",
"../types/lib.textEncoder.d.ts"
]
Expand Down
25 changes: 20 additions & 5 deletions extensions/github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
}
},
"enabledApiProposals": [
"contribShareMenu"
"contribShareMenu",
"contribEditSessions"
],
"contributes": {
"commands": [
Expand All @@ -37,10 +38,20 @@
{
"command": "github.copyVscodeDevLink",
"title": "Copy vscode.dev Link"
},
{
"command": "github.copyVscodeDevLinkFile",
"title": "Copy vscode.dev Link"
},
{
"command": "github.copyVscodeDevLinkFile",
"title": "Copy vscode.dev Link"
},
{
"command": "github.openOnVscodeDev",
"title": "Open on vscode.dev"
}
],
"continueEditSession": [
{
"command": "github.openOnVscodeDev",
"when": "github.hasGitHubRepo"
}
],
"menus": {
Expand All @@ -56,6 +67,10 @@
{
"command": "github.copyVscodeDevLinkFile",
"when": "false"
},
{
"command": "github.openOnVscodeDev",
"when": "false"
}
],
"file/share": [
Expand Down
14 changes: 14 additions & 0 deletions extensions/github/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ async function copyVscodeDevLink(gitAPI: GitAPI, useSelection: boolean) {
}
}

async function openVscodeDevLink(gitAPI: GitAPI): Promise<vscode.Uri | undefined> {
try {
const permalink = getPermalink(gitAPI, true, 'https://vscode.dev/github');
return permalink ? vscode.Uri.parse(permalink) : undefined;
} catch (err) {
vscode.window.showErrorMessage(err.message);
return undefined;
}
}

export function registerCommands(gitAPI: GitAPI): vscode.Disposable {
const disposables = new DisposableStore();

Expand All @@ -39,5 +49,9 @@ export function registerCommands(gitAPI: GitAPI): vscode.Disposable {
return copyVscodeDevLink(gitAPI, false);
}));

disposables.add(vscode.commands.registerCommand('github.openOnVscodeDev', async () => {
return openVscodeDevLink(gitAPI);
}));

return disposables;
}
65 changes: 28 additions & 37 deletions src/vs/base/browser/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1734,18 +1734,27 @@ export function computeClippingRect(elementOrRect: HTMLElement | DOMRectReadOnly
return { top, right, bottom, left };
}

interface DomNodeAttributes {
role?: string;
ariaHidden?: boolean;
style?: StyleAttributes;
}

interface StyleAttributes {
height?: number | string;
width?: number | string;
}
type HTMLElementAttributeKeys<T> = Partial<{ [K in keyof T]: T[K] extends Function ? never : T[K] extends object ? HTMLElementAttributeKeys<T[K]> : T[K] }>;
type ElementAttributes<T> = HTMLElementAttributeKeys<T> & Record<string, any>;
type RemoveHTMLElement<T> = T extends HTMLElement ? never : T;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
type ArrayToObj<T extends any[]> = UnionToIntersection<RemoveHTMLElement<T[number]>>;

//<div role="presentation" aria-hidden="true" class="scroll-decoration"></div>
type TagToElement<T> = T extends `.${string}`
? HTMLDivElement
: T extends `#${string}`
? HTMLDivElement
: T extends `${infer TStart}#${string}`
? TStart extends keyof HTMLElementTagNameMap
? HTMLElementTagNameMap[TStart]
: HTMLElement
: T extends `${infer TStart}.${string}`
? TStart extends keyof HTMLElementTagNameMap
? HTMLElementTagNameMap[TStart]
: HTMLElement
: T extends keyof HTMLElementTagNameMap
? HTMLElementTagNameMap[T]
: HTMLElement;

/**
* A helper function to create nested dom nodes.
Expand All @@ -1762,22 +1771,25 @@ interface StyleAttributes {
* private readonly editor = createEditor(this.htmlElements.editor);
* ```
*/
export function h<TTag extends string>(
tag: TTag
): (Record<'root', TagToElement<TTag>>) extends infer Y ? { [TKey in keyof Y]: Y[TKey] } : never;
export function h<TTag extends string, TId extends string>(
tag: TTag,
attributes: { $: TId } & DomNodeAttributes
attributes: { $: TId } & Partial<ElementAttributes<TagToElement<TTag>>>
): Record<TId | 'root', TagToElement<TTag>>;
export function h<TTag extends string>(tag: TTag, attributes: DomNodeAttributes): Record<'root', TagToElement<TTag>>;
export function h<TTag extends string, T extends (HTMLElement | string | Record<string, HTMLElement>)[]>(
tag: TTag,
children: T
): (ArrayToObj<T> & Record<'root', TagToElement<TTag>>) extends infer Y ? { [TKey in keyof Y]: Y[TKey] } : never;
export function h<TTag extends string>(tag: TTag, attributes: Partial<ElementAttributes<TagToElement<TTag>>>): Record<'root', TagToElement<TTag>>;
export function h<TTag extends string, TId extends string, T extends (HTMLElement | string | Record<string, HTMLElement>)[]>(
tag: TTag,
attributes: { $: TId } & DomNodeAttributes,
attributes: { $: TId } & Partial<ElementAttributes<TagToElement<TTag>>>,
children: T
): (ArrayToObj<T> & Record<TId, TagToElement<TTag>>) extends infer Y ? { [TKey in keyof Y]: Y[TKey] } : never;
export function h(tag: string, ...args: [] | [attributes: { $: string } & DomNodeAttributes | Record<string, any>, children?: any[]] | [children: any[]]): Record<string, HTMLElement> {
let attributes: { $?: string } & DomNodeAttributes;
export function h(tag: string, ...args: [] | [attributes: { $: string } & Partial<ElementAttributes<HTMLElement>> | Record<string, any>, children?: any[]] | [children: any[]]): Record<string, HTMLElement> {
let attributes: { $?: string } & Partial<ElementAttributes<HTMLElement>>;
let children: (Record<string, HTMLElement> | HTMLElement)[] | undefined;

if (Array.isArray(args[0])) {
Expand Down Expand Up @@ -1845,24 +1857,3 @@ export function h(tag: string, ...args: [] | [attributes: { $: string } & DomNod
function camelCaseToHyphenCase(str: string) {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}

type RemoveHTMLElement<T> = T extends HTMLElement ? never : T;

type ArrayToObj<T extends any[]> = UnionToIntersection<RemoveHTMLElement<T[number]>>;


type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;

type HTMLElementsByTagName = {
div: HTMLDivElement;
span: HTMLSpanElement;
a: HTMLAnchorElement;
};

type TagToElement<T> = T extends `${infer TStart}.${string}`
? TStart extends keyof HTMLElementsByTagName
? HTMLElementsByTagName[TStart]
: HTMLElement
: T extends keyof HTMLElementsByTagName
? HTMLElementsByTagName[T]
: HTMLElement;
48 changes: 43 additions & 5 deletions src/vs/base/browser/ui/findinput/findInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as dom from 'vs/base/browser/dom';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
import { IToggleStyles } from 'vs/base/browser/ui/toggle/toggle';
import { IToggleStyles, Toggle } from 'vs/base/browser/ui/toggle/toggle';
import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview';
import { CaseSensitiveToggle, RegexToggle, WholeWordsToggle } from 'vs/base/browser/ui/findinput/findInputToggles';
import { HistoryInputBox, IInputBoxStyles, IInputValidator, IMessage as InputBoxMessage } from 'vs/base/browser/ui/inputbox/inputBox';
Expand All @@ -31,6 +31,7 @@ export interface IFindInputOptions extends IFindInputStyles {
readonly appendWholeWordsLabel?: string;
readonly appendRegexLabel?: string;
readonly history?: string[];
readonly additionalToggles?: Toggle[];
readonly showHistoryHint?: () => boolean;
}

Expand Down Expand Up @@ -74,6 +75,7 @@ export class FindInput extends Widget {
protected regex: RegexToggle;
protected wholeWords: WholeWordsToggle;
protected caseSensitive: CaseSensitiveToggle;
protected additionalToggles: Toggle[] = [];
public domNode: HTMLElement;
public inputBox: HistoryInputBox;

Expand Down Expand Up @@ -209,10 +211,6 @@ export class FindInput extends Widget {
this._onCaseSensitiveKeyDown.fire(e);
}));

if (this._showOptionButtons) {
this.inputBox.paddingRight = this.caseSensitive.width() + this.wholeWords.width() + this.regex.width();
}

// Arrow-Key support to navigate between options
const indexes = [this.caseSensitive.domNode, this.wholeWords.domNode, this.regex.domNode];
this.onkeydown(this.domNode, (event: IKeyboardEvent) => {
Expand Down Expand Up @@ -250,6 +248,34 @@ export class FindInput extends Widget {
this.controls.appendChild(this.wholeWords.domNode);
this.controls.appendChild(this.regex.domNode);

if (!this._showOptionButtons) {
this.caseSensitive.domNode.style.display = 'none';
this.wholeWords.domNode.style.display = 'none';
this.regex.domNode.style.display = 'none';
}

for (const toggle of options?.additionalToggles ?? []) {
this._register(toggle);
this.controls.appendChild(toggle.domNode);

this._register(toggle.onChange(viaKeyboard => {
this._onDidOptionChange.fire(viaKeyboard);
if (!viaKeyboard && this.fixFocusOnOptionClickEnabled) {
this.inputBox.focus();
}
}));

this.additionalToggles.push(toggle);
}

if (this.additionalToggles.length > 0) {
this.controls.style.display = 'block';
}

this.inputBox.paddingRight =
(this._showOptionButtons ? this.caseSensitive.width() + this.wholeWords.width() + this.regex.width() : 0)
+ this.additionalToggles.reduce((r, t) => r + t.width(), 0);

this.domNode.appendChild(this.controls);

parent?.appendChild(this.domNode);
Expand Down Expand Up @@ -282,6 +308,10 @@ export class FindInput extends Widget {
this.regex.enable();
this.wholeWords.enable();
this.caseSensitive.enable();

for (const toggle of this.additionalToggles) {
toggle.enable();
}
}

public disable(): void {
Expand All @@ -290,6 +320,10 @@ export class FindInput extends Widget {
this.regex.disable();
this.wholeWords.disable();
this.caseSensitive.disable();

for (const toggle of this.additionalToggles) {
toggle.disable();
}
}

public setFocusInputOnOptionClick(value: boolean): void {
Expand Down Expand Up @@ -356,6 +390,10 @@ export class FindInput extends Widget {
this.wholeWords.style(toggleStyles);
this.caseSensitive.style(toggleStyles);

for (const toggle of this.additionalToggles) {
toggle.style(toggleStyles);
}

const inputBoxStyles: IInputBoxStyles = {
inputBackground: this.inputBackground,
inputForeground: this.inputForeground,
Expand Down
Loading

0 comments on commit d6452a3

Please sign in to comment.