Skip to content

Commit 84d560e

Browse files
committed
#11 Context menu closes on the next mouse interaction, instead of when the mouse leaves the context menu.
1 parent 3eccc50 commit 84d560e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

media/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ svg.openFolderIcon, svg.closedFolderIcon, svg.fileIcon{
326326
display:none;
327327
position:absolute;
328328
background-color:var(--vscode-menu-background);
329-
box-shadow:0 1px 3px 1px var(--vscode-widget-shadow);
329+
box-shadow:0 1px 4px 1px var(--vscode-widget-shadow);
330330
color:var(--vscode-menu-foreground);
331331
list-style-type:none;
332332
margin:0;

web/main.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@
544544
], sourceElem);
545545
});
546546
addListenerToClass('commit', 'click', (e: Event) => {
547-
e.stopPropagation();
548547
let sourceElem = <HTMLElement>(<Element>e.target).closest('.commit')!;
549548
if (this.expandedCommit !== null && this.expandedCommit.hash === sourceElem.dataset.hash!) {
550549
this.hideCommitDetails();
@@ -871,6 +870,7 @@
871870
html += '<li class="contextMenuItem" data-index="' + i + '">' + items[i].title + '</li>';
872871
}
873872

873+
hideContextMenuListener();
874874
contextMenu.style.opacity = '0';
875875
contextMenu.className = 'active';
876876
contextMenu.innerHTML = html;
@@ -880,10 +880,10 @@
880880
contextMenu.style.opacity = '1';
881881

882882
addListenerToClass('contextMenuItem', 'click', (e) => {
883+
e.stopPropagation();
883884
hideContextMenu();
884885
items[parseInt((<HTMLElement>(e.target)).dataset.index!)].onClick();
885886
});
886-
contextMenu.addEventListener('mouseleave', hideContextMenu);
887887

888888
contextMenuSource = sourceElem;
889889
contextMenuSource.classList.add('contextMenuActive');
@@ -893,7 +893,6 @@
893893
contextMenu.innerHTML = '';
894894
contextMenu.style.left = '0px';
895895
contextMenu.style.top = '0px';
896-
contextMenu.removeEventListener('mouseleave', hideContextMenu);
897896
if (contextMenuSource !== null) {
898897
contextMenuSource.classList.remove('contextMenuActive');
899898
contextMenuSource = null;
@@ -973,7 +972,18 @@
973972
dialogMenuSource = null;
974973
}
975974
}
975+
976+
/* Global Listeners */
976977
document.addEventListener('keyup', (e) => {
977-
if (e.key === 'Escape' && dialog.classList.contains('active')) hideDialog();
978+
if (e.key === 'Escape') {
979+
if (dialog.classList.contains('active')) hideDialog();
980+
hideContextMenuListener();
981+
}
978982
});
983+
document.addEventListener('click', hideContextMenuListener);
984+
document.addEventListener('contextmenu', hideContextMenuListener);
985+
document.addEventListener('mouseleave', hideContextMenuListener);
986+
function hideContextMenuListener() {
987+
if (contextMenu.classList.contains('active')) hideContextMenu();
988+
}
979989
}());

0 commit comments

Comments
 (0)