From aa1c792d1aaf18928bd6845f3c9ea4b7fd61e6cb Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Wed, 10 Dec 2014 16:32:46 -0800 Subject: [PATCH] fix(batScopeTree): unfocus model editing on enter/exit keydown --- panel/components/json-tree/json-tree.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/panel/components/json-tree/json-tree.js b/panel/components/json-tree/json-tree.js index 86e3d47..e0477fe 100644 --- a/panel/components/json-tree/json-tree.js +++ b/panel/components/json-tree/json-tree.js @@ -3,6 +3,9 @@ angular.module('batarang.json-tree', []). var BAT_JSON_TREE_TEMPLATE = '
'; +var ENTER_KEY = 13, + EXIT_KEY = 27; + var BAT_JSON_TREE_UNEDITABLE = [ '$id', @@ -120,12 +123,23 @@ function batJsonTreeDirective() { ''); // TODO: test this - childElt.on('blur', function () { + childElt.on('keydown', function (ev) { + if (ev.keyCode === ENTER_KEY || ev.keyCode === EXIT_KEY) { + ev.preventDefault(); + childElt[0].blur(); + doAssign(); + } + }); + + // TODO: test this + childElt.on('blur', doAssign); + + function doAssign() { scope.batAssign({ path: fullPath, value: childElt.text() }); - }); + } } }