diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-02-03 16:37:12 +0100 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-02-03 16:37:12 +0100 |
| commit | ad57726f9181d7b80d217d7bf1b6cdca282d0982 (patch) | |
| tree | 04bd8d40a59ba81df0f49f5d315b0017a3554c3c /editors/code/src | |
| parent | 056a01502b7a072f16db0e81eeb99ed8508d2ee6 (diff) | |
| download | rust-ad57726f9181d7b80d217d7bf1b6cdca282d0982.tar.gz rust-ad57726f9181d7b80d217d7bf1b6cdca282d0982.zip | |
Use simple prng instead of a dependency
closes #2999
Diffstat (limited to 'editors/code/src')
| -rw-r--r-- | editors/code/src/highlighting.ts | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 3d190c3ad71..66216e0fc32 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -1,6 +1,5 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; -import seedrandom from 'seedrandom'; import { ColorTheme, TextMateRuleSettings } from './color_theme'; @@ -70,9 +69,9 @@ interface Decoration { // Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76 function fancify(seed: string, shade: 'light' | 'dark') { - const random = seedrandom(seed); + const random = randomU32Numbers(hashString(seed)) const randomInt = (min: number, max: number) => { - return Math.floor(random() * (max - min + 1)) + min; + return Math.abs(random()) % (max - min + 1) + min; }; const h = randomInt(0, 360); @@ -246,3 +245,23 @@ const TAG_TO_SCOPES = new Map<string, string[]>([ ["keyword.unsafe", ["keyword.other.unsafe"]], ["keyword.control", ["keyword.control"]], ]); + +function randomU32Numbers(seed: number) { + let random = seed | 0; + return () => { + random ^= random << 13; + random ^= random >> 17; + random ^= random << 5; + random |= 0; + return random + } +} + +function hashString(str: string): number { + let res = 0; + for (let i = 0; i < str.length; ++i) { + const c = str.codePointAt(i)!!; + res = (res * 31 + c) & ~0; + } + return res; +} |
