Posted 18 April 2019, 10:36 am EST
Currently while editing a cell the user can press CTRL + Enter to go to a newline, I would like the same behavior to occur when the user presses COMMAND + Enter on a Mac.
How would I make this happen?
Forums Home / Spread / SpreadJS
Posted by: adisa.craig on 18 April 2019, 10:36 am EST
Posted 18 April 2019, 10:36 am EST
Currently while editing a cell the user can press CTRL + Enter to go to a newline, I would like the same behavior to occur when the user presses COMMAND + Enter on a Mac.
How would I make this happen?
Posted 22 April 2019, 4:14 am EST
Hi,
To add additional key combinations that behave the same as ctrl+enter, we could handle keydown event and trigger the ctrl+enter event manually when required.
Please refer to the following code snippet and let us know if you face any issues:
spread.bind(GC.Spread.Sheets.Events.EditorStatusChanged, function(e, info){
if(info.newStatus == GC.Spread.Sheets.EditorStatus.edit || GC.Spread.Sheets.EditorStatus.enter){
var editor = spread.getHost().querySelector('[gcuielement="gcEditingInput"]');
if(editor){
editor.addEventListener('keypress', function(e){
if(e.keyCode == 13 && e.metaKey){
try{
var kb = new KeyboardEvent('keydown', {
ctrlKey: true,
keyCode: 13
});
editor.dispatchEvent(kb);
e.preventDefault();
}catch(err){
// keyboard event is not supported
}
}
}, true);
}
}
});
Regards
Posted 23 April 2019, 2:23 pm EST
Thanks the above worked, just had to change the event listener to ‘keydown’ instead of ‘keypress’