From f4e9b622614dea9c1728b59e27e573fbdc758f29 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Fri, 1 Feb 2019 13:18:34 -0500 Subject: [PATCH] Insert "position: after" decorations in increasing order --- src/text-editor-component.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 67219e135..9da3db137 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -3866,15 +3866,24 @@ class LinesTileComponent { if (blockDecorations) { blockDecorations.forEach((newDecorations, screenLineId) => { - var oldDecorations = oldProps.blockDecorations ? oldProps.blockDecorations.get(screenLineId) : null - for (var i = 0; i < newDecorations.length; i++) { - var newDecoration = newDecorations[i] - if (oldDecorations && oldDecorations.includes(newDecoration)) continue + const oldDecorations = oldProps.blockDecorations ? oldProps.blockDecorations.get(screenLineId) : null + const lineNode = lineComponentsByScreenLineId.get(screenLineId).element + let lastAfter = lineNode + + for (let i = 0; i < newDecorations.length; i++) { + const newDecoration = newDecorations[i] + const element = TextEditor.viewForItem(newDecoration.item) + + if (oldDecorations && oldDecorations.includes(newDecoration)) { + if (newDecoration.position === 'after') { + lastAfter = element + } + continue + } - var element = TextEditor.viewForItem(newDecoration.item) - var lineNode = lineComponentsByScreenLineId.get(screenLineId).element if (newDecoration.position === 'after') { - this.element.insertBefore(element, lineNode.nextSibling) + this.element.insertBefore(element, lastAfter.nextSibling) + lastAfter = element } else { this.element.insertBefore(element, lineNode) }