-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-1746: Initial changes for the input box with validation support.
Signed-off-by: Akos Kitta <kittaakos@gmail.com>
- Loading branch information
Showing
10 changed files
with
220 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
/** | ||
* A string that could be: | ||
* | ||
* - one of the browser colors, (E.g.: `blue`, `red`, `magenta`), | ||
* - the case insensitive hexadecimal color code, (for instance, `#ee82ee`, `#20B2AA`, `#f09` ), or | ||
* - either the `rgb()` or the `rgba()` functions. | ||
* | ||
* For more details, see: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value. | ||
* | ||
* Note, it is highly recommended to use one of the predefined colors of Theia, so the desired color will | ||
* look nice with both the `light` and the `dark` theme too. For instance: `var(--theia-success-color0)`. | ||
*/ | ||
export type Color = string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { injectable } from 'inversify'; | ||
import { MaybePromise } from '@theia/core/lib/common/types'; | ||
|
||
@injectable() | ||
export class GitCommitMessageValidator { | ||
|
||
static readonly MAX_CHARS_PER_LINE = 72; | ||
|
||
/** | ||
* Validates the input and returns with either a validation result with the status and message, or `undefined` if everything went fine. | ||
*/ | ||
validate(input: string | undefined): MaybePromise<GitCommitMessageValidator.Result | undefined> { | ||
if (input) { | ||
for (const line of input.split(/\r?\n/)) { | ||
const result = this.isLineValid(line); | ||
if (!!result) { | ||
return result; | ||
} | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
protected isLineValid(line: string): GitCommitMessageValidator.Result | undefined { | ||
const diff = line.length - this.maxCharsPerLine(); | ||
if (diff > 0) { | ||
return { | ||
status: 'warning', | ||
message: `${diff} characters over ${this.maxCharsPerLine()} in current line` | ||
}; | ||
} | ||
return undefined; | ||
} | ||
|
||
protected maxCharsPerLine(): number { | ||
return GitCommitMessageValidator.MAX_CHARS_PER_LINE; | ||
} | ||
|
||
} | ||
|
||
export namespace GitCommitMessageValidator { | ||
|
||
/** | ||
* Type for the validation result with a status and a corresponding message. | ||
*/ | ||
export type Result = Readonly<{ message: string, status: 'info' | 'success' | 'warning' | 'error' }>; | ||
|
||
export namespace Result { | ||
|
||
/** | ||
* `true` if the `message` and the `status` properties are the same on both `left` and `right`. Or both arguments are `undefined`. Otherwise, `false`. | ||
*/ | ||
export function equal(left: Result | undefined, right: Result | undefined): boolean { | ||
if (left && right) { | ||
return left.message === right.message && left.status === right.status; | ||
} | ||
return left === right; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.