diff options
| author | Alon Levy <alon@pobox.com> | 2015-03-10 13:02:07 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-03-10 13:02:31 +0200 |
| commit | 353c6b50db1a80b67c4b0511bc4171944a56b226 (patch) | |
| tree | c4d194f606df3719f187c04c462eee0499ecf5ca /src/client/keyshortcuts.js | |
| parent | 3ebb8554564760482eeabb079813db589e734a51 (diff) | |
client: graph_view: handle keyboard events when svg nodes are focused
enter to open edit, space and shift-space to select/append.
Diffstat (limited to 'src/client/keyshortcuts.js')
| -rw-r--r-- | src/client/keyshortcuts.js | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/client/keyshortcuts.js b/src/client/keyshortcuts.js index 92f4182b..4e85df2f 100644 --- a/src/client/keyshortcuts.js +++ b/src/client/keyshortcuts.js @@ -11,11 +11,23 @@ function get_rz_core() return rz_core; } +function get_graph_view(element) +{ + var dict = get_rz_core().root_element_id_to_graph_view; + + while (undefined !== element && null !== element && undefined === dict[element.id]) { + element = element.parentElement; + } + return element !== undefined && element !== null ? dict[element.id] : undefined; +} + function install() { document.body.onkeydown = function(e) { var key = ((e.key && String(e.key)) || (e.charCode && String.fromCharCode(e.charCode)) - || (e.which && String.fromCharCode(e.which))).toLowerCase(); + || (e.which && String.fromCharCode(e.which))).toLowerCase(), + handled = false, + graph_view = get_graph_view(e.target); if (e.altKey && e.ctrlKey && 'i' === key) { $('#textanalyser').focus(); @@ -25,12 +37,19 @@ function install() { } if (e.ctrlKey && 'a' === key && e.target === document.body) { selection.update(get_rz_core().main_graph.nodes(), false); - e.preventDefault(); - e.stopPropagation(); + handled = true; } if (e.ctrlKey && 'z' === key && e.target.nodeName !== 'INPUT') { // TODO: rz_core.main_graph.undo(); } + // SVG elements cannot handle any keys directly - pass the key to them in this case + if (undefined !== graph_view) { + graph_view.keyboard_handler(e); + } + if (handled) { + e.preventDefault(); + e.stopPropagation(); + } }; } return { |
