Project

General

Profile

Defect #5908 » 0001-Fix-context-menu-and-its-submenus-extending-beyond-t.patch

Go MAEDA, 2026-11-21 09:15

View differences:

app/assets/javascripts/context_menu.js
var window_height;
var max_width;
var max_height;
var min_y;
var url;
$('#context-menu').css('left', (render_x + 'px'));
......
}
if (max_height > window_height) {
render_y -= menu_height;
$('#context-menu').addClass('reverse-y');
// adding class for submenu
if (mouse_y_c < 325) {
$('#context-menu .folder').addClass('down');
}
render_y -= menu_height;
$('#context-menu').addClass('reverse-y');
} else {
// adding class for submenu
if (window_height - mouse_y_c < 345) {
$('#context-menu .folder').addClass('up');
}
$('#context-menu').removeClass('reverse-y');
}
/* keep the top left corner of the menu inside the visible area */
min_y = $(window).scrollTop() + 1;
if (render_x <= 0) render_x = 1;
if (render_y <= 0) render_y = 1;
if (render_y < min_y) render_y = min_y;
$('#context-menu').css('left', (render_x + 'px'));
$('#context-menu').css('top', (render_y + 'px'));
$('#context-menu').show();
contextMenuAdjustSubmenus(window_height);
//if (window.parseStylesheets) { window.parseStylesheets(); } // IE
}
});
}
/* open each submenu in the direction where it fits in the visible area */
function contextMenuAdjustSubmenus(window_height) {
var menu = document.getElementById('context-menu');
var reverse_y = menu.classList.contains('reverse-y');
menu.querySelectorAll('li.folder').forEach(function(folder) {
var submenu = folder.querySelector(':scope > ul');
var rect = folder.getBoundingClientRect();
if (!submenu || rect.height === 0) {return;}
/* submenus are hidden until hovered, so display them invisibly to measure */
submenu.style.maxHeight = '';
submenu.style.visibility = 'hidden';
submenu.style.display = 'block';
var submenu_height = submenu.offsetHeight;
var style = getComputedStyle(submenu);
/* max-height does not include the padding and the border */
var extra_height = ['paddingTop', 'paddingBottom', 'borderTopWidth', 'borderBottomWidth']
.reduce(function(sum, name) { return sum + parseFloat(style[name]); }, 0);
submenu.style.display = '';
submenu.style.visibility = '';
var space_below = window_height - rect.top;
var space_above = rect.bottom;
var open_up = submenu_height > space_below && space_above > space_below;
var space = Math.floor(open_up ? space_above : space_below);
/* submenus of a menu displayed above the click open upward by default */
folder.classList.toggle('up', open_up && !reverse_y);
folder.classList.toggle('down', !open_up && reverse_y);
if (submenu_height > space) {
submenu.style.maxHeight = (space - extra_height) + 'px';
}
});
}
function contextMenuSetLastSelected(tr) {
$('.cm-last').removeClass('cm-last');
tr.addClass('cm-last');
test/system/issues_test.rb
assert page.first('#sidebar').has_content?(user.name)
end
def test_context_menu_submenu_should_not_overflow_the_top_of_the_viewport
log_user('jsmith', 'jsmith')
page.current_window.resize_to(1024, 600)
visit '/issues'
# The menu does not fit below the click and is displayed above it
first('table.issues tr.issue td.updated_on').right_click
folder = find('#context-menu.reverse-y li.folder', text: 'Priority')
folder.hover
assert_operator page.evaluate_script('arguments[0].getBoundingClientRect().top', folder.find('ul')), :>=, 0
ensure
page.current_window.resize_to(1024, 900)
end
def test_watch_issue_via_context_menu
log_user('jsmith', 'jsmith')
visit '/issues'
(3-3/6)