Skip to content

Commit cc97b7b

Browse files
committed
fix: support dynamically toggling drag and selection features
1 parent a0b71f2 commit cc97b7b

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/methods.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ const methods = {
8686
if (import.meta.env.MODE !== 'lite') {
8787
this.keypress && keypressInit(this, this.keypress)
8888

89-
if (this.editable) {
90-
selection(this)
91-
this.disposable.push(nodeDraggable(this))
92-
}
89+
selection(this)
90+
this.disposable.push(nodeDraggable(this))
9391
if (this.contextMenu) {
9492
this.disposable.push(contextMenu(this, this.contextMenu))
9593
}

src/mouse.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export default function (mind: MindElixirInstance) {
2020
let lastDistance: number | null = null
2121
const activePointers = new Map<number, { x: number; y: number }>()
2222

23-
// Node drag state - only initialize if draggable is enabled
24-
const nodeDragState = mind.editable ? createNodeDragState(mind) : null
23+
// Node drag state - always initialize
24+
const nodeDragState = createNodeDragState(mind)
2525

2626
// Long press state for touch devices
2727
let longPressTimer: number | null = null
@@ -190,7 +190,7 @@ export default function (mind: MindElixirInstance) {
190190
const mouseMoveButton = mind.mouseSelectionButton === 0 ? 2 : 0
191191

192192
// Handle node dragging with left button or touch (only for topics)
193-
if (nodeDragState && (e.button === 0 || e.pointerType === 'touch')) {
193+
if (mind.editable && nodeDragState && (e.button === 0 || e.pointerType === 'touch')) {
194194
// For touch, only start drag with single finger
195195
if (e.pointerType === 'touch' && activePointers.size > 1) {
196196
// Cancel any ongoing drag if second finger touches

src/plugin/selection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default function (mei: MindElixirInstance) {
2525
},
2626
})
2727
.on('beforestart', ({ event }) => {
28+
if (!mei.editable) return false
2829
if (mei.spacePressed) return false
2930
const target = event!.target as HTMLElement
3031
if (target.id === 'input-box') return false

0 commit comments

Comments
 (0)