aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/highlighting.ts25
1 files changed, 22 insertions, 3 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 3d190c3ad..66216e0fc 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -1,6 +1,5 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3import seedrandom from 'seedrandom';
4 3
5import { ColorTheme, TextMateRuleSettings } from './color_theme'; 4import { ColorTheme, TextMateRuleSettings } from './color_theme';
6 5
@@ -70,9 +69,9 @@ interface Decoration {
70 69
71// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76 70// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
72function fancify(seed: string, shade: 'light' | 'dark') { 71function fancify(seed: string, shade: 'light' | 'dark') {
73 const random = seedrandom(seed); 72 const random = randomU32Numbers(hashString(seed))
74 const randomInt = (min: number, max: number) => { 73 const randomInt = (min: number, max: number) => {
75 return Math.floor(random() * (max - min + 1)) + min; 74 return Math.abs(random()) % (max - min + 1) + min;
76 }; 75 };
77 76
78 const h = randomInt(0, 360); 77 const h = randomInt(0, 360);
@@ -246,3 +245,23 @@ const TAG_TO_SCOPES = new Map<string, string[]>([
246 ["keyword.unsafe", ["keyword.other.unsafe"]], 245 ["keyword.unsafe", ["keyword.other.unsafe"]],
247 ["keyword.control", ["keyword.control"]], 246 ["keyword.control", ["keyword.control"]],
248]); 247]);
248
249function randomU32Numbers(seed: number) {
250 let random = seed | 0;
251 return () => {
252 random ^= random << 13;
253 random ^= random >> 17;
254 random ^= random << 5;
255 random |= 0;
256 return random
257 }
258}
259
260function hashString(str: string): number {
261 let res = 0;
262 for (let i = 0; i < str.length; ++i) {
263 const c = str.codePointAt(i)!!;
264 res = (res * 31 + c) & ~0;
265 }
266 return res;
267}