diff --git a/app/ui/client/lib/chatMessages.js b/app/ui/client/lib/chatMessages.js index eb2422eb1f16..b96f9d432256 100644 --- a/app/ui/client/lib/chatMessages.js +++ b/app/ui/client/lib/chatMessages.js @@ -138,18 +138,22 @@ export class ChatMessages { toPrevMessage() { const { element } = this.editing; - if (element) { - let previous; - for (previous = element.previousElementSibling; previous; previous = previous.previousElementSibling) { - if (previous.matches('.own:not(.system)')) { - break; - } + if (!element) { + const messages = Array.from(this.wrapper.querySelectorAll('.own:not(.system)')); + const message = messages.pop(); + return message && this.edit(message, false); + } + + for ( + let previous = element.previousElementSibling; + previous; + previous = previous.previousElementSibling + ) { + if (previous.matches('.own:not(.system)')) { + return this.edit(previous, false); } - - previous ? this.edit(previous, false) : this.clearEditing(); - } else { - this.edit(this.wrapper.querySelector('.own:not(.system):last-child'), false); } + this.clearEditing(); } toNextMessage() {