Skip to content

Commit

Permalink
Move context-menu init code (vuejs#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau authored Jan 24, 2018
1 parent 67520ee commit 2df8065
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
19 changes: 0 additions & 19 deletions src/backend/hook.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { findRelatedComponent } from './utils'

// this script is injected into every page.

/**
Expand Down Expand Up @@ -85,21 +83,4 @@ export function installHook (window) {
return hook
}
})

// Start recording context menu when Vue is detected
// event if Vue devtools are not loaded yet
document.addEventListener('contextmenu', event => {
const el = event.target
if (el) {
// Search for parent that "is" a component instance
const instance = findRelatedComponent(el)
if (instance) {
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = true
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = instance
return
}
}
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = null
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = null
})
}
22 changes: 22 additions & 0 deletions src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { highlight, unHighlight, getInstanceRect } from './highlighter'
import { initVuexBackend } from './vuex'
import { initEventsBackend } from './events'
import { findRelatedComponent } from './utils'
import { stringify, classify, camelize, set, parse, getComponentName } from '../util'
import ComponentSelector from './component-selector'
import config from './config'
Expand Down Expand Up @@ -32,6 +33,8 @@ export function initBackend (_bridge) {
}

config(bridge)

initRightClick()
}

function connect () {
Expand Down Expand Up @@ -725,3 +728,22 @@ function setStateValue ({ id, path, value, newKey, remove }) {
}
}
}

function initRightClick () {
// Start recording context menu when Vue is detected
// event if Vue devtools are not loaded yet
document.addEventListener('contextmenu', event => {
const el = event.target
if (el) {
// Search for parent that "is" a component instance
const instance = findRelatedComponent(el)
if (instance) {
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = true
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = instance
return
}
}
window.__VUE_DEVTOOLS_CONTEXT_MENU_HAS_TARGET__ = null
window.__VUE_DEVTOOLS_CONTEXT_MENU_TARGET__ = null
})
}

0 comments on commit 2df8065

Please sign in to comment.