Fix custom context menu (#225006)

Fixes some issues introduced by
https://github.com/elastic/kibana/pull/217865

## Summary
While testing something in Serverles, we realized that the Console
copy/cut/paste commands weren't working as expected: cut wasn't working
and paste something from outside Kibana behaved weird. Those changes
were introduced in https://github.com/elastic/kibana/pull/217865.

This PR fixes it by:
* Uncomment commented line (probably by mistake), allowing cut.
* Deletes the keybindings lines, allowing them to be native to the
user's OS.
* Removes the trick done for set position when copying. This glitch was
caused by the keybindings let them to default by OS fix it.

Note: You may need to do `yarn kbn clean && yarn kbn bootstrap` before
starting the dev server to see the changes.
This commit is contained in:
Sonia Sanz Vivas 2025-06-24 11:36:38 +02:00 committed by GitHub
parent 26d064520d
commit b2992eacef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,8 +33,6 @@ const DEFAULT_ACTIONS: ContextMenuAction[] = [
label: i18n.translate('sharedUXPackages.codeEditor.contextMenuAction.cutActionLabel', {
defaultMessage: 'Cut',
}),
// eslint-disable-next-line no-bitwise
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyX],
contextMenuGroupId: '9_cutcopypaste',
contextMenuOrder: 1,
run: async (ed) => {
@ -43,7 +41,7 @@ const DEFAULT_ACTIONS: ContextMenuAction[] = [
if (selection && model) {
const selectedText = model.getValueInRange(selection);
copyToClipboard(selectedText);
// ed.executeEdits('Cut selection', [{ range: selection, text: '' }]);
ed.executeEdits('Cut selection', [{ range: selection, text: '' }]);
}
},
},
@ -55,22 +53,14 @@ const DEFAULT_ACTIONS: ContextMenuAction[] = [
label: i18n.translate('sharedUXPackages.codeEditor.contextMenuAction.copyActionLabel', {
defaultMessage: 'Copy',
}),
// eslint-disable-next-line no-bitwise
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyC],
contextMenuGroupId: '9_cutcopypaste',
contextMenuOrder: 2,
run: async (ed) => {
const selection = ed.getSelection();
const model = ed.getModel();
const position = ed.getPosition();
if (selection && model) {
const selectedText = model.getValueInRange(selection);
copyToClipboard(selectedText);
if (position) {
// For some reason (possibly rerendering), calling copyToClipboard
// changes the position of the cursor so we set it to the initial position
ed.setPosition(position);
}
}
},
},
@ -82,8 +72,6 @@ const DEFAULT_ACTIONS: ContextMenuAction[] = [
label: i18n.translate('sharedUXPackages.codeEditor.contextMenuAction.pasteActionLabel', {
defaultMessage: 'Paste',
}),
// eslint-disable-next-line no-bitwise
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyV],
contextMenuGroupId: '9_cutcopypaste',
contextMenuOrder: 3,
run: async (ed) => {