Created
August 5, 2014 18:51
-
-
Save nathansobo/c443d7ff0ae880a0b547 to your computer and use it in GitHub Desktop.
Splice-Based Line Updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| updateTileLines: (lines, tileStartRow, change) -> | |
| tileSize = @getTileSize() | |
| tileEndRow = tileStartRow + tileSize | |
| changeStart = change.start | |
| # Make change end-row exclusive to simplify logic below | |
| changeOldEnd = change.end + 1 | |
| changeNewEnd = change.end + change.screenDelta + 1 | |
| # If the change starts past this tile, stop now | |
| return lines if changeStart >= tileEndRow | |
| if changeOldEnd < tileStartRow or changeNewEnd < tileStartRow | |
| changeTranslation = tileStartRow - Math.min(changeOldEnd, changeNewEnd) | |
| changeOldEnd += changeTranslation | |
| changeNewEnd += changeTranslation | |
| changeStart = Math.max(tileStartRow, changeStart) | |
| changeOldEnd = Math.min(tileEndRow, changeOldEnd) | |
| changeNewEnd = Math.min(tileEndRow, changeNewEnd) | |
| console.log "splice" | |
| if changeNewEnd > changeStart | |
| newLines = @editor.linesForScreenRows(changeStart, changeNewEnd - 1) | |
| lines = lines.splice(changeStart - tileStartRow, changeOldEnd - changeStart, newLines...) | |
| else | |
| lines = lines.splice(changeStart - tileStartRow, changeOldEnd - changeStart) | |
| if lines.length > tileSize | |
| console.log "splice" | |
| lines = lines.splice(tileSize, lines.length - tileSize) | |
| if lines.length < tileSize | |
| console.log "splice" | |
| lines = lines.splice(lines.length, 0, @editor.linesForScreenRows(tileStartRow + lines.length, tileEndRow - 1)...) | |
| lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment