mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Never use more than 3 divs to render a selection
This should hopefully improve performance for large selections.
This commit is contained in:
@@ -56,8 +56,8 @@ describe "Selection", ->
|
||||
expect(region2.width()).toBe(25 * charWidth)
|
||||
|
||||
describe "when the selection spans more than 2 lines", ->
|
||||
it "covers the selection's range with a region for each line", ->
|
||||
selection.setRange(new Range({row: 2, column: 7}, {row: 4, column: 25}))
|
||||
it "covers the selection's range with 3 regions", ->
|
||||
selection.setRange(new Range({row: 2, column: 7}, {row: 6, column: 25}))
|
||||
|
||||
expect(selection.regions.length).toBe 3
|
||||
|
||||
@@ -70,11 +70,11 @@ describe "Selection", ->
|
||||
region2 = selection.regions[1]
|
||||
expect(region2.position().top).toBe(3 * lineHeight)
|
||||
expect(region2.position().left).toBe(0)
|
||||
expect(region2.height()).toBe lineHeight
|
||||
expect(region2.height()).toBe(3 * lineHeight)
|
||||
expect(region2.width()).toBe(editor.width())
|
||||
|
||||
region3 = selection.regions[2]
|
||||
expect(region3.position().top).toBe(4 * lineHeight)
|
||||
expect(region3.position().top).toBe(6 * lineHeight)
|
||||
expect(region3.position().left).toBe(0)
|
||||
expect(region3.height()).toBe lineHeight
|
||||
expect(region3.width()).toBe(25 * charWidth)
|
||||
|
||||
@@ -54,7 +54,7 @@ class Editor extends Template
|
||||
@on 'newline', => @insertNewline()
|
||||
@on 'backspace', => @backspace()
|
||||
@on 'delete', => @delete()
|
||||
@on 'copy', => @copyText()
|
||||
@on 'copy', => @copySelection()
|
||||
|
||||
|
||||
buildCursorAndSelection: ->
|
||||
@@ -192,5 +192,5 @@ class Editor extends Template
|
||||
insertNewline: -> @selection.insertNewline()
|
||||
backspace: -> @selection.backspace()
|
||||
delete: -> @selection.delete()
|
||||
copySelection: -> @selection().copy()
|
||||
copySelection: -> @selection.copy()
|
||||
|
||||
|
||||
@@ -34,26 +34,22 @@ class Selection extends Template
|
||||
|
||||
range = @getRange()
|
||||
return if range.isEmpty()
|
||||
for row in [range.start.row..range.end.row]
|
||||
start =
|
||||
if row == range.start.row
|
||||
range.start
|
||||
else
|
||||
{ row: row, column: 0 }
|
||||
|
||||
end =
|
||||
if row == range.end.row
|
||||
range.end
|
||||
else
|
||||
null
|
||||
rowSpan = range.end.row - range.start.row
|
||||
|
||||
@appendRegion(start, end)
|
||||
if rowSpan == 0
|
||||
@appendRegion(1, range.start, range.end)
|
||||
else
|
||||
@appendRegion(1, range.start, null)
|
||||
if rowSpan > 1
|
||||
@appendRegion(rowSpan - 1, { row: range.start.row + 1, column: 0}, null)
|
||||
@appendRegion(1, { row: range.end.row, column: 0 }, range.end)
|
||||
|
||||
appendRegion: (start, end) ->
|
||||
appendRegion: (rows, start, end) ->
|
||||
{ lineHeight, charWidth } = @editor
|
||||
top = start.row * lineHeight
|
||||
left = start.column * charWidth
|
||||
height = lineHeight
|
||||
height = lineHeight * rows
|
||||
width = if end
|
||||
end.column * charWidth - left
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user