From dee24ac27a06a3a108005beddb675965b9c4d752 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 27 May 2019 16:45:26 +0200 Subject: [PATCH] extract constant --- src/utils/EventUtils.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/EventUtils.js b/src/utils/EventUtils.js index 76ef044b2a..ff20a68e3c 100644 --- a/src/utils/EventUtils.js +++ b/src/utils/EventUtils.js @@ -61,6 +61,7 @@ export function canEditOwnEvent(mxEvent) { return canEditContent(mxEvent); } +const MAX_JUMP_DISTANCE = 100; export function findEditableEvent(room, isForward, fromEventId = undefined) { const liveTimeline = room.getLiveTimeline(); const events = liveTimeline.getEvents(); @@ -69,7 +70,7 @@ export function findEditableEvent(room, isForward, fromEventId = undefined) { const beginIdx = isForward ? 0 : maxIdx; let endIdx = isForward ? maxIdx : 0; if (!fromEventId) { - endIdx = Math.min(Math.max(0, beginIdx + (inc * 100)), maxIdx); + endIdx = Math.min(Math.max(0, beginIdx + (inc * MAX_JUMP_DISTANCE)), maxIdx); } let foundFromEventId = !fromEventId; for (let i = beginIdx; i !== (endIdx + inc); i += inc) { @@ -77,9 +78,9 @@ export function findEditableEvent(room, isForward, fromEventId = undefined) { // find start event first if (!foundFromEventId && e.getId() === fromEventId) { foundFromEventId = true; - // don't look further than 100 events from `fromEventId` + // don't look further than MAX_JUMP_DISTANCE events from `fromEventId` // to not iterate potentially 1000nds of events on key up/down - endIdx = Math.min(Math.max(0, i + (inc * 100)), maxIdx); + endIdx = Math.min(Math.max(0, i + (inc * MAX_JUMP_DISTANCE)), maxIdx); } else if (foundFromEventId && !shouldHideEvent(e) && canEditOwnEvent(e)) { // otherwise look for editable event return e;