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
This commit is contained in:
Christian Günter 2019-09-12 14:29:52 +02:00 committed by Lars Hvam
parent 880f6a8b28
commit b6f82aa8cf
2 changed files with 30 additions and 3 deletions

View File

@ -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);
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
};});
}

View File

@ -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.