Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add character countdown to commit message input #36890

Merged
merged 2 commits into from Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/git/src/repository.ts
Expand Up @@ -484,6 +484,7 @@ export class Repository implements Disposable {
this._sourceControl.inputBox.placeholder = localize('commitMessage', "Message (press {0} to commit)");
this._sourceControl.acceptInputCommand = { command: 'git.commitWithInput', title: localize('commit', "Commit"), arguments: [this._sourceControl] };
this._sourceControl.quickDiffProvider = this;
this._sourceControl.inputBox.warningLength = 72;
this.disposables.push(this._sourceControl);

this._mergeGroup = this._sourceControl.createResourceGroup('merge', localize('merge changes', "Merge Changes"));
Expand Down
5 changes: 5 additions & 0 deletions src/vs/vscode.d.ts
Expand Up @@ -5782,6 +5782,11 @@ declare module 'vscode' {
* A string to show as place holder in the input box to guide the user.
*/
placeholder: string;

/**
* The warning threshold for commit messages.
*/
warningLength: number | undefined;
}

interface QuickDiffProvider {
Expand Down
10 changes: 10 additions & 0 deletions src/vs/workbench/api/electron-browser/mainThreadSCM.ts
Expand Up @@ -391,4 +391,14 @@ export class MainThreadSCM implements MainThreadSCMShape {

repository.input.placeholder = placeholder;
}

$setWarningLength(sourceControlHandle: number, warningLength: number): void {
const repository = this._repositories[sourceControlHandle];

if (!repository) {
return;
}

repository.input.warningLength = warningLength;
}
}
1 change: 1 addition & 0 deletions src/vs/workbench/api/node/extHost.protocol.ts
Expand Up @@ -410,6 +410,7 @@ export interface MainThreadSCMShape extends IDisposable {

$setInputBoxValue(sourceControlHandle: number, value: string): void;
$setInputBoxPlaceholder(sourceControlHandle: number, placeholder: string): void;
$setWarningLength(sourceControlHandle: number, warningLength: number): void;
}

export type DebugSessionUUID = string;
Expand Down
13 changes: 12 additions & 1 deletion src/vs/workbench/api/node/extHostSCM.ts
Expand Up @@ -110,7 +110,7 @@ function compareResourceStates(a: vscode.SourceControlResourceState, b: vscode.S
return result;
}

export class ExtHostSCMInputBox {
export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {

private _value: string = '';

Expand Down Expand Up @@ -140,6 +140,17 @@ export class ExtHostSCMInputBox {
this._placeholder = placeholder;
}

private _warningLength: number | undefined;

get warningLength(): number | undefined {
return this._warningLength;
}

set warningLength(warningLength: number) {
this._proxy.$setWarningLength(this._sourceControlHandle, warningLength);
this._warningLength = warningLength;
}

constructor(private _proxy: MainThreadSCMShape, private _sourceControlHandle: number) {
// noop
}
Expand Down
30 changes: 28 additions & 2 deletions src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts
Expand Up @@ -45,7 +45,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IExtensionsViewlet, VIEWLET_ID as EXTENSIONS_VIEWLET_ID } from 'vs/workbench/parts/extensions/common/extensions';
import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
import { IMessage, InputBox, MessageType } from 'vs/base/browser/ui/inputbox/inputBox';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Command } from 'vs/editor/common/modes';
Expand Down Expand Up @@ -753,7 +753,33 @@ export class RepositoryPanel extends ViewletPanel {
this.inputBox.setPlaceHolder(placeholder);
};

this.inputBox = new InputBox(this.inputBoxContainer, this.contextViewService, { flexibleHeight: true });
const validation = (text: string): IMessage => {
const warningLength = this.repository.input.warningLength;
if (warningLength === undefined) {
return {
content: localize('commitMessageInfo', "{0} characters", text.length),
type: MessageType.INFO
};
}

const charactersLeft = warningLength - text.length;
if (charactersLeft > 0) {
return {
content: localize('commitMessageCountdown', "{0} characters left", text.length),
type: MessageType.INFO
};
} else {
return {
content: localize('commitMessageWarning', "{0} characters over", text.length),
type: MessageType.WARNING
};
}
};

this.inputBox = new InputBox(this.inputBoxContainer, this.contextViewService, {
flexibleHeight: true,
validationOptions: { validation: validation }
});
this.disposables.push(attachInputBoxStyler(this.inputBox, this.themeService));
this.disposables.push(this.inputBox);

Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/services/scm/common/scm.ts
Expand Up @@ -74,6 +74,8 @@ export interface ISCMInput {

placeholder: string;
readonly onDidChangePlaceholder: Event<string>;

warningLength: number | undefined;
}

export interface ISCMRepository extends IDisposable {
Expand Down
12 changes: 11 additions & 1 deletion src/vs/workbench/services/scm/common/scmService.ts
Expand Up @@ -39,6 +39,16 @@ class SCMInput implements ISCMInput {

private _onDidChangePlaceholder = new Emitter<string>();
get onDidChangePlaceholder(): Event<string> { return this._onDidChangePlaceholder.event; }

private _warningLength: number | undefined;

get warningLength(): number | undefined {
return this._warningLength;
}

set warningLength(warningLength: number) {
this._warningLength = warningLength;
}
}

class SCMRepository implements ISCMRepository {
Expand Down Expand Up @@ -106,4 +116,4 @@ export class SCMService implements ISCMService {

return repository;
}
}
}