Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: menu bubble size at the end of the line
Compute menu bubble position without translateX.
The previous approach made the bubble shrink
towards the end of the line.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Mar 29, 2022
commit 9fac289a73cf274b09dae79abf642f76bdd7d801
22 changes: 6 additions & 16 deletions src/components/MenuBubble.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
import { optimalPath } from './../helpers/files'
import { loadState } from '@nextcloud/initial-state'

// This is a rough estimate used for positioning the bubble.
// The actual width depends on the language and the state of the bubble.
const MAX_BUBBLE_WIDTH = 325

export default {
name: 'MenuBubble',
components: {
Expand Down Expand Up @@ -102,21 +106,7 @@ export default {
isUsingDirectEditing: loadState('text', 'directEditingToken', null) !== null,
}
},
computed: {

// Minimum left value for the bubble so that it stays inside the editor.
// the width of the menububble changes depending on its state
// during the bubblePosition calculation it has not been rendered yet.
// so we have to hard code the minimum.
minLeft() {
if (this.linkMenuIsActive || !this.editor.isActive.link()) {
return 150
} else {
return 225
}
},

},
methods: {
showLinkMenu(attrs) {
this.linkUrl = attrs.href
Expand Down Expand Up @@ -166,7 +156,8 @@ export default {
this.hideLinkMenu()
},
bubblePosition(menu) {
const left = Math.max(this.minLeft, menu.left)
const maxLeft = document.getElementById('editor').offsetWidth - MAX_BUBBLE_WIDTH
const left = Math.min(maxLeft, menu.left - (MAX_BUBBLE_WIDTH / 2))
const offset = this.contentWrapper?.scrollTop || 0
return {
top: `${menu.top + offset + 5}px`,
Expand All @@ -192,7 +183,6 @@ export default {
margin-left: 10px;
visibility: hidden;
opacity: 0;
transform: translateX(-50%);
transition: opacity 0.2s, visibility 0.2s;
height: 44px;

Expand Down