Created
December 19, 2013 16:41
-
-
Save datatravelandexperiments/8042259 to your computer and use it in GitHub Desktop.
WIP for keyboard-layout-editor: Added prefix count for motion and size operations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From aab2d58869a1b4b05a107a1e611d0e131045a3b3 Mon Sep 17 00:00:00 2001 | |
From: Kevin Schoedel <[email protected]> | |
Date: Thu, 19 Dec 2013 11:00:44 -0500 | |
Subject: [PATCH] Added prefix count for motion and size operations. | |
MIME-Version: 1.0 | |
Content-Type: text/plain; charset=UTF-8 | |
Content-Transfer-Encoding: 8bit | |
The user can type a number and optional unit that will be used as | |
a value by certain following commands. | |
0 - 9 . - value | |
u - standard key size (1u = ¾″) | |
i - inches | |
m - millimetres (doubling this as ‘mm’ is also accepted) | |
, - retrieve previous value | |
For the movement and size commands (←↓↑→ and shifted ←↓↑→), a value | |
without a unit is interpreted as a number of ¼u steps; that is, like | |
a repeat count of the operation. For instance, “2→” moves the selected | |
keys 2 steps to the right (one half unit), while “2u→” moves the keys | |
two units to the right. | |
Additional shortcuts: | |
x - set the selected key(s) X position | |
y - set the selected key(s) Y position | |
w - set the selected key(s) width | |
h - set the selected key(s) height | |
For these shortcuts, a value without a unit is taken to be in key sizes, | |
(same as entered in the input box); so “2w” and “2uw” and “1.5iw” all | |
set the selected keys to be 1.5 inches wide. | |
Commands that use the count reset it; for example “2→↑” moves the key | |
two steps to the right and one step up. The comma “,” shortcut retrieves | |
the last used count; for example “2→,↑” moves the key two steps right | |
and two steps up. | |
TO DO: | |
- display the current count somewhere! (and indicate whether it is valid) | |
- backspace to edit the count | |
- accept EE-style embedded units, e.g. “2u5” = “2.5u” | |
- more shortcuts, e.g. shift-W for secondary width | |
--- | |
kb.html | 39 +++++++++++++++++------- | |
kb.js | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
2 files changed, 132 insertions(+), 10 deletions(-) | |
diff --git a/kb.html b/kb.html | |
index 917fd7d..25eacfa 100644 | |
--- a/kb.html | |
+++ b/kb.html | |
@@ -102,14 +102,14 @@ All rights reserved. | |
<div id="keyboard" | |
tabindex="0" | |
ng-style="{height: kbHeight + 'px', 'background-color': keyboard.meta.backcolor}" | |
- ui-keydown="{ left:'moveKeys(-.25,0,$event)', | |
- right:'moveKeys(.25,0,$event)', | |
- up:'moveKeys(0,-.25,$event)', | |
- down:'moveKeys(0,.25,$event)', | |
- 'shift-left':'sizeKeys(-.25,0,$event)', | |
- 'shift-right':'sizeKeys(.25,0,$event)', | |
- 'shift-up':'sizeKeys(0,-.25,$event)', | |
- 'shift-down':'sizeKeys(0,.25,$event)', | |
+ ui-keydown="{ left:'moveKeys(-1,0,$event)', | |
+ right:'moveKeys(1,0,$event)', | |
+ up:'moveKeys(0,-1,$event)', | |
+ down:'moveKeys(0,1,$event)', | |
+ 'shift-left':'sizeKeys(-1,0,$event)', | |
+ 'shift-right':'sizeKeys(1,0,$event)', | |
+ 'shift-up':'sizeKeys(0,-1,$event)', | |
+ 'shift-down':'sizeKeys(0,1,$event)', | |
'pageup':'rotateKeys(-15,$event)', | |
'pagedown':'rotateKeys(15,$event)', | |
'ctrl-left':'moveCenterKeys(-.25,0,$event)', | |
@@ -118,11 +118,30 @@ All rights reserved. | |
'ctrl-down':'moveCenterKeys(0,.25,$event)', | |
delete:'deleteKeys()', | |
insert:'addKey()', | |
+ 48: 'updateCount(\'0\',$event)', | |
+ 49: 'updateCount(\'1\',$event)', | |
+ 50: 'updateCount(\'2\',$event)', | |
+ 51: 'updateCount(\'3\',$event)', | |
+ 52: 'updateCount(\'4\',$event)', | |
+ 53: 'updateCount(\'5\',$event)', | |
+ 54: 'updateCount(\'6\',$event)', | |
+ 55: 'updateCount(\'7\',$event)', | |
+ 56: 'updateCount(\'8\',$event)', | |
+ 57: 'updateCount(\'9\',$event)', | |
+ 72: 'updatePropFromCount(\'size\',\'height\',$event)', | |
+ 73: 'updateCount(\'i\',$event)', | |
74: 'prevKey($event)', | |
75: 'nextKey($event)', | |
+ 77: 'updateCount(\'m\',$event)', | |
+ 85: 'updateCount(\'u\',$event)', | |
+ 87: 'updatePropFromCount(\'size\',\'width\',$event)', | |
+ 88: 'updatePropFromCount(\'move\',\'x\',$event)', | |
+ 89: 'updatePropFromCount(\'move\',\'y\',$event)', | |
+ 113: 'focusEditor()', | |
+ 188: 'restoreCount($event)', | |
+ 190: 'updateCount(\'.\',$event)', | |
'shift-74': 'prevKey($event)', | |
'shift-75': 'nextKey($event)', | |
- 113: 'focusEditor()', | |
esc: 'unselectAll()', | |
'ctrl-65': 'selectAll($event)', | |
'ctrl-67 ctrl-45': 'copy($event)', | |
@@ -416,4 +435,4 @@ All rights reserved. | |
</div> | |
</div> | |
</body> | |
-</html> | |
\ No newline at end of file | |
+</html> | |
diff --git a/kb.js b/kb.js | |
index 5366568..fb49097 100644 | |
--- a/kb.js | |
+++ b/kb.js | |
@@ -39,6 +39,7 @@ | |
$scope.unselectAll = function() { | |
$scope.selectedKeys = []; | |
$scope.multi = {}; | |
+ $scope.clearCount(); | |
}; | |
$scope.selectAll = function(event) { | |
if(event) { event.preventDefault(); } | |
@@ -405,6 +406,12 @@ | |
return; | |
} | |
+ if (x) { | |
+ x = $scope.consumeCount(x, 'q'); | |
+ } else { | |
+ y = $scope.consumeCount(y, 'q'); | |
+ } | |
+ | |
if(x<0 || y<0) { | |
var canMoveKeys = true; | |
$scope.selectedKeys.forEach(function(selectedKey) { | |
@@ -436,6 +443,13 @@ | |
if($scope.selectedKeys.length<1) { | |
return; | |
} | |
+ | |
+ if (x) { | |
+ x = $scope.consumeCount(x, 'q'); | |
+ } else { | |
+ y = $scope.consumeCount(y, 'q'); | |
+ } | |
+ | |
transaction("size", function() { | |
$scope.selectedKeys.forEach(function(selectedKey) { | |
update(selectedKey, 'width', Math.max(1,selectedKey.width + x)); | |
@@ -854,6 +868,95 @@ | |
$scope.keyboardTop = function() { var kbElem = $("#keyboard"); return kbElem.position().top + parseInt(kbElem.css('margin-top'),10); }; | |
$scope.keyboardLeft = function() { var kbElem = $("#keyboard"); return kbElem.position().left + parseInt(kbElem.css('margin-left'),10); }; | |
+ | |
+ // Count operand | |
+ $scope.count = ''; | |
+ $scope.countSave = ''; | |
+ $scope.clearCount = function() { | |
+ if ($scope.count != '') { | |
+ $scope.countSave = $scope.count; | |
+ $scope.count = ''; | |
+ } | |
+ } | |
+ $scope.restoreCount = function(event) { | |
+ if (event) { | |
+ event.preventDefault(); | |
+ } | |
+ if ($scope.countSave != '') { | |
+ if ($scope.count != '') { | |
+ var t = $scope.count; | |
+ $scope.count = $scope.countSave; | |
+ $scope.countSave = t; | |
+ } else { | |
+ $scope.count = $scope.countSave; | |
+ } | |
+ } | |
+ } | |
+ $scope.updateCount = function(c, event) { | |
+ if (event) { | |
+ event.preventDefault(); | |
+ } | |
+ $scope.count += c; | |
+ } | |
+ $scope.consumeCount = function(scale, defaultUnit) { | |
+ var r = scale * $scope.parseCount($scope.count, defaultUnit); | |
+ $scope.clearCount(); | |
+ return r; | |
+ } | |
+ $scope.parseCount = function(s, defaultUnit) { | |
+ var n = 1; | |
+ var u = defaultUnit; | |
+ if (s != '') { | |
+ var a = s.match(/^(\d*\.?\d*)(\D*)$/); | |
+ if (a[1] != '') { | |
+ n = parseFloat(a[1]); | |
+ } | |
+ if (a[2] != '') { | |
+ u = a[2]; | |
+ } | |
+ } | |
+ switch (u) { | |
+ case 'u': | |
+ break; | |
+ case 'q': | |
+ n *= 0.25; | |
+ break; | |
+ case 'i': | |
+ n = n * 4 / 3; | |
+ break; | |
+ case 'm': | |
+ case 'mm': | |
+ n = n * 4 / 76.2; | |
+ break; | |
+ default: | |
+ n = null; | |
+ break; | |
+ } | |
+ return n; | |
+ } | |
+ | |
+ $scope.updatePropFromCount = function(type, prop, event) { | |
+ if (event) { | |
+ event.preventDefault(); | |
+ } | |
+ if ($scope.selectedKeys.length<1) { | |
+ return; | |
+ } | |
+ if ($scope.count == '') { | |
+ // TODO: move to property input? | |
+ return; | |
+ } | |
+ var v = $scope.consumeCount(1, 'u'); | |
+ | |
+ transaction(type, function() { | |
+ $scope.selectedKeys.forEach(function(selectedKey) { | |
+ update(selectedKey, prop, v); | |
+ renderKey(selectedKey); | |
+ }); | |
+ $scope.multi = angular.copy($scope.selectedKeys.last()); | |
+ }); | |
+ } | |
+ | |
}]); | |
// Modernizr-inspired check to see if "color" input fields are supported; | |
-- | |
1.8.4.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment