From 794202225efb5e29bf35657370fecf12dcb43b23 Mon Sep 17 00:00:00 2001 From: Tianci He Date: Tue, 8 Dec 2020 20:14:56 +0800 Subject: [PATCH] feat: add hotkey support for deleting rules and values --- biz/webui/htdocs/src/js/index.js | 11 +++++++++++ biz/webui/htdocs/src/js/util.js | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/biz/webui/htdocs/src/js/index.js b/biz/webui/htdocs/src/js/index.js index c98e05d7c..5b12124b5 100644 --- a/biz/webui/htdocs/src/js/index.js +++ b/biz/webui/htdocs/src/js/index.js @@ -749,6 +749,17 @@ var Index = React.createClass({ self.importSessions(e); e.preventDefault(); } + + if ( + (util.IS_MACOS && e.key === 'Backspace' && e.metaKey === true) || + (!util.IS_MACOS && e.key === 'Delete') + ) { + if (self.state.name === 'rules') { + self.removeRules(); + } else if (self.state.name === 'values') { + self.removeValues(); + } + } }); function getKey(url) { diff --git a/biz/webui/htdocs/src/js/util.js b/biz/webui/htdocs/src/js/util.js index 658a6fc0a..4b1af4493 100644 --- a/biz/webui/htdocs/src/js/util.js +++ b/biz/webui/htdocs/src/js/util.js @@ -17,6 +17,10 @@ var dragTarget, dragOffset, dragCallback; var logTempId = 0; var LEVELS = ['fatal', 'error', 'warn', 'info', 'debug']; +var IS_MACOS = navigator.userAgent.indexOf('Macintosh') >= 0; + +exports.IS_MACOS = IS_MACOS; + function noop(_) { return _; } @@ -277,7 +281,7 @@ exports.getExtension = function(headers) { } type = type || getRawType(headers); type = type.substring(type.indexOf('/') + 1).toLowerCase(); - return /\w+/.test(type) ? '.' + RegExp['$&'] : ''; + return /\w+/.test(type) ? '.' + RegExp['$&'] : ''; }; function getContentType(type) {