Fix context-menu #1671
1 changed files with 7 additions and 7 deletions
|
@ -21,11 +21,11 @@ function injectDevelopmentTemplate(event, templates) {
|
||||||
return templates;
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openContextMenu(event, templates = []) {
|
export function openContextMenu(event, templates = [], canEdit = false) {
|
||||||
|
const { type, value } = event.target;
|
||||||
const isSomethingSelected = window.getSelection().toString().length > 0;
|
const isSomethingSelected = window.getSelection().toString().length > 0;
|
||||||
const { type } = event.target;
|
|
||||||
const isInput = event.target.matches('input') && (type === 'text' || type === 'number');
|
const isInput = event.target.matches('input') && (type === 'text' || type === 'number');
|
||||||
const { value } = event.target;
|
const isTextField = canEdit || isInput || event.target.matches('textarea');
|
||||||
|
|
||||||
templates.push({
|
templates.push({
|
||||||
label: 'Copy',
|
label: 'Copy',
|
||||||
|
@ -36,12 +36,12 @@ export function openContextMenu(event, templates = []) {
|
||||||
|
|
||||||
// If context menu is opened on Input and there is text on the input and something is selected.
|
// If context menu is opened on Input and there is text on the input and something is selected.
|
||||||
const { selectionStart, selectionEnd } = event.target;
|
const { selectionStart, selectionEnd } = event.target;
|
||||||
if (!!value && isInput && selectionStart !== selectionEnd) {
|
if (!!value && isTextField && selectionStart !== selectionEnd) {
|
||||||
templates.push({ label: 'Cut', accelerator: 'CmdOrCtrl+X', role: 'cut' });
|
templates.push({ label: 'Cut', accelerator: 'CmdOrCtrl+X', role: 'cut' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// If context menu is opened on Input and text is present on clipboard
|
// If context menu is opened on Input and text is present on clipboard
|
||||||
if (clipboard.readText().length > 0 && isInput) {
|
if (clipboard.readText().length > 0 && isTextField) {
|
||||||
templates.push({
|
templates.push({
|
||||||
label: 'Paste',
|
label: 'Paste',
|
||||||
accelerator: 'CmdOrCtrl+V',
|
accelerator: 'CmdOrCtrl+V',
|
||||||
|
@ -50,7 +50,7 @@ export function openContextMenu(event, templates = []) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If context menu is opened on Input
|
// If context menu is opened on Input
|
||||||
if (isInput && value) {
|
if (isTextField && value) {
|
||||||
templates.push({
|
templates.push({
|
||||||
label: 'Select All',
|
label: 'Select All',
|
||||||
accelerator: 'CmdOrCtrl+A',
|
accelerator: 'CmdOrCtrl+A',
|
||||||
|
@ -70,5 +70,5 @@ export function openCopyLinkMenu(text, event) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
openContextMenu(event, templates, false);
|
openContextMenu(event, templates);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue