Project

General

Profile

Feature #43259 » 0001-Keep-wiki-toolbar-menus-from-being-clipped-by-the-fo.patch

Go MAEDA, 2026-11-03 09:10

View differences:

app/assets/stylesheets/jstoolbar.css
}
.table-generator, .jstMenu {
position: absolute;
position: fixed;
z-index: 100;
}
app/javascript/controllers/wiki_toolbar_controller.js
if (!this.menu.contains(event.target) && !currentTarget.contains(event.target)) this.closeMenu()
}
document.addEventListener('mousedown', this.closeMenuOnOutsideClick)
// The menu has a fixed position so that it is not clipped by the form
this.repositionMenu = () => this.positionMenu(currentTarget)
window.addEventListener('scroll', this.repositionMenu, { capture: true, passive: true })
window.addEventListener('resize', this.repositionMenu)
this.menu.querySelector('button')?.focus()
}
......
if (!this.menu) return
document.removeEventListener('mousedown', this.closeMenuOnOutsideClick)
window.removeEventListener('scroll', this.repositionMenu, { capture: true })
window.removeEventListener('resize', this.repositionMenu)
this.menu.remove()
this.menu = null
this.closeMenuOnOutsideClick = null
this.repositionMenu = null
}
highlightTable({ target }) {
......
}
positionMenu(button) {
const parent = this.menu.offsetParent || document.documentElement
const parentRect = parent.getBoundingClientRect()
const blockRect = this.element.getBoundingClientRect()
const buttonRect = button.getBoundingClientRect()
const left = buttonRect.left - parentRect.left + parent.scrollLeft
const maxLeft = this.element.clientWidth - this.menu.offsetWidth
this.menu.style.left = `${Math.max(0, Math.min(left, maxLeft))}px`
this.menu.style.top = `${buttonRect.bottom - parentRect.top + parent.scrollTop}px`
const maxLeft = blockRect.left + this.element.clientWidth - this.menu.offsetWidth
this.menu.style.left = `${Math.max(blockRect.left, Math.min(buttonRect.left, maxLeft))}px`
this.menu.style.top = `${buttonRect.bottom}px`
}
encloseSelection(prefix, suffix) {
test/system/wiki_toolbar_test.rb
assert_equal false, overflow
end
def test_precode_menu_should_not_be_clipped_by_the_form
log_user('jsmith', 'jsmith')
visit '/projects/ecookbook/issues/new'
find('button.jstb_precode').click
assert_selector '.jstMenu'
visible = page.evaluate_script(<<~JS)
(() => {
const menu = document.querySelector('.jstMenu')
const rect = menu.getBoundingClientRect()
return menu.contains(document.elementFromPoint(rect.left + rect.width / 2, rect.bottom - 5))
})()
JS
assert visible
end
private
def select_text(id, start, finish)
(9-9/13)