Skip to content

Commit e35f59a

Browse files
committed
feat: add keyboard shortcuts for BST, AVL, LinkedList, ArrayList
1 parent 734b9d4 commit e35f59a

7 files changed

Lines changed: 242 additions & 44 deletions

File tree

src/algo/AVL.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default class AVL extends Algorithm {
5959
4,
6060
false,
6161
);
62+
this.insertField.setAttribute('data-shortcut-target', 'insert');
6263
this.controls.push(this.insertField);
6364

6465
this.insertButton = addControlToAlgorithmBar('Button', 'Insert');
@@ -75,6 +76,7 @@ export default class AVL extends Algorithm {
7576
4,
7677
false,
7778
);
79+
this.deleteField.setAttribute('data-shortcut-target', 'delete');
7880
this.controls.push(this.deleteField);
7981

8082
this.deleteButton = addControlToAlgorithmBar('Button', 'Delete');
@@ -91,6 +93,7 @@ export default class AVL extends Algorithm {
9193
4,
9294
false,
9395
);
96+
this.findField.setAttribute('data-shortcut-target', 'find');
9497
this.controls.push(this.findField);
9598

9699
this.findButton = addControlToAlgorithmBar('Button', 'Find');
@@ -311,12 +314,12 @@ export default class AVL extends Algorithm {
311314
act.setText,
312315
0,
313316
'Searching for ' +
314-
value +
315-
' : ' +
316-
value +
317-
' < ' +
318-
tree.data +
319-
' (look to left subtree)',
317+
value +
318+
' : ' +
319+
value +
320+
' < ' +
321+
tree.data +
322+
' (look to left subtree)',
320323
);
321324
this.cmd(act.step);
322325
this.cmd(act.setHighlight, tree.graphicID, 0);
@@ -338,12 +341,12 @@ export default class AVL extends Algorithm {
338341
act.setText,
339342
0,
340343
' Searching for ' +
341-
value +
342-
' : ' +
343-
value +
344-
' > ' +
345-
tree.data +
346-
' (look to right subtree)',
344+
value +
345+
' : ' +
346+
value +
347+
' > ' +
348+
tree.data +
349+
' (look to right subtree)',
347350
);
348351
this.cmd(act.step);
349352
this.cmd(act.setHighlight, tree.graphicID, 0);
@@ -438,7 +441,7 @@ export default class AVL extends Algorithm {
438441
this.resizeTree();
439442
const connected = this.connectSmart(curr.graphicID, curr.left.graphicID);
440443
connected && this.cmd(act.step);
441-
// } else if (data > curr.data) {
444+
// } else if (data > curr.data) {
442445
} else if (this.compare(data, curr.data) > 0) {
443446
this.cmd(act.setText, 0, `${data} > ${curr.data}. Looking at right subtree`);
444447
this.cmd(act.step);
@@ -683,7 +686,7 @@ export default class AVL extends Algorithm {
683686
this.connectSmart(curr.graphicID, curr.left.graphicID);
684687
this.resizeTree();
685688
}
686-
// } else if (data > curr.data) {
689+
// } else if (data > curr.data) {
687690
} else if (this.compare(data, curr.data) > 0) {
688691
this.cmd(act.setText, 0, `${data} > ${curr.data}. Looking right`);
689692
this.cmd(act.step);

src/algo/ArrayList.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export default class ArrayList extends Algorithm {
8282
4,
8383
false,
8484
);
85+
this.addValueField.setAttribute('data-shortcut-target', 'insert');
8586
this.controls.push(this.addValueField);
8687

8788
addLabelToAlgorithmBar('at index', addTopHorizontalGroup);
@@ -143,6 +144,7 @@ export default class ArrayList extends Algorithm {
143144
4,
144145
true,
145146
);
147+
this.removeField.setAttribute('data-shortcut-target', 'delete');
146148
this.controls.push(this.removeField);
147149

148150
// Remove from index button

src/algo/BST.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default class BST extends Algorithm {
7575
4,
7676
false,
7777
);
78+
this.insertField.setAttribute('data-shortcut-target', 'insert');
7879
this.controls.push(this.insertField);
7980

8081
this.insertButton = addControlToAlgorithmBar('Button', 'Insert');
@@ -91,6 +92,7 @@ export default class BST extends Algorithm {
9192
4,
9293
false,
9394
);
95+
this.deleteField.setAttribute('data-shortcut-target', 'delete');
9496
this.controls.push(this.deleteField);
9597

9698
this.deleteButton = addControlToAlgorithmBar('Button', 'Delete');
@@ -107,6 +109,7 @@ export default class BST extends Algorithm {
107109
4,
108110
false,
109111
);
112+
this.findField.setAttribute('data-shortcut-target', 'find');
110113
this.controls.push(this.findField);
111114

112115
this.findButton = addControlToAlgorithmBar('Button', 'Find');
@@ -603,12 +606,12 @@ export default class BST extends Algorithm {
603606
act.setText,
604607
0,
605608
'Searching for ' +
606-
value +
607-
' : ' +
608-
value +
609-
' < ' +
610-
tree.data +
611-
' (look to left subtree)',
609+
value +
610+
' : ' +
611+
value +
612+
' < ' +
613+
tree.data +
614+
' (look to left subtree)',
612615
);
613616
this.cmd(act.step);
614617

@@ -635,12 +638,12 @@ export default class BST extends Algorithm {
635638
act.setText,
636639
0,
637640
' Searching for ' +
638-
value +
639-
' : ' +
640-
value +
641-
' > ' +
642-
tree.data +
643-
' (look to right subtree)',
641+
value +
642+
' : ' +
643+
value +
644+
' > ' +
645+
tree.data +
646+
' (look to right subtree)',
644647
);
645648
this.cmd(act.step);
646649
this.cmd(act.setHighlight, tree.graphicID, 0, 'find');
@@ -765,7 +768,7 @@ export default class BST extends Algorithm {
765768
this.resizeTree();
766769
const connected = this.connectSmart(curr.graphicID, curr.left.graphicID);
767770
connected && this.cmd(act.step);
768-
// } else if (data > curr.data) {
771+
// } else if (data > curr.data) {
769772
} else if (this.compare(data, curr.data) > 0) {
770773
this.highlight(10, 0, 'add');
771774
this.highlight(11, 0, 'add');
@@ -865,7 +868,7 @@ export default class BST extends Algorithm {
865868
this.connectSmart(curr.graphicID, curr.left.graphicID);
866869
this.resizeTree();
867870
}
868-
// } else if (data > curr.data) {
871+
// } else if (data > curr.data) {
869872
} else if (this.compare(data, curr.data)) {
870873
this.highlight(11, 0, this.predSuccMethod);
871874
this.highlight(12, 0, this.predSuccMethod);

src/algo/LinkedList.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export default class LinkedList extends Algorithm {
9797
4,
9898
false,
9999
);
100+
this.addValueField.setAttribute('data-shortcut-target', 'insert');
100101
this.controls.push(this.addValueField);
101102

102103
addLabelToAlgorithmBar('at index', addTopHorizontalGroup);
@@ -158,6 +159,7 @@ export default class LinkedList extends Algorithm {
158159
4,
159160
true,
160161
);
162+
this.removeField.setAttribute('data-shortcut-target', 'delete');
161163
this.controls.push(this.removeField);
162164

163165
// Remove from index button
@@ -838,8 +840,8 @@ export default class LinkedList extends Algorithm {
838840
runningRemoveIndexOnly
839841
? this.highlight(12, 0, 'removeIndex')
840842
: runningRemoveBack
841-
? this.highlight(10, 0, 'removeBack')
842-
: this.highlight(3, 0, 'removeFront');
843+
? this.highlight(10, 0, 'removeBack')
844+
: this.highlight(3, 0, 'removeFront');
843845

844846
this.cmd(act.step);
845847
this.cmd(act.delete, this.linkedListElemID[index]);
@@ -863,8 +865,8 @@ export default class LinkedList extends Algorithm {
863865
runningRemoveIndexOnly
864866
? this.highlight(13, 0, 'removeIndex')
865867
: runningRemoveBack
866-
? this.highlight(11, 0, 'removeBack')
867-
: this.highlight(4, 0, 'removeFront');
868+
? this.highlight(11, 0, 'removeBack')
869+
: this.highlight(4, 0, 'removeFront');
868870
this.cmd(act.step);
869871

870872
return this.commands;

0 commit comments

Comments
 (0)