Skip to content

514 - Move context-menu init code #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
})
}