FEATURE: do not insert smart list if SHIFT+Enter is pressed (#29452)

A common pattern in the industry for bypassing smart lists is detection of
the shift key.

This information is not available in the "beforeinput" event but it always
fires afer keydown, so we track if shift is pressed on keydown.
This commit is contained in:
Sam 2024-10-29 10:18:52 +11:00 committed by GitHub
parent 0839bce7b6
commit 4d7f70b923
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -379,6 +379,10 @@ export default class DEditor extends Component {
"beforeinput", "beforeinput",
this.onBeforeInputSmartList this.onBeforeInputSmartList
); );
this._textarea.addEventListener(
"keydown",
this.onBeforeInputSmartListShiftDetect
);
this._textarea.addEventListener("input", this.onInputSmartList); this._textarea.addEventListener("input", this.onInputSmartList);
} }
@ -415,11 +419,18 @@ export default class DEditor extends Component {
} }
} }
@bind
onBeforeInputSmartListShiftDetect(event) {
this._shiftPressed = event.shiftKey;
}
@bind @bind
onBeforeInputSmartList(event) { onBeforeInputSmartList(event) {
// This inputType is much more consistently fired in `beforeinput` // This inputType is much more consistently fired in `beforeinput`
// rather than `input`. // rather than `input`.
this.handleSmartListAutocomplete = event.inputType === "insertLineBreak"; if (!this._shiftPressed) {
this.handleSmartListAutocomplete = event.inputType === "insertLineBreak";
}
} }
@bind @bind
@ -490,6 +501,10 @@ export default class DEditor extends Component {
"beforeinput", "beforeinput",
this.onBeforeInputSmartList this.onBeforeInputSmartList
); );
this._textarea.removeEventListener(
"keydown",
this.onBeforeInputSmartListShiftDetect
);
this._textarea.removeEventListener("input", this.onInputSmartList); this._textarea.removeEventListener("input", this.onInputSmartList);
} }
} }