Skip to content

Commit 8df51fb

Browse files
committed
feat(taRegisterTool('indent'), taRegisterTool('outdent')): Enhanced toolbar to handle TAB and SHIFT-TAB KEYS.
The _keydown() function in main.js now detets the keyCode:9 (the TAB key) and keyCode:9 + shiftKey. These two key events cause a specialKey property to be added to the key event: TAB key -> specialKey: 'TabKey' Shift TAB key -> specialKey: 'ShiftTabKey' which is then passed on to _keypress(). taRegisterTool('indent', ...) is enhanced with a commandKeyCode: 'TabKey' -- so that the Tab key triggers an indent taRegisterTool('outdent', ...) is enhanced with a commandKeyCode: 'ShiftTabKey' -- so that the Shift-Tab key triggers an outdent. The textAngularManager::sendKeyCommand() detects the event.specialKey and then calls the registered tools. Closes #734 and pull request #742
1 parent 69b0af5 commit 8df51fb

7 files changed

+41
-15
lines changed

dist/textAngular-rangy.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/textAngular-sanitize.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/textAngular.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ textAngular.directive("textAngular", [
22062206
}else{
22072207
scope.displayElements.text[0].focus();
22082208
}
2209-
$window.rangy.restoreSelection(_savedSelection);
2209+
// $window.rangy.restoreSelection(_savedSelection);
22102210
$window.rangy.removeMarkers(_savedSelection);
22112211
}
22122212
_savedSelection = false;
@@ -2396,6 +2396,17 @@ textAngular.directive("textAngular", [
23962396
};
23972397
// start updating on keydown
23982398
_keydown = function(){
2399+
// keyCode 9 is the TAB key
2400+
/* istanbul ignore next: not sure how to test this */
2401+
if (event.ctrlKey===false && event.metaKey===false && event.keyCode===9) {
2402+
event.preventDefault();
2403+
var extraEventData = { specialKey: 'TabKey' };
2404+
if (event.shiftKey) {
2405+
extraEventData.specialKey = 'ShiftTabKey';
2406+
}
2407+
// since nether tab nor shift-tab generate a keypress event, we call directly
2408+
_keypress(event, extraEventData);
2409+
}
23992410
/* istanbul ignore next: ie catch */
24002411
if(!scope.focussed){
24012412
scope._bUpdateSelectedStyles = false;
@@ -2516,8 +2527,8 @@ textAngular.service('textAngularManager', ['taToolExecuteAction', 'taTools', 'ta
25162527
sendKeyCommand: function(event){
25172528
// we return true if we applied an action, false otherwise
25182529
var result = false;
2519-
if(event.ctrlKey || event.metaKey) angular.forEach(taTools, function(tool, name){
2520-
if(tool.commandKeyCode && tool.commandKeyCode === event.which){
2530+
if(event.ctrlKey || event.metaKey || event.specialKey) angular.forEach(taTools, function(tool, name){
2531+
if(tool.commandKeyCode && (tool.commandKeyCode === event.which || tool.commandKeyCode === event.specialKey)){
25212532
for(var _t = 0; _t < _toolbars.length; _t++){
25222533
if(_toolbars[_t].tools[name] !== undefined){
25232534
taToolExecuteAction.call(_toolbars[_t].tools[name], scope);

0 commit comments

Comments
 (0)