You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -12,12 +15,14 @@ codeInput.plugins.SpecialChars = class extends codeInput.Plugin {
12
15
/**
13
16
* Create a special characters plugin instance
14
17
* @param {RegExp} specialCharRegExp The regular expression which matches special characters
18
+
* @param {Boolean} colorInSpecialChars Whether or not to give special characters custom background colors based on their hex code
15
19
*/
16
-
constructor(specialCharRegExp=/(?!\n)(?!\t)[\u{0000}-\u{001F}]|[\u{0080}-\u{FFFF}]/ug){// By default, covers many non-renderable ASCII characters
20
+
constructor(specialCharRegExp=/(?!\n)(?!\t)[\u{0000}-\u{001F}]|[\u{007F}-\u{FFFF}]/ug,colorInSpecialChars=false){// By default, covers many non-renderable ASCII characters
17
21
super();
18
22
this.specialCharRegExp=specialCharRegExp;
19
-
this.cachedColors={};
23
+
this.colorInSpecialChars=colorInSpecialChars;
20
24
25
+
this.cachedColors={};
21
26
this.cachedWidths={};
22
27
23
28
letcanvas=document.createElement("canvas");
@@ -30,26 +35,42 @@ codeInput.plugins.SpecialChars = class extends codeInput.Plugin {
30
35
this.canvasContext.font="20px 'Consolas'";// TODO: Make dynamic
31
36
}
32
37
38
+
/* Runs before elements are added into a `code-input`; Params: codeInput element) */
hex_code=("00"+hex_code).substring(hex_code.length);// So 2 chars with leading 0
55
+
hex_code=("0000"+hex_code).substring(hex_code.length);// So 2 chars with leading 0
46
56
hex_code=hex_code.toUpperCase();
47
57
48
58
letchar_width=this.getCharacterWidth(match_char);
49
-
console.log(hex_code,char_width);
50
59
51
-
// let background_color = hashed_last_hex_char + hashed_last_hex_char + hex_code.substr(0, 1) + hex_code.substr(0, 1) + hex_code.substr(1, 1) + hex_code.substr(1, 1) // So good range of colours
0 commit comments