Remove Decorations object

This commit is contained in:
Ben Ogle
2014-06-16 10:47:38 -07:00
parent 408e62a993
commit 32a0804b9a
2 changed files with 46 additions and 51 deletions

View File

@@ -1,47 +0,0 @@
_ = require 'underscore-plus'
Decoration = require './decoration'
module.exports =
class Decorations
constructor: (@editor, @startScreenRow, @endScreenRow) ->
@decorationsCache = {}
@decorationsByMarkerId = @editor.decorationsForScreenRowRange(@startScreenRow, @endScreenRow)
@decorationsByScreenRow = @indexDecorationsByScreenRow(@decorationsByMarkerId)
decorationsByScreenRowForType: (decorationType) ->
unless @decorationsCache[decorationType]?
filteredDecorations = {}
for screenRow, decorations of @decorationsByScreenRow
for decoration in decorations
if decoration.isType(decorationType)
filteredDecorations[screenRow] ?= []
filteredDecorations[screenRow].push decoration
for screenRow in [@startScreenRow...@endScreenRow]
if @editor.isFoldableAtScreenRow(screenRow)
filteredDecorations[screenRow] ?= []
filteredDecorations[screenRow].push new Decoration(null, {class: 'foldable'})
@decorationsCache[decorationType] = filteredDecorations
@decorationsCache[decorationType]
decorationsByMarkerIdForType: (decorationType) ->
filteredDecorations = {}
for id, decorations of @decorationsByMarkerId
for decoration in decorations
if decoration.isType(decorationType)
filteredDecorations[id] ?= []
filteredDecorations[id].push decoration
filteredDecorations
indexDecorationsByScreenRow: (decorationsByMarkerId) ->
decorationsByScreenRow = {}
for id, decorations of decorationsByMarkerId
for decoration in decorations
continue unless decoration.isValid()
range = decoration.getScreenRange()
for screenRow in [range.start.row..range.end.row]
decorationsByScreenRow[screenRow] ?= []
decorationsByScreenRow[screenRow].push(decoration)
decorationsByScreenRow

View File

@@ -4,7 +4,7 @@ React = require 'react-atom-fork'
scrollbarStyle = require 'scrollbar-style'
{Range, Point} = require 'text-buffer'
Decorations = require './decorations'
Decoration = require './decoration'
GutterComponent = require './gutter-component'
InputComponent = require './input-component'
CursorsComponent = require './cursors-component'
@@ -51,9 +51,13 @@ EditorComponent = React.createClass
[renderedStartRow, renderedEndRow] = renderedRowRange
cursorScreenRanges = @getCursorScreenRanges(renderedRowRange)
selectionScreenRanges = @getSelectionScreenRanges(renderedRowRange)
decorations = new Decorations(editor, renderedStartRow, renderedEndRow)
gutterDecorations = decorations.decorationsByScreenRowForType('gutter')
highlightDecorations = decorations.decorationsByMarkerIdForType('highlight')
decorationsByMarkerId = editor.decorationsForScreenRowRange(renderedStartRow, renderedEndRow)
highlightDecorations = @decorationsByMarkerIdForType(decorationsByMarkerId, 'highlight')
decorationsByScreenRow = @indexDecorationsByScreenRow(decorationsByMarkerId)
gutterDecorations = @decorationsByScreenRowForType(decorationsByScreenRow, 'gutter')
scrollHeight = editor.getScrollHeight()
scrollWidth = editor.getScrollWidth()
scrollTop = editor.getScrollTop()
@@ -236,6 +240,44 @@ EditorComponent = React.createClass
selectionScreenRanges
indexDecorationsByScreenRow: (decorationsByMarkerId) ->
decorationsByScreenRow = {}
for id, decorations of decorationsByMarkerId
for decoration in decorations
continue unless decoration.isValid()
range = decoration.getScreenRange()
for screenRow in [range.start.row..range.end.row]
decorationsByScreenRow[screenRow] ?= []
decorationsByScreenRow[screenRow].push(decoration)
decorationsByScreenRow
decorationsByMarkerIdForType: (decorationsByMarkerId, decorationType) ->
filteredDecorations = {}
for id, decorations of decorationsByMarkerId
for decoration in decorations
if decoration.isType(decorationType)
filteredDecorations[id] ?= []
filteredDecorations[id].push decoration
filteredDecorations
decorationsByScreenRowForType: (decorationsByScreenRow, decorationType) ->
{editor} = @props
filteredDecorations = {}
for screenRow, decorations of decorationsByScreenRow
for decoration in decorations
if decoration.isType(decorationType)
filteredDecorations[screenRow] ?= []
filteredDecorations[screenRow].push decoration
[startScreenRow, endScreenRow] = @getRenderedRowRange()
for screenRow in [startScreenRow...endScreenRow]
if editor.isFoldableAtScreenRow(screenRow)
filteredDecorations[screenRow] ?= []
filteredDecorations[screenRow].push new Decoration(null, class: 'foldable')
filteredDecorations
getGutterDecorations: (renderedRowRange) ->
[renderedStartRow, renderedEndRow] = renderedRowRange