MCPcopy
hub / github.com/autoNumeric/autoNumeric / _onKeyup

Method _onKeyup

src/AutoNumeric.js:6771–6931  ·  view source on GitHub ↗

* Handler for 'keyup' events. * The user just released any key, hence one event is sent. * * @param {KeyboardEvent} e

(e)

Source from the content-addressed store, hash-verified

6769 * @param {KeyboardEvent} e
6770 */
6771 _onKeyup(e) {
6772 if (this.compositioning) {
6773 return;
6774 }
6775 this.isEditing = false;
6776 this.keydownEventCounter = 0; // Reset the keydown events counter
6777
6778 if (this.formulaMode) {
6779 return;
6780 }
6781
6782 if (this.settings.isCancellable && this.eventKey === AutoNumericEnum.keyName.Esc) {
6783 // If the user wants to cancel its modifications, we drop the 'keyup' event for the Esc key
6784 e.preventDefault();
6785
6786 return;
6787 }
6788
6789 // Manage the undo/redo events
6790 this._updateEventKeyInfo(e); // Fixes #761, where the Ctrl key is not correctly detected during undo/redo since this.eventKey was not updated from 'Z' to 'Control'
6791 if (this.eventKey === AutoNumericEnum.keyName.Z || this.eventKey === AutoNumericEnum.keyName.z) {
6792 if (e.ctrlKey && e.shiftKey) {
6793 // Redo
6794 e.preventDefault();
6795 this._historyTableRedo();
6796 this._triggerEvent(AutoNumeric.events.native.input, e.target); //TODO instead of adding the event here, generate it from the `_historyTableRedo()` function?
6797 this.onGoingRedo = true;
6798
6799 // if lastVal is updated in the undo branch, it should be updated here too, otherwise Backspace could delete two chars (enter 1234, ctrl-z, ctrl-y, Backspace)
6800 this.lastVal = AutoNumericHelper.getElementValue(e.target);
6801 this.throwInput = true;
6802
6803 return;
6804 } else if (e.ctrlKey && !e.shiftKey) {
6805 if (this.onGoingRedo) {
6806 // Prevent an 'undo' to be launched when releasing the shift key before the ctrl key after a 'redo' shortcut
6807 this.onGoingRedo = false;
6808 } else {
6809 e.preventDefault();
6810 // Undo
6811 this._historyTableUndo();
6812 this._triggerEvent(AutoNumeric.events.native.input, e.target); //TODO instead of adding the event here, generate it from the `_historyTableRedo()` function?
6813
6814 // lastVal should be updated to properly detect change in the Delete/Backspace handler above
6815 this.lastVal = AutoNumericHelper.getElementValue(e.target);
6816 this.throwInput = true;
6817
6818 return;
6819 }
6820 }
6821 } else if ((this.eventKey === AutoNumericEnum.keyName.Y || this.eventKey === AutoNumericEnum.keyName.y) && e.ctrlKey) {
6822 // Redo
6823 e.preventDefault();
6824 this._historyTableRedo();
6825 this._triggerEvent(AutoNumeric.events.native.input, e.target); //TODO instead of adding the event here, generate it from the `_historyTableRedo()` function?
6826 this.onGoingRedo = true;
6827
6828 // if lastVal is updated in the undo branch, it should be updated here too, otherwise Backspace could delete two chars (enter 1234, ctrl-z, ctrl-y, Backspace)

Callers 1

_createEventListenersMethod · 0.95

Calls 15

_updateEventKeyInfoMethod · 0.95
_historyTableRedoMethod · 0.95
_triggerEventMethod · 0.95
_historyTableUndoMethod · 0.95
setMethod · 0.95
_setCaretPositionMethod · 0.95
_setRawValueMethod · 0.95
_formatValueMethod · 0.95

Tested by

no test coverage detected