diff --git a/frontend/__tests__/test/test-words.spec.ts b/frontend/__tests__/test/test-words.spec.ts index 085edf395ce3..642c45a2506e 100644 --- a/frontend/__tests__/test/test-words.spec.ts +++ b/frontend/__tests__/test/test-words.spec.ts @@ -60,5 +60,15 @@ describe("test-words", () => { expect(() => words.removeCommitCharacterFromLastWord()).not.toThrow(); expect(words.get()).toEqual([]); }); + + it("does not empty the last word when it's only a newline", () => { + words.push("word\n", 0); + words.push("\n", 0); + words.removeCommitCharacterFromLastWord(); + expect(words.get().map((w) => w.textWithCommit)).toEqual([ + "word\n", + "\n", + ]); + }); }); }); diff --git a/frontend/src/ts/test/test-words.ts b/frontend/src/ts/test/test-words.ts index 2469c63a7d07..a05135a1abfe 100644 --- a/frontend/src/ts/test/test-words.ts +++ b/frontend/src/ts/test/test-words.ts @@ -79,7 +79,7 @@ class Words { removeCommitCharacterFromLastWord(): void { if (this.length === 0) return; const lastWord = this.list[this.length - 1]; - if (lastWord === undefined) return; + if (lastWord === undefined || lastWord.text === "") return; if (lastWord.commit === " " || lastWord.commit === "\n") { lastWord.commit = ""; lastWord.textWithCommit = lastWord.text;