Skip to content

Commit b2ef665

Browse files
committed
Handle CapsLock
1 parent 3b4f0ed commit b2ef665

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<script src="js/jquery.min.js"></script>
1212
<script src="js/caret.js"></script>
1313
<script src="js/keyboard.js"></script>
14+
<script src="js/ColorState.js"></script>
1415
<script src="js/var.js"></script>
1516
<script src="js/keymap.js"></script>
1617
<script src="js/colorMap.js"></script>

js/ColorState.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function ColorState(startKey, endKey, color) {
22
this.startKey = startKey;
33
this.endKey = endKey;
44
this.color = color;
5-
this.state = false;
5+
this.openStatus = false;
66
}
77

88
ColorState.prototype = {
@@ -12,7 +12,7 @@ ColorState.prototype = {
1212
getCloseKey: function() { return this.endKey; },
1313
getColor: function() { return this.color; },
1414

15-
isOpen: function() { return this.state; },
16-
open: function() { this.state = true; },
17-
close: function() { this.state = false; }
15+
isOpen: function() { return this.openStatus; },
16+
open: function() { this.openStatus = true; },
17+
close: function() { this.openStatus = false; }
1818
}

js/colorize.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ const isNumber = function(str) {
1111
return !isNaN(str);
1212
}
1313

14+
const characterizeWord = function(word) {
15+
let html = "";
16+
for(let i = 0; i < word.length; i++) {
17+
let char = word.charAt(i);
18+
html += characterPrefix + char + characterSuffix;
19+
}
20+
21+
return html;
22+
}
23+
1424
const wordToHTML = function(word) {
1525
let htmlWord = word.length==0 ? '' : characterizeWord(word);
1626

@@ -64,12 +74,3 @@ const colorizeLine = function(text, prevColorStateList) {
6474
return htmlLine;
6575
}
6676

67-
const characterizeWord = function(word) {
68-
let html = "";
69-
for(let i = 0; i < word.length; i++) {
70-
let char = word.charAt(i);
71-
html += characterPrefix + char + characterSuffix;
72-
}
73-
74-
return html;
75-
}

js/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ $(document).ready(function() {
99
initNewDoc();
1010

1111
$(document).on('keydown', function(event) {
12+
// prevent TAB KEY from switching focus
1213
if(event.keyCode == 9) event.preventDefault();
14+
15+
if (event.originalEvent.getModifierState("CapsLock")) capsLockKey.press();
16+
else capsLockKey.release();
17+
1318
handleKeyDown(event.keyCode);
1419
});
1520

js/keyboard.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const isIgnoreKey = function(keyCode) {
3535

3636
const keyToChar = function(keyCode) {
3737
let char;
38-
if(shiftKey.isPressed()) {
38+
if(shiftKey.isPressed() || capsLockKey.isPressed()) {
3939
char = keymap[keyCode][0];
4040
} else {
4141
char = keymap[keyCode][1];
@@ -55,8 +55,16 @@ const handleKeyDown = function(keyCode) {
5555
ctrlKey.press();
5656
}
5757

58+
/*
59+
TODO
60+
CapsLock Key - keyCode = 20
61+
*/
62+
63+
// Ignore Keys --------------------------------------------------------------------
64+
if(keyCode == 20) {}
65+
5866
// Deletion --------------------------------------------------------------------
59-
if(keyCode == 13) { // ENTER
67+
else if(keyCode == 13) { // ENTER
6068
// TODO handle brackets indentation (|) {|} [|]
6169
let charBefore = defaultCaret.getCharacterBefore();
6270
let charAfter = defaultCaret.getCharacter();

js/var.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const valuePrefix = '<div class="value">';
88
const valueSuffix = '</div>';
99

1010
var lineRef = [];
11-
var defaultCaret = new Caret(0,1,1);
12-
var shiftKey = new Key(16, '');
13-
var ctrlKey = new Key(17, '');
14-
var altKey = new Key(18, '');
11+
const defaultCaret = new Caret(0,1,1);
12+
const shiftKey = new Key(16, '');
13+
const ctrlKey = new Key(17, '');
14+
const altKey = new Key(18, '');
15+
const capsLockKey = new Key(20, '');
1516
var ignoreKeyList = [16, 17, 18];

0 commit comments

Comments
 (0)