Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Fix for https://github.com/brave/browser-laptop/issues/1407 #1670

Merged
merged 2 commits into from
May 11, 2016
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
2 changes: 2 additions & 0 deletions app/extensions/brave/locales/en-US/menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ redo=Redo
cut=Cut
copy=Copy
paste=Paste
pasteAndGo=Paste and Go
pasteAndSearch=Paste and Search
pasteWithoutFormatting=Paste without formatting
delete=Delete
selectAll=Select All
Expand Down
2 changes: 2 additions & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ var rendererIdentifiers = function () {
'cut',
'copy',
'paste',
'pasteAndGo',
'pasteAndSearch',
'pasteWithoutFormatting',
'delete',
'selectAll',
Expand Down
2 changes: 1 addition & 1 deletion js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class UrlBar extends ImmutableComponent {
}

onContextMenu (e) {
contextMenus.onUrlBarContextMenu(e)
contextMenus.onUrlBarContextMenu(this.searchDetail, this.props.activeFrameProps, e)
}

render () {
Expand Down
61 changes: 44 additions & 17 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const ipc = global.require('electron').ipcRenderer
const locale = require('../js/l10n')
const getSetting = require('./settings').getSetting
const settings = require('./constants/settings')
const {isUrl} = require('./lib/appUrlUtil')

/**
* Obtains an add bookmark menu item
Expand Down Expand Up @@ -70,11 +71,36 @@ function tabPageTemplateInit (framePropsList) {
}]
}

function inputTemplateInit (e) {
function urlBarTemplateInit (searchDetail, activeFrame, e) {
const hasSelection = e.target.selectionStart !== undefined &&
e.target.selectionEnd !== undefined &&
e.target.selectionStart !== e.target.selectionEnd
return getEditableItems(hasSelection)
const items = getEditableItems(hasSelection)
const clipboardText = clipboard.readText()
const hasClipboard = clipboardText && clipboardText.length > 0
const isLocationUrl = hasClipboard && isUrl(clipboardText)

if (isLocationUrl) {
items.push({
label: locale.translation('pasteAndGo'),
enabled: hasClipboard,
click: (item, focusedWindow) => {
windowActions.loadUrl(activeFrame, clipboardText)
}
})
} else {
let searchUrl = searchDetail.get('searchURL').replace('{searchTerms}', encodeURIComponent(clipboardText))

items.push({
label: locale.translation('pasteAndSearch'),
enabled: hasClipboard,
click: (item, focusedWindow) => {
windowActions.loadUrl(activeFrame, searchUrl)
}
})
}

return items
}

function tabsToolbarTemplateInit (activeFrame, closestDestinationDetail, isParent) {
Expand Down Expand Up @@ -428,25 +454,26 @@ function getMisspelledSuggestions (selection, isMisspelled, suggestions) {

function getEditableItems (selection) {
const hasSelection = selection.length > 0
const hasClipboard = clipboard.readText().length > 0
const items = []
if (hasSelection) {
items.push({
label: locale.translation('cut'),
enabled: hasSelection,
accelerator: 'CmdOrCtrl+X',
role: 'cut'
}, {
label: locale.translation('copy'),
enabled: hasSelection,
accelerator: 'CmdOrCtrl+C',
role: 'copy'
})
}

items.push({
label: locale.translation('cut'),
enabled: hasSelection,
accelerator: 'CmdOrCtrl+X',
role: 'cut'
}, {
label: locale.translation('copy'),
enabled: hasSelection,
accelerator: 'CmdOrCtrl+C',
role: 'copy'
}, {
label: locale.translation('paste'),
accelerator: 'CmdOrCtrl+V',
enabled: hasClipboard,
role: 'paste'
})

return items
}

Expand Down Expand Up @@ -819,9 +846,9 @@ function onTabPageContextMenu (framePropsList, e) {
tabPageMenu.popup(remote.getCurrentWindow())
}

function onUrlBarContextMenu (e) {
function onUrlBarContextMenu (searchDetail, activeFrame, e) {
e.stopPropagation()
const inputMenu = Menu.buildFromTemplate(inputTemplateInit(e))
const inputMenu = Menu.buildFromTemplate(urlBarTemplateInit(searchDetail, activeFrame, e))
inputMenu.popup(remote.getCurrentWindow())
}

Expand Down