Skip to content

Commit b6cd99e

Browse files
authored
Merge pull request #233 from phyng/master
fix: context menu and selection position
2 parents b12cea3 + 71c7fe9 commit b6cd99e

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828

2929
<body>
3030
<div id="map"></div>
31-
<div id="map2"></div>
31+
<!-- test transform compatibility -->
32+
<div style="transform: translateX(30px) translateY(20px);">
33+
<div id="map2"></div>
34+
</div>
3235
<script type="module" src="/src/dev.ts"></script>
3336
</body>
3437

35-
</html>
38+
</html>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Be aware that Mind Elixir will not observe the change of `prefers-color-scheme`.
351351

352352
```
353353
pnpm i
354-
npm start
354+
pnpm dev
355355
```
356356

357357
Test generated files with `dev.dist.ts`:

src/plugin/contextMenu.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import i18n from '../i18n'
22
import type { Topic } from '../types/dom'
33
import type { MindElixirInstance } from '../types/index'
44
import { encodeHTML, isTopic } from '../utils/index'
5+
import dragMoveHelper from '../utils/dragMoveHelper'
56
import './contextMenu.less'
67

78
export default function (mind: MindElixirInstance, option: any) {
@@ -91,21 +92,36 @@ export default function (mind: MindElixirInstance, option: any) {
9192
}
9293
if (!mind.currentNodes) mind.selectNode(target)
9394
menuContainer.hidden = false
95+
96+
if (dragMoveHelper.mousedown) {
97+
dragMoveHelper.mousedown = false
98+
}
99+
100+
menuUl.style.top = ''
101+
menuUl.style.bottom = ''
102+
menuUl.style.left = ''
103+
menuUl.style.right = ''
104+
const rect = menuUl.getBoundingClientRect()
94105
const height = menuUl.offsetHeight
95106
const width = menuUl.offsetWidth
96-
if (height + e.clientY > window.innerHeight) {
107+
108+
const relativeY = e.clientY - rect.top
109+
const relativeX = e.clientX - rect.left
110+
111+
if (height + relativeY > window.innerHeight) {
97112
menuUl.style.top = ''
98113
menuUl.style.bottom = '0px'
99114
} else {
100115
menuUl.style.bottom = ''
101-
menuUl.style.top = e.clientY + 15 + 'px'
116+
menuUl.style.top = relativeY + 15 + 'px'
102117
}
103-
if (width + e.clientX > window.innerWidth) {
118+
119+
if (width + relativeX > window.innerWidth) {
104120
menuUl.style.left = ''
105121
menuUl.style.right = '0px'
106122
} else {
107123
menuUl.style.right = ''
108-
menuUl.style.left = e.clientX + 10 + 'px'
124+
menuUl.style.left = relativeX + 10 + 'px'
109125
}
110126
}
111127
}

src/plugin/selection.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function (mei: MindElixirInstance) {
66
const selection = new SelectionArea({
77
selectables: ['.map-container me-tpc'],
88
boundaries: [mei.container],
9-
container: mei.container,
9+
container: 'body',
1010
behaviour: {
1111
// Scroll configuration.
1212
scrolling: {
@@ -28,6 +28,12 @@ export default function (mei: MindElixirInstance) {
2828
if (((event as MouseEvent).target as Topic).tagName === 'ME-TPC') return false
2929
if (((event as MouseEvent).target as HTMLElement).id === 'input-box') return false
3030
if (((event as MouseEvent).target as HTMLElement).className === 'circle') return false
31+
const selectionAreaElement = selection.getSelectionArea()
32+
selectionAreaElement.style.background = '#4f90f22d'
33+
selectionAreaElement.style.border = '1px solid #4f90f2'
34+
if (selectionAreaElement.parentElement) {
35+
selectionAreaElement.parentElement.style.zIndex = '9999'
36+
}
3137
return true
3238
})
3339
.on('start', ({ event }) => {

0 commit comments

Comments
 (0)