From b6f82aa8cf0c12d280744c67a57ee4e8f82f8efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=BCnter?= Date: Thu, 12 Sep 2019 14:29:52 +0200 Subject: [PATCH] Command palette: Jump to files on Diff/Stage page (#2913) * Patch/Diff: Command palette for file jump * change hotkey to F2 * cleanup * Improve JS func call --- src/ui/zabapgit_js_common.w3mi.data.js | 28 +++++++++++++++++++--- src/ui/zcl_abapgit_gui_page_diff.clas.abap | 5 ++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/ui/zabapgit_js_common.w3mi.data.js b/src/ui/zabapgit_js_common.w3mi.data.js index bcdf0a074..29065e9e3 100644 --- a/src/ui/zabapgit_js_common.w3mi.data.js +++ b/src/ui/zabapgit_js_common.w3mi.data.js @@ -23,6 +23,7 @@ /* exported getIndocStyleSheet */ /* exported addMarginBottom */ /* exported enumerateTocAllRepos */ +/* exported enumerateJumpAllFiles */ /********************************************************** * Polyfills @@ -599,8 +600,10 @@ function DiffHelper(params) { // Action on jump click DiffHelper.prototype.onJump = function(e){ - if (!e.target.text) return; - var elFile = document.querySelector("[data-file*='" + e.target.text + "']"); + var text = ((e.target && e.target.text) || e); + if (!text) return; + + var elFile = document.querySelector("[data-file*='" + text + "']"); if (!elFile) return; setTimeout(function(){ @@ -1663,7 +1666,11 @@ CommandPalette.prototype.handleUlClick = function(event) { CommandPalette.prototype.exec = function(cmd) { if (!cmd) return; this.toggleDisplay(false); - submitSapeventForm(null, cmd.action); + if (typeof cmd.action === "function"){ + cmd.action(); + } else { + submitSapeventForm(null, cmd.action); + } }; /* COMMAND ENUMERATORS */ @@ -1724,3 +1731,18 @@ function enumerateToolbarActions() { return items; } + +function enumerateJumpAllFiles() { + var root = document.getElementById("jump"); + if (!root || root.nodeName !== "UL") return null; + + return Array + .prototype.slice.call(root.children) + .filter(function(elem) { return elem.nodeName === "LI" }) + .map(function(listItem) { + var title = listItem.children[0].childNodes[0].textContent; + return { + action: root.onclick.bind(null, title), + title: title + };}); +} diff --git a/src/ui/zcl_abapgit_gui_page_diff.clas.abap b/src/ui/zcl_abapgit_gui_page_diff.clas.abap index 85aa068b1..4715721b0 100644 --- a/src/ui/zcl_abapgit_gui_page_diff.clas.abap +++ b/src/ui/zcl_abapgit_gui_page_diff.clas.abap @@ -967,6 +967,11 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_DIFF IMPLEMENTATION. ro_html->add( 'addMarginBottom();' ). + ro_html->add( 'var gGoJumpPalette = new CommandPalette(enumerateJumpAllFiles, {' ). + ro_html->add( ' toggleKey: "F2",' ). + ro_html->add( ' hotkeyDescription: "Jump to file ..."' ). + ro_html->add( '});' ). + ENDMETHOD.