fix: Remove 1ms delay before inserting list prefix, fix race condition in tests (#8207)

Fixed the race condition that made the existing E2E tests fail. There was a 1ms delay between inserting a newline and the line prefix to facilitate creation of two "undo" entries (so "ctrl+z" basically undoes the list continuation, but not the newline). Thus scripted text changes may have happened out of order.

This only ever reliably worked in Firefox and seems to still work there even without a timeout.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8207
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Danko Aleksejevs <danko@very.lv>
Co-committed-by: Danko Aleksejevs <danko@very.lv>
This commit is contained in:
Danko Aleksejevs 2025-06-18 12:58:31 +02:00 committed by Gusted
parent 321561d315
commit ae00a1d61b

View file

@ -587,9 +587,7 @@ class ComboMarkdownEditor {
// Split the newline and prefix addition in two, so that it's two separate undo entries in Firefox
// Chrome seems to bundle everything together more aggressively, even with prior text input.
if (document.execCommand('insertText', false, '\n')) {
setTimeout(() => {
document.execCommand('insertText', false, text);
}, 1);
} else {
this.textarea.setRangeText(`\n${text}`);
}