mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-24 03:23:10 +00:00
Merge pull request #2626 from overleaf/bg-fix-editor-regexps
fix stateful regexp usage in editor inputs GitOrigin-RevId: 4950066251cb6235e218ff4f600fab2652d15e76
This commit is contained in:
parent
c120309dd0
commit
5f712645ed
1 changed files with 16 additions and 20 deletions
|
@ -201,28 +201,24 @@ define([
|
|||
// you can modify the input or reject the event with e.preventDefault()
|
||||
editor.commands.on('exec', function(e) {
|
||||
// replace bad characters in paste content
|
||||
if (
|
||||
e.command &&
|
||||
e.command.name === 'paste' &&
|
||||
e.args &&
|
||||
BAD_CHARS_REGEXP.test(e.args.text)
|
||||
) {
|
||||
e.args.text = e.args.text.replace(
|
||||
BAD_CHARS_REGEXP,
|
||||
BAD_CHARS_REPLACEMENT_CHAR
|
||||
)
|
||||
if (e.command && e.command.name === 'paste') {
|
||||
BAD_CHARS_REGEXP.lastIndex = 0 // reset stateful regexp for this usage
|
||||
if (e.args && BAD_CHARS_REGEXP.test(e.args.text)) {
|
||||
e.args.text = e.args.text.replace(
|
||||
BAD_CHARS_REGEXP,
|
||||
BAD_CHARS_REPLACEMENT_CHAR
|
||||
)
|
||||
}
|
||||
}
|
||||
// replace bad characters in keyboard input
|
||||
if (
|
||||
e.command &&
|
||||
e.command.name === 'insertstring' &&
|
||||
e.args &&
|
||||
BAD_CHARS_REGEXP.test(e.args)
|
||||
) {
|
||||
e.args = e.args.replace(
|
||||
BAD_CHARS_REGEXP,
|
||||
BAD_CHARS_REPLACEMENT_CHAR
|
||||
)
|
||||
if (e.command && e.command.name === 'insertstring') {
|
||||
BAD_CHARS_REGEXP.lastIndex = 0 // reset stateful regexp for this usage
|
||||
if (e.args && BAD_CHARS_REGEXP.test(e.args)) {
|
||||
e.args = e.args.replace(
|
||||
BAD_CHARS_REGEXP,
|
||||
BAD_CHARS_REPLACEMENT_CHAR
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue