diff --git a/src/public/app/services/context_menu.js b/src/public/app/services/context_menu.js index fde332b0e..f1ee8fd48 100644 --- a/src/public/app/services/context_menu.js +++ b/src/public/app/services/context_menu.js @@ -25,21 +25,46 @@ class ContextMenu { positionMenu() { // code below tries to detect when dropdown would overflow from page // in such case we'll position it above click coordinates so it will fit into client + + const CONTEXT_MENU_PADDING = 5; // How many pixels to pad context menu from edge of screen + const CONTEXT_MENU_OFFSET = 10; // How many pixels to offset context menu by relative to cursor + const clientHeight = document.documentElement.clientHeight; - const contextMenuHeight = this.$widget.outerHeight() + 30; + const clientWidth = document.documentElement.clientWidth; + const contextMenuHeight = this.$widget.outerHeight(); + const contextMenuWidth = this.$widget.outerWidth(); let top, left; - if (this.options.y + contextMenuHeight > clientHeight) { - top = clientHeight - contextMenuHeight - 10; + if (this.options.y + contextMenuHeight - CONTEXT_MENU_OFFSET > clientHeight - CONTEXT_MENU_PADDING) { + // Overflow: bottom + top = clientHeight - contextMenuHeight - CONTEXT_MENU_PADDING; + } else if (this.options.y - CONTEXT_MENU_OFFSET < CONTEXT_MENU_PADDING) { + // Overflow: top + top = CONTEXT_MENU_PADDING; } else { - top = this.options.y - 10; + top = this.options.y - CONTEXT_MENU_OFFSET; } if (this.options.orientation === 'left') { - left = this.options.x - this.$widget.outerWidth() + 20; - } - else { - left = this.options.x - 20; + if (this.options.x + CONTEXT_MENU_OFFSET > clientWidth - CONTEXT_MENU_PADDING) { + // Overflow: right + left = clientWidth - contextMenuWidth - CONTEXT_MENU_OFFSET; + } else if (this.options.x - contextMenuWidth + CONTEXT_MENU_OFFSET < CONTEXT_MENU_PADDING) { + // Overflow: left + left = CONTEXT_MENU_PADDING; + } else { + left = this.options.x - contextMenuWidth + CONTEXT_MENU_OFFSET; + } + } else { + if (this.options.x + contextMenuWidth - CONTEXT_MENU_OFFSET > clientWidth - CONTEXT_MENU_PADDING) { + // Overflow: right + left = clientWidth - contextMenuWidth - CONTEXT_MENU_PADDING; + } else if (this.options.x - CONTEXT_MENU_OFFSET < CONTEXT_MENU_PADDING) { + // Overflow: left + left = CONTEXT_MENU_PADDING; + } else { + left = this.options.x - CONTEXT_MENU_OFFSET; + } } this.$widget.css({ diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.js index 3aceb4278..ccec6d9ab 100644 --- a/src/public/app/widgets/tab_row.js +++ b/src/public/app/widgets/tab_row.js @@ -51,7 +51,6 @@ const TAB_ROW_TPL = ` width: 100%; background: var(--main-background-color); overflow: hidden; - margin-top: 2px; } .tab-row-widget * { diff --git a/src/public/app/widgets/title_bar_buttons.js b/src/public/app/widgets/title_bar_buttons.js index d1a302e2b..ed84b19d4 100644 --- a/src/public/app/widgets/title_bar_buttons.js +++ b/src/public/app/widgets/title_bar_buttons.js @@ -6,25 +6,32 @@ const TPL = `
`; export default class TitleBarButtonsWidget extends BasicWidget {