Skip to content

Commit 2df8065

Browse files
author
Guillaume Chau
authored
Move context-menu init code (#553)
1 parent 67520ee commit 2df8065

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/backend/hook.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { findRelatedComponent } from './utils'
2-
31
// this script is injected into every page.
42

53
/**
@@ -85,21 +83,4 @@ export function installHook (window) {
8583
return hook
8684
}
8785
})
88-
89-
// Start recording context menu when Vue is detected
90-
// event if Vue devtools are not loaded yet
91-
document.addEventListener('contextmenu', event => {
92-
const el = event.target
93-
if (el) {
94-
// Search for parent that "is" a component instance
95-
const instance = findRelatedComponent(el)
96-
if (instance) {
97-
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = true
98-
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = instance
99-
return
100-
}
101-
}
102-
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = null
103-
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = null
104-
})
10586
}

src/backend/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { highlight, unHighlight, getInstanceRect } from './highlighter'
55
import { initVuexBackend } from './vuex'
66
import { initEventsBackend } from './events'
7+
import { findRelatedComponent } from './utils'
78
import { stringify, classify, camelize, set, parse, getComponentName } from '../util'
89
import ComponentSelector from './component-selector'
910
import config from './config'
@@ -32,6 +33,8 @@ export function initBackend (_bridge) {
3233
}
3334

3435
config(bridge)
36+
37+
initRightClick()
3538
}
3639

3740
function connect () {
@@ -725,3 +728,22 @@ function setStateValue ({ id, path, value, newKey, remove }) {
725728
}
726729
}
727730
}
731+
732+
function initRightClick () {
733+
// Start recording context menu when Vue is detected
734+
// event if Vue devtools are not loaded yet
735+
document.addEventListener('contextmenu', event => {
736+
const el = event.target
737+
if (el) {
738+
// Search for parent that "is" a component instance
739+
const instance = findRelatedComponent(el)
740+
if (instance) {
741+
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = true
742+
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = instance
743+
return
744+
}
745+
}
746+
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = null
747+
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = null
748+
})
749+
}

0 commit comments

Comments
 (0)