diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index e96d54d708e6167f444a5d47762784ed1e97a131..4ee58c70fffe7ecbd17e38aeff45ef91972ea934 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -519,6 +519,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.lineWarningLength = 72; this.disposables.push(this._sourceControl); this._mergeGroup = this._sourceControl.createResourceGroup('merge', localize('merge changes', "Merge Changes")); diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index b02773f70b9966ef2bc00d90bbdd5812515bffef..86982258339b414c7f31748ae2e13e01641a04cb 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -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 lines in the input box. + */ + lineWarningLength: number | undefined; } interface QuickDiffProvider { diff --git a/src/vs/workbench/api/electron-browser/mainThreadSCM.ts b/src/vs/workbench/api/electron-browser/mainThreadSCM.ts index 88c6377b3c46a08057eeb6eb0668a358bc3b11a5..2541503baa9416983d3f26c08d9ff1cb000676a3 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadSCM.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadSCM.ts @@ -391,4 +391,14 @@ export class MainThreadSCM implements MainThreadSCMShape { repository.input.placeholder = placeholder; } + + $setLineWarningLength(sourceControlHandle: number, lineWarningLength: number): void { + const repository = this._repositories[sourceControlHandle]; + + if (!repository) { + return; + } + + repository.input.lineWarningLength = lineWarningLength; + } } diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 111a4643be84edf11d8bdc0e8b830fdb139c9274..f9fd93dfa20b3f8f5aa2fcf390a8eed79eae3808 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -410,6 +410,7 @@ export interface MainThreadSCMShape extends IDisposable { $setInputBoxValue(sourceControlHandle: number, value: string): void; $setInputBoxPlaceholder(sourceControlHandle: number, placeholder: string): void; + $setLineWarningLength(sourceControlHandle: number, lineWarningLength: number): void; } export type DebugSessionUUID = string; diff --git a/src/vs/workbench/api/node/extHostSCM.ts b/src/vs/workbench/api/node/extHostSCM.ts index 9444ef007441510abd29a0ee148111b62bd50c80..37a6b752ab1ec6429732c87c41706fc62464dd77 100644 --- a/src/vs/workbench/api/node/extHostSCM.ts +++ b/src/vs/workbench/api/node/extHostSCM.ts @@ -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 = ''; @@ -140,6 +140,17 @@ export class ExtHostSCMInputBox { this._placeholder = placeholder; } + private _lineWarningLength: number | undefined; + + get lineWarningLength(): number | undefined { + return this._lineWarningLength; + } + + set lineWarningLength(lineWarningLength: number) { + this._proxy.$setLineWarningLength(this._sourceControlHandle, lineWarningLength); + this._lineWarningLength = lineWarningLength; + } + constructor(private _proxy: MainThreadSCMShape, private _sourceControlHandle: number) { // noop } diff --git a/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts b/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts index d2a18a112ea2c199e0476e80c11121577c456fcc..bce5b81ee3c3992a9d0db81aa6dd2b285bfb1a45 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts @@ -74,5 +74,11 @@ Registry.as(ConfigurationExtensions.Configuration).regis default: 'all', description: localize('diffDecorations', "Controls diff decorations in the editor.") }, + 'scm.inputCounter': { + type: 'string', + enum: ['always', 'warn', 'off'], + default: 'warn', + description: localize('inputCounter', "Controls when to display the input counter.") + } } }); \ No newline at end of file diff --git a/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts b/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts index 4530cff6727f2dd7ebe0b3d77ce5af8e851fda9e..af7f2a6a9b6bebfa35bf6cda1c02fde76456aea5 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts @@ -8,7 +8,7 @@ import 'vs/css!./media/scmViewlet'; import { localize } from 'vs/nls'; import { TPromise } from 'vs/base/common/winjs.base'; -import Event, { Emitter, chain, mapEvent } from 'vs/base/common/event'; +import Event, { Emitter, chain, mapEvent, anyEvent } from 'vs/base/common/event'; import { domEvent, stop } from 'vs/base/browser/event'; import { basename } from 'vs/base/common/paths'; import { onUnexpectedError } from 'vs/base/common/errors'; @@ -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'; @@ -56,6 +56,7 @@ import { format } from 'vs/base/common/strings'; import { ISpliceable, ISequence, ISplice } from 'vs/base/common/sequence'; import { firstIndex } from 'vs/base/common/arrays'; import { WorkbenchList, IListService } from 'vs/platform/list/browser/listService'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; // TODO@Joao // Need to subclass MenuItemActionItem in order to respect @@ -695,7 +696,8 @@ export class RepositoryPanel extends ViewletPanel { @IWorkbenchEditorService protected editorService: IWorkbenchEditorService, @IEditorGroupService protected editorGroupService: IEditorGroupService, @IContextKeyService protected contextKeyService: IContextKeyService, - @IInstantiationService protected instantiationService: IInstantiationService + @IInstantiationService protected instantiationService: IInstantiationService, + @IConfigurationService protected configurationService: IConfigurationService ) { super(repository.provider.label, {}, keybindingService, contextMenuService); this.menus = instantiationService.createInstance(SCMMenus, repository.provider); @@ -753,10 +755,63 @@ 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 setting = this.configurationService.getValue<'always' | 'warn' | 'off'>('scm.inputCounter'); + + if (setting === 'off') { + return null; + } + + let position = this.inputBox.inputElement.selectionStart; + let start = 0, end; + let match: RegExpExecArray; + const regex = /\r?\n/g; + + while ((match = regex.exec(text)) && position > match.index) { + start = match.index + match[0].length; + } + + end = match ? match.index : text.length; + + const line = text.substring(start, end); + + const lineWarningLength = this.repository.input.lineWarningLength; + + if (lineWarningLength === undefined) { + return { + content: localize('commitMessageInfo', "{0} characters in current line", text.length), + type: MessageType.INFO + }; + } + + if (line.length <= lineWarningLength) { + if (setting !== 'always') { + return null; + } + + return { + content: localize('commitMessageCountdown', "{0} characters left in current line", lineWarningLength - line.length), + type: MessageType.INFO + }; + } else { + return { + content: localize('commitMessageWarning', "{0} characters over {1} in current line", line.length - lineWarningLength, lineWarningLength), + 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); + const onKeyUp = domEvent(this.inputBox.inputElement, 'keyup'); + const onMouseUp = domEvent(this.inputBox.inputElement, 'mouseup'); + anyEvent(onKeyUp, onMouseUp)(() => this.inputBox.validate(), null, this.disposables); + this.inputBox.value = this.repository.input.value; this.inputBox.onDidChange(value => this.repository.input.value = value, null, this.disposables); this.repository.input.onDidChange(value => this.inputBox.value = value, null, this.disposables); diff --git a/src/vs/workbench/services/scm/common/scm.ts b/src/vs/workbench/services/scm/common/scm.ts index 78c1252f599ec96ccb1e9c3fc4624cf085476a09..78014460542ebcf28decda44893bd58f07e4d504 100644 --- a/src/vs/workbench/services/scm/common/scm.ts +++ b/src/vs/workbench/services/scm/common/scm.ts @@ -74,6 +74,8 @@ export interface ISCMInput { placeholder: string; readonly onDidChangePlaceholder: Event; + + lineWarningLength: number | undefined; } export interface ISCMRepository extends IDisposable { diff --git a/src/vs/workbench/services/scm/common/scmService.ts b/src/vs/workbench/services/scm/common/scmService.ts index db569fc7c5774046870874822deb2987c99d564e..ad66331ddc13ff3927aa7ceab99389a7224f2399 100644 --- a/src/vs/workbench/services/scm/common/scmService.ts +++ b/src/vs/workbench/services/scm/common/scmService.ts @@ -39,6 +39,8 @@ class SCMInput implements ISCMInput { private _onDidChangePlaceholder = new Emitter(); get onDidChangePlaceholder(): Event { return this._onDidChangePlaceholder.event; } + + public lineWarningLength: number | undefined = undefined; } class SCMRepository implements ISCMRepository { @@ -106,4 +108,4 @@ export class SCMService implements ISCMService { return repository; } -} \ No newline at end of file +}