mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Update DisplayBuffer
This commit is contained in:
@@ -45,9 +45,12 @@ class DisplayBuffer
|
||||
|
||||
### Public ###
|
||||
|
||||
# Sets the visibility of the tokenized buffer.
|
||||
#
|
||||
# visible - A {Boolean} indicating of the tokenized buffer is shown
|
||||
setVisible: (visible) -> @tokenizedBuffer.setVisible(visible)
|
||||
|
||||
# Public: Defines the limit at which the buffer begins to soft wrap text.
|
||||
# Defines the limit at which the buffer begins to soft wrap text.
|
||||
#
|
||||
# softWrapColumn - A {Number} defining the soft wrap limit.
|
||||
setSoftWrapColumn: (@softWrapColumn) ->
|
||||
@@ -58,7 +61,7 @@ class DisplayBuffer
|
||||
bufferDelta = 0
|
||||
@triggerChanged({ start, end, screenDelta, bufferDelta })
|
||||
|
||||
# Public: Gets the screen line for the given screen row.
|
||||
# Gets the screen line for the given screen row.
|
||||
#
|
||||
# screenRow - A {Number} indicating the screen row.
|
||||
#
|
||||
@@ -66,7 +69,7 @@ class DisplayBuffer
|
||||
lineForRow: (row) ->
|
||||
@lineMap.lineForScreenRow(row)
|
||||
|
||||
# Public: Gets the screen lines for the given screen row range.
|
||||
# Gets the screen lines for the given screen row range.
|
||||
#
|
||||
# startRow - A {Number} indicating the beginning screen row.
|
||||
# endRow - A {Number} indicating the ending screen row.
|
||||
@@ -75,14 +78,14 @@ class DisplayBuffer
|
||||
linesForRows: (startRow, endRow) ->
|
||||
@lineMap.linesForScreenRows(startRow, endRow)
|
||||
|
||||
# Public: Gets all the screen lines.
|
||||
# Gets all the screen lines.
|
||||
#
|
||||
# Returns an {Array} of {ScreenLines}s.
|
||||
getLines: ->
|
||||
@lineMap.linesForScreenRows(0, @lineMap.lastScreenRow())
|
||||
|
||||
|
||||
# Public: Given starting and ending screen rows, this returns an array of the
|
||||
# Given starting and ending screen rows, this returns an array of the
|
||||
# buffer rows corresponding to every screen row in the range
|
||||
#
|
||||
# startRow - The screen row {Number} to start at
|
||||
@@ -92,7 +95,7 @@ class DisplayBuffer
|
||||
bufferRowsForScreenRows: (startRow, endRow) ->
|
||||
@lineMap.bufferRowsForScreenRows(startRow, endRow)
|
||||
|
||||
# Public: Creates a new fold between two row numbers.
|
||||
# Creates a new fold between two row numbers.
|
||||
#
|
||||
# startRow - The row {Number} to start folding at
|
||||
# endRow - The row {Number} to end the fold
|
||||
@@ -119,7 +122,7 @@ class DisplayBuffer
|
||||
|
||||
fold
|
||||
|
||||
# Public: Given a {Fold}, determines if it is contained within another fold.
|
||||
# Given a {Fold}, determines if it is contained within another fold.
|
||||
#
|
||||
# fold - The {Fold} to check
|
||||
#
|
||||
@@ -129,7 +132,7 @@ class DisplayBuffer
|
||||
for otherFold in folds
|
||||
return otherFold if fold != otherFold and fold.isContainedByFold(otherFold)
|
||||
|
||||
# Public: Given a starting and ending row, tries to find an existing fold.
|
||||
# Given a starting and ending row, tries to find an existing fold.
|
||||
#
|
||||
# startRow - A {Number} representing a fold's starting row
|
||||
# endRow - A {Number} representing a fold's ending row
|
||||
@@ -139,7 +142,7 @@ class DisplayBuffer
|
||||
_.find @activeFolds[startRow] ? [], (fold) ->
|
||||
fold.startRow == startRow and fold.endRow == endRow
|
||||
|
||||
# Public: Removes any folds found that contain the given buffer row.
|
||||
# Removes any folds found that contain the given buffer row.
|
||||
#
|
||||
# bufferRow - The buffer row {Number} to check against
|
||||
destroyFoldsContainingBufferRow: (bufferRow) ->
|
||||
@@ -150,7 +153,7 @@ class DisplayBuffer
|
||||
foldsStartingAtBufferRow: (bufferRow) ->
|
||||
new Array((@activeFolds[bufferRow] ? [])...)
|
||||
|
||||
# Public: Given a buffer row, this returns the largest fold that starts there.
|
||||
# Given a buffer row, this returns the largest fold that starts there.
|
||||
#
|
||||
# Largest is defined as the fold whose difference between its start and end points
|
||||
# are the greatest.
|
||||
@@ -162,7 +165,7 @@ class DisplayBuffer
|
||||
return unless folds = @activeFolds[bufferRow]
|
||||
(folds.sort (a, b) -> b.endRow - a.endRow)[0]
|
||||
|
||||
# Public: Given a screen row, this returns the largest fold that starts there.
|
||||
# Given a screen row, this returns the largest fold that starts there.
|
||||
#
|
||||
# Largest is defined as the fold whose difference between its start and end points
|
||||
# are the greatest.
|
||||
@@ -173,7 +176,7 @@ class DisplayBuffer
|
||||
largestFoldStartingAtScreenRow: (screenRow) ->
|
||||
@largestFoldStartingAtBufferRow(@bufferRowForScreenRow(screenRow))
|
||||
|
||||
# Public: Given a buffer row, this returns the largest fold that includes it.
|
||||
# Given a buffer row, this returns the largest fold that includes it.
|
||||
#
|
||||
# Largest is defined as the fold whose difference between its start and end points
|
||||
# are the greatest.
|
||||
@@ -188,7 +191,7 @@ class DisplayBuffer
|
||||
largestFold = fold if fold.endRow >= bufferRow
|
||||
largestFold
|
||||
|
||||
# Public: Given a buffer range, this converts it into a screen range.
|
||||
# Given a buffer range, this converts it into a screen range.
|
||||
#
|
||||
# bufferRange - A {Range} consisting of buffer positions
|
||||
#
|
||||
@@ -198,7 +201,7 @@ class DisplayBuffer
|
||||
@lineMap.screenRangeForBufferRange(
|
||||
@expandBufferRangeToLineEnds(bufferRange)))
|
||||
|
||||
# Public: Given a buffer row, this converts it into a screen row.
|
||||
# Given a buffer row, this converts it into a screen row.
|
||||
#
|
||||
# bufferRow - A {Number} representing a buffer row
|
||||
#
|
||||
@@ -209,7 +212,7 @@ class DisplayBuffer
|
||||
lastScreenRowForBufferRow: (bufferRow) ->
|
||||
@lineMap.screenPositionForBufferPosition([bufferRow, Infinity]).row
|
||||
|
||||
# Public: Given a screen row, this converts it into a buffer row.
|
||||
# Given a screen row, this converts it into a buffer row.
|
||||
#
|
||||
# screenRow - A {Number} representing a screen row
|
||||
#
|
||||
@@ -217,7 +220,7 @@ class DisplayBuffer
|
||||
bufferRowForScreenRow: (screenRow) ->
|
||||
@lineMap.bufferPositionForScreenPosition([screenRow, 0]).row
|
||||
|
||||
# Public: Given a buffer range, this converts it into a screen position.
|
||||
# Given a buffer range, this converts it into a screen position.
|
||||
#
|
||||
# bufferRange - The {Range} to convert
|
||||
#
|
||||
@@ -225,7 +228,7 @@ class DisplayBuffer
|
||||
screenRangeForBufferRange: (bufferRange) ->
|
||||
@lineMap.screenRangeForBufferRange(bufferRange)
|
||||
|
||||
# Public: Given a screen range, this converts it into a buffer position.
|
||||
# Given a screen range, this converts it into a buffer position.
|
||||
#
|
||||
# screenRange - The {Range} to convert
|
||||
#
|
||||
@@ -233,25 +236,25 @@ class DisplayBuffer
|
||||
bufferRangeForScreenRange: (screenRange) ->
|
||||
@lineMap.bufferRangeForScreenRange(screenRange)
|
||||
|
||||
# Public: Gets the number of lines in the buffer.
|
||||
# Gets the number of lines in the buffer.
|
||||
#
|
||||
# Returns a {Number}.
|
||||
getLineCount: ->
|
||||
@lineMap.getScreenLineCount()
|
||||
|
||||
# Public: Gets the number of the last row in the buffer.
|
||||
# Gets the number of the last row in the buffer.
|
||||
#
|
||||
# Returns a {Number}.
|
||||
getLastRow: ->
|
||||
@getLineCount() - 1
|
||||
|
||||
# Public: Gets the length of the longest screen line.
|
||||
# Gets the length of the longest screen line.
|
||||
#
|
||||
# Returns a {Number}.
|
||||
maxLineLength: ->
|
||||
@lineMap.maxScreenLineLength
|
||||
|
||||
# Public: Given a buffer position, this converts it into a screen position.
|
||||
# Given a buffer position, this converts it into a screen position.
|
||||
#
|
||||
# bufferPosition - An object that represents a buffer position. It can be either
|
||||
# an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point}
|
||||
@@ -263,7 +266,7 @@ class DisplayBuffer
|
||||
screenPositionForBufferPosition: (position, options) ->
|
||||
@lineMap.screenPositionForBufferPosition(position, options)
|
||||
|
||||
# Public: Given a buffer range, this converts it into a screen position.
|
||||
# Given a buffer range, this converts it into a screen position.
|
||||
#
|
||||
# screenPosition - An object that represents a buffer position. It can be either
|
||||
# an {Object} (`{row, column}`), {Array} (`[row, column]`), or {Point}
|
||||
@@ -275,7 +278,7 @@ class DisplayBuffer
|
||||
bufferPositionForScreenPosition: (position, options) ->
|
||||
@lineMap.bufferPositionForScreenPosition(position, options)
|
||||
|
||||
# Public: Retrieves the grammar's token scopes for a buffer position.
|
||||
# Retrieves the grammar's token scopes for a buffer position.
|
||||
#
|
||||
# bufferPosition - A {Point} in the {Buffer}
|
||||
#
|
||||
@@ -283,7 +286,7 @@ class DisplayBuffer
|
||||
scopesForBufferPosition: (bufferPosition) ->
|
||||
@tokenizedBuffer.scopesForPosition(bufferPosition)
|
||||
|
||||
# Public: Retrieves the grammar's token for a buffer position.
|
||||
# Retrieves the grammar's token for a buffer position.
|
||||
#
|
||||
# bufferPosition - A {Point} in the {Buffer}.
|
||||
#
|
||||
@@ -291,13 +294,13 @@ class DisplayBuffer
|
||||
tokenForBufferPosition: (bufferPosition) ->
|
||||
@tokenizedBuffer.tokenForPosition(bufferPosition)
|
||||
|
||||
# Public: Retrieves the current tab length.
|
||||
# Retrieves the current tab length.
|
||||
#
|
||||
# Returns a {Number}.
|
||||
getTabLength: ->
|
||||
@tokenizedBuffer.getTabLength()
|
||||
|
||||
# Public: Specifies the tab length.
|
||||
# Specifies the tab length.
|
||||
#
|
||||
# tabLength - A {Number} that defines the new tab length.
|
||||
setTabLength: (tabLength) ->
|
||||
@@ -312,7 +315,7 @@ class DisplayBuffer
|
||||
reloadGrammar: ->
|
||||
@tokenizedBuffer.reloadGrammar()
|
||||
|
||||
# Public: Given a position, this clips it to a real position.
|
||||
# Given a position, this clips it to a real position.
|
||||
#
|
||||
# For example, if `position`'s row exceeds the row count of the buffer,
|
||||
# or if its column goes beyond a line's length, this "sanitizes" the value
|
||||
@@ -328,6 +331,264 @@ class DisplayBuffer
|
||||
clipScreenPosition: (position, options) ->
|
||||
@lineMap.clipScreenPosition(position, options)
|
||||
|
||||
# Given a line, finds the point where it would wrap.
|
||||
#
|
||||
# line - The {String} to check
|
||||
# softWrapColumn - The {Number} where you want soft wrapping to occur
|
||||
#
|
||||
# Returns a {Number} representing the `line` position where the wrap would take place.
|
||||
# Returns `null` if a wrap wouldn't occur.
|
||||
findWrapColumn: (line, softWrapColumn) ->
|
||||
return unless line.length > softWrapColumn
|
||||
|
||||
if /\s/.test(line[softWrapColumn])
|
||||
# search forward for the start of a word past the boundary
|
||||
for column in [softWrapColumn..line.length]
|
||||
return column if /\S/.test(line[column])
|
||||
return line.length
|
||||
else
|
||||
# search backward for the start of the word on the boundary
|
||||
for column in [softWrapColumn..0]
|
||||
return column + 1 if /\s/.test(line[column])
|
||||
return softWrapColumn
|
||||
|
||||
# Given a range in screen coordinates, this expands it to the start and end of a line
|
||||
#
|
||||
# screenRange - The {Range} to expand
|
||||
#
|
||||
# Returns a new {Range}.
|
||||
expandScreenRangeToLineEnds: (screenRange) ->
|
||||
screenRange = Range.fromObject(screenRange)
|
||||
{ start, end } = screenRange
|
||||
new Range([start.row, 0], [end.row, @lineMap.lineForScreenRow(end.row).text.length])
|
||||
|
||||
# Given a range in buffer coordinates, this expands it to the start and end of a line
|
||||
#
|
||||
# screenRange - The {Range} to expand
|
||||
#
|
||||
# Returns a new {Range}.
|
||||
expandBufferRangeToLineEnds: (bufferRange) ->
|
||||
bufferRange = Range.fromObject(bufferRange)
|
||||
{ start, end } = bufferRange
|
||||
new Range([start.row, 0], [end.row, Infinity])
|
||||
|
||||
# Calculates a {Range} representing the start of the {Buffer} until the end.
|
||||
#
|
||||
# Returns a {Range}.
|
||||
rangeForAllLines: ->
|
||||
new Range([0, 0], @clipScreenPosition([Infinity, Infinity]))
|
||||
|
||||
# Retrieves a {DisplayBufferMarker} based on its id.
|
||||
#
|
||||
# id - A {Number} representing a marker id
|
||||
#
|
||||
# Returns the {DisplayBufferMarker} (if it exists).
|
||||
getMarker: (id) ->
|
||||
@markers[id] ? new DisplayBufferMarker({id, displayBuffer: this})
|
||||
|
||||
# Retrieves the active markers in the buffer.
|
||||
#
|
||||
# Returns an {Array} of existing {DisplayBufferMarker}s.
|
||||
getMarkers: ->
|
||||
_.values(@markers)
|
||||
|
||||
# Constructs a new marker at the given screen range.
|
||||
#
|
||||
# range - The marker {Range} (representing the distance between the head and tail)
|
||||
# options - Options to pass to the {BufferMarker} constructor
|
||||
#
|
||||
# Returns a {Number} representing the new marker's ID.
|
||||
markScreenRange: (args...) ->
|
||||
bufferRange = @bufferRangeForScreenRange(args.shift())
|
||||
@markBufferRange(bufferRange, args...)
|
||||
|
||||
# Constructs a new marker at the given buffer range.
|
||||
#
|
||||
# range - The marker {Range} (representing the distance between the head and tail)
|
||||
# options - Options to pass to the {BufferMarker} constructor
|
||||
#
|
||||
# Returns a {Number} representing the new marker's ID.
|
||||
markBufferRange: (args...) ->
|
||||
@buffer.markRange(args...)
|
||||
|
||||
# Constructs a new marker at the given screen position.
|
||||
#
|
||||
# range - The marker {Range} (representing the distance between the head and tail)
|
||||
# options - Options to pass to the {BufferMarker} constructor
|
||||
#
|
||||
# Returns a {Number} representing the new marker's ID.
|
||||
markScreenPosition: (screenPosition, options) ->
|
||||
@markBufferPosition(@bufferPositionForScreenPosition(screenPosition), options)
|
||||
|
||||
# Constructs a new marker at the given buffer position.
|
||||
#
|
||||
# range - The marker {Range} (representing the distance between the head and tail)
|
||||
# options - Options to pass to the {BufferMarker} constructor
|
||||
#
|
||||
# Returns a {Number} representing the new marker's ID.
|
||||
markBufferPosition: (bufferPosition, options) ->
|
||||
@buffer.markPosition(bufferPosition, options)
|
||||
|
||||
# Removes the marker with the given id.
|
||||
#
|
||||
# id - The {Number} of the ID to remove
|
||||
destroyMarker: (id) ->
|
||||
@buffer.destroyMarker(id)
|
||||
delete @markers[id]
|
||||
|
||||
# Gets the screen range of the display marker.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Range}.
|
||||
getMarkerScreenRange: (id) ->
|
||||
@getMarker(id).getScreenRange()
|
||||
|
||||
# Modifies the screen range of the display marker.
|
||||
#
|
||||
# id - The {Number} of the ID to change
|
||||
# screenRange - The new {Range} to use
|
||||
# options - A hash of options matching those found in {BufferMarker.setRange}
|
||||
setMarkerScreenRange: (id, screenRange, options) ->
|
||||
@getMarker(id).setScreenRange(screenRange, options)
|
||||
|
||||
# Gets the buffer range of the display marker.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Range}.
|
||||
getMarkerBufferRange: (id) ->
|
||||
@getMarker(id).getBufferRange()
|
||||
|
||||
# Modifies the buffer range of the display marker.
|
||||
#
|
||||
# id - The {Number} of the ID to change
|
||||
# screenRange - The new {Range} to use
|
||||
# options - A hash of options matching those found in {BufferMarker.setRange}
|
||||
setMarkerBufferRange: (id, bufferRange, options) ->
|
||||
@getMarker(id).setBufferRange(bufferRange, options)
|
||||
|
||||
# Retrieves the screen position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerScreenPosition: (id) ->
|
||||
@getMarkerHeadScreenPosition(id)
|
||||
|
||||
# Retrieves the buffer position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerBufferPosition: (id) ->
|
||||
@getMarkerHeadBufferPosition(id)
|
||||
|
||||
# Retrieves the screen position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerHeadScreenPosition: (id) ->
|
||||
@getMarker(id).getHeadScreenPosition()
|
||||
|
||||
# Sets the screen position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to change
|
||||
# screenRange - The new {Point} to use
|
||||
# options - A hash of options matching those found in {DisplayBuffer.bufferPositionForScreenPosition}
|
||||
setMarkerHeadScreenPosition: (id, screenPosition, options) ->
|
||||
@getMarker(id).setHeadScreenPosition(screenPosition, options)
|
||||
|
||||
# Retrieves the buffer position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerHeadBufferPosition: (id) ->
|
||||
@getMarker(id).getHeadBufferPosition()
|
||||
|
||||
# Sets the buffer position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
# screenRange - The new {Point} to use
|
||||
# options - A hash of options matching those found in {DisplayBuffer.bufferPositionForScreenPosition}
|
||||
setMarkerHeadBufferPosition: (id, bufferPosition) ->
|
||||
@getMarker(id).setHeadBufferPosition(bufferPosition)
|
||||
|
||||
# Retrieves the screen position of the marker's tail.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerTailScreenPosition: (id) ->
|
||||
@getMarker(id).getTailScreenPosition()
|
||||
|
||||
# Sets the screen position of the marker's tail.
|
||||
#
|
||||
# id - The {Number} of the ID to change
|
||||
# screenRange - The new {Point} to use
|
||||
# options - A hash of options matching those found in {DisplayBuffer.bufferPositionForScreenPosition}
|
||||
setMarkerTailScreenPosition: (id, screenPosition, options) ->
|
||||
@getMarker(id).setTailScreenPosition(screenPosition, options)
|
||||
|
||||
# Retrieves the buffer position of the marker's tail.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerTailBufferPosition: (id) ->
|
||||
@getMarker(id).getTailBufferPosition()
|
||||
|
||||
# Sets the buffer position of the marker's tail.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
# screenRange - The new {Point} to use
|
||||
# options - A hash of options matching those found in {DisplayBuffer.bufferPositionForScreenPosition}
|
||||
setMarkerTailBufferPosition: (id, bufferPosition) ->
|
||||
@getMarker(id).setTailBufferPosition(bufferPosition)
|
||||
|
||||
# Sets the marker's tail to the same position as the marker's head.
|
||||
#
|
||||
# This only works if there isn't already a tail position.
|
||||
#
|
||||
# id - A {Number} representing the marker to change
|
||||
#
|
||||
# Returns a {Point} representing the new tail position.
|
||||
placeMarkerTail: (id) ->
|
||||
@getMarker(id).placeTail()
|
||||
|
||||
# Removes the tail from the marker.
|
||||
#
|
||||
# id - A {Number} representing the marker to change
|
||||
clearMarkerTail: (id) ->
|
||||
@getMarker(id).clearTail()
|
||||
|
||||
# Identifies if the ending position of a marker is greater than the starting position.
|
||||
#
|
||||
# This can happen when, for example, you highlight text "up" in a {Buffer}.
|
||||
#
|
||||
# id - A {Number} representing the marker to check
|
||||
#
|
||||
# Returns a {Boolean}.
|
||||
isMarkerReversed: (id) ->
|
||||
@buffer.isMarkerReversed(id)
|
||||
|
||||
# Identifies if the marker's head position is equal to its tail.
|
||||
#
|
||||
# id - A {Number} representing the marker to check
|
||||
#
|
||||
# Returns a {Boolean}.
|
||||
isMarkerRangeEmpty: (id) ->
|
||||
@buffer.isMarkerRangeEmpty(id)
|
||||
|
||||
# Sets a callback to be fired whenever a marker is changed.
|
||||
#
|
||||
# id - A {Number} representing the marker to watch
|
||||
# callback - A {Function} to execute
|
||||
observeMarker: (id, callback) ->
|
||||
@getMarker(id).observe(callback)
|
||||
|
||||
### Internal ###
|
||||
|
||||
registerFold: (fold) ->
|
||||
@@ -427,268 +688,6 @@ class DisplayBuffer
|
||||
|
||||
lineFragments
|
||||
|
||||
### Public ###
|
||||
|
||||
# Public: Given a line, finds the point where it would wrap.
|
||||
#
|
||||
# line - The {String} to check
|
||||
# softWrapColumn - The {Number} where you want soft wrapping to occur
|
||||
#
|
||||
# Returns a {Number} representing the `line` position where the wrap would take place.
|
||||
# Returns `null` if a wrap wouldn't occur.
|
||||
findWrapColumn: (line, softWrapColumn) ->
|
||||
return unless line.length > softWrapColumn
|
||||
|
||||
if /\s/.test(line[softWrapColumn])
|
||||
# search forward for the start of a word past the boundary
|
||||
for column in [softWrapColumn..line.length]
|
||||
return column if /\S/.test(line[column])
|
||||
return line.length
|
||||
else
|
||||
# search backward for the start of the word on the boundary
|
||||
for column in [softWrapColumn..0]
|
||||
return column + 1 if /\s/.test(line[column])
|
||||
return softWrapColumn
|
||||
|
||||
# Public: Given a range in screen coordinates, this expands it to the start and end of a line
|
||||
#
|
||||
# screenRange - The {Range} to expand
|
||||
#
|
||||
# Returns a new {Range}.
|
||||
expandScreenRangeToLineEnds: (screenRange) ->
|
||||
screenRange = Range.fromObject(screenRange)
|
||||
{ start, end } = screenRange
|
||||
new Range([start.row, 0], [end.row, @lineMap.lineForScreenRow(end.row).text.length])
|
||||
|
||||
# Public: Given a range in buffer coordinates, this expands it to the start and end of a line
|
||||
#
|
||||
# screenRange - The {Range} to expand
|
||||
#
|
||||
# Returns a new {Range}.
|
||||
expandBufferRangeToLineEnds: (bufferRange) ->
|
||||
bufferRange = Range.fromObject(bufferRange)
|
||||
{ start, end } = bufferRange
|
||||
new Range([start.row, 0], [end.row, Infinity])
|
||||
|
||||
# Public: Calculates a {Range} representing the start of the {Buffer} until the end.
|
||||
#
|
||||
# Returns a {Range}.
|
||||
rangeForAllLines: ->
|
||||
new Range([0, 0], @clipScreenPosition([Infinity, Infinity]))
|
||||
|
||||
# Public: Retrieves a {DisplayBufferMarker} based on its id.
|
||||
#
|
||||
# id - A {Number} representing a marker id
|
||||
#
|
||||
# Returns the {DisplayBufferMarker} (if it exists).
|
||||
getMarker: (id) ->
|
||||
@markers[id] ? new DisplayBufferMarker({id, displayBuffer: this})
|
||||
|
||||
# Public: Retrieves the active markers in the buffer.
|
||||
#
|
||||
# Returns an {Array} of existing {DisplayBufferMarker}s.
|
||||
getMarkers: ->
|
||||
_.values(@markers)
|
||||
|
||||
# Public: Constructs a new marker at the given screen range.
|
||||
#
|
||||
# range - The marker {Range} (representing the distance between the head and tail)
|
||||
# options - Options to pass to the {BufferMarker} constructor
|
||||
#
|
||||
# Returns a {Number} representing the new marker's ID.
|
||||
markScreenRange: (args...) ->
|
||||
bufferRange = @bufferRangeForScreenRange(args.shift())
|
||||
@markBufferRange(bufferRange, args...)
|
||||
|
||||
# Public: Constructs a new marker at the given buffer range.
|
||||
#
|
||||
# range - The marker {Range} (representing the distance between the head and tail)
|
||||
# options - Options to pass to the {BufferMarker} constructor
|
||||
#
|
||||
# Returns a {Number} representing the new marker's ID.
|
||||
markBufferRange: (args...) ->
|
||||
@buffer.markRange(args...)
|
||||
|
||||
# Public: Constructs a new marker at the given screen position.
|
||||
#
|
||||
# range - The marker {Range} (representing the distance between the head and tail)
|
||||
# options - Options to pass to the {BufferMarker} constructor
|
||||
#
|
||||
# Returns a {Number} representing the new marker's ID.
|
||||
markScreenPosition: (screenPosition, options) ->
|
||||
@markBufferPosition(@bufferPositionForScreenPosition(screenPosition), options)
|
||||
|
||||
# Public: Constructs a new marker at the given buffer position.
|
||||
#
|
||||
# range - The marker {Range} (representing the distance between the head and tail)
|
||||
# options - Options to pass to the {BufferMarker} constructor
|
||||
#
|
||||
# Returns a {Number} representing the new marker's ID.
|
||||
markBufferPosition: (bufferPosition, options) ->
|
||||
@buffer.markPosition(bufferPosition, options)
|
||||
|
||||
# Public: Removes the marker with the given id.
|
||||
#
|
||||
# id - The {Number} of the ID to remove
|
||||
destroyMarker: (id) ->
|
||||
@buffer.destroyMarker(id)
|
||||
delete @markers[id]
|
||||
|
||||
# Public: Gets the screen range of the display marker.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Range}.
|
||||
getMarkerScreenRange: (id) ->
|
||||
@getMarker(id).getScreenRange()
|
||||
|
||||
# Public: Modifies the screen range of the display marker.
|
||||
#
|
||||
# id - The {Number} of the ID to change
|
||||
# screenRange - The new {Range} to use
|
||||
# options - A hash of options matching those found in {BufferMarker.setRange}
|
||||
setMarkerScreenRange: (id, screenRange, options) ->
|
||||
@getMarker(id).setScreenRange(screenRange, options)
|
||||
|
||||
# Public: Gets the buffer range of the display marker.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Range}.
|
||||
getMarkerBufferRange: (id) ->
|
||||
@getMarker(id).getBufferRange()
|
||||
|
||||
# Public: Modifies the buffer range of the display marker.
|
||||
#
|
||||
# id - The {Number} of the ID to change
|
||||
# screenRange - The new {Range} to use
|
||||
# options - A hash of options matching those found in {BufferMarker.setRange}
|
||||
setMarkerBufferRange: (id, bufferRange, options) ->
|
||||
@getMarker(id).setBufferRange(bufferRange, options)
|
||||
|
||||
# Public: Retrieves the screen position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerScreenPosition: (id) ->
|
||||
@getMarkerHeadScreenPosition(id)
|
||||
|
||||
# Public: Retrieves the buffer position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerBufferPosition: (id) ->
|
||||
@getMarkerHeadBufferPosition(id)
|
||||
|
||||
# Public: Retrieves the screen position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerHeadScreenPosition: (id) ->
|
||||
@getMarker(id).getHeadScreenPosition()
|
||||
|
||||
# Public: Sets the screen position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to change
|
||||
# screenRange - The new {Point} to use
|
||||
# options - A hash of options matching those found in {DisplayBuffer.bufferPositionForScreenPosition}
|
||||
setMarkerHeadScreenPosition: (id, screenPosition, options) ->
|
||||
@getMarker(id).setHeadScreenPosition(screenPosition, options)
|
||||
|
||||
# Public: Retrieves the buffer position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerHeadBufferPosition: (id) ->
|
||||
@getMarker(id).getHeadBufferPosition()
|
||||
|
||||
# Public: Sets the buffer position of the marker's head.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
# screenRange - The new {Point} to use
|
||||
# options - A hash of options matching those found in {DisplayBuffer.bufferPositionForScreenPosition}
|
||||
setMarkerHeadBufferPosition: (id, bufferPosition) ->
|
||||
@getMarker(id).setHeadBufferPosition(bufferPosition)
|
||||
|
||||
# Public: Retrieves the screen position of the marker's tail.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerTailScreenPosition: (id) ->
|
||||
@getMarker(id).getTailScreenPosition()
|
||||
|
||||
# Public: Sets the screen position of the marker's tail.
|
||||
#
|
||||
# id - The {Number} of the ID to change
|
||||
# screenRange - The new {Point} to use
|
||||
# options - A hash of options matching those found in {DisplayBuffer.bufferPositionForScreenPosition}
|
||||
setMarkerTailScreenPosition: (id, screenPosition, options) ->
|
||||
@getMarker(id).setTailScreenPosition(screenPosition, options)
|
||||
|
||||
# Public: Retrieves the buffer position of the marker's tail.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
#
|
||||
# Returns a {Point}.
|
||||
getMarkerTailBufferPosition: (id) ->
|
||||
@getMarker(id).getTailBufferPosition()
|
||||
|
||||
# Public: Sets the buffer position of the marker's tail.
|
||||
#
|
||||
# id - The {Number} of the ID to check
|
||||
# screenRange - The new {Point} to use
|
||||
# options - A hash of options matching those found in {DisplayBuffer.bufferPositionForScreenPosition}
|
||||
setMarkerTailBufferPosition: (id, bufferPosition) ->
|
||||
@getMarker(id).setTailBufferPosition(bufferPosition)
|
||||
|
||||
# Public: Sets the marker's tail to the same position as the marker's head.
|
||||
#
|
||||
# This only works if there isn't already a tail position.
|
||||
#
|
||||
# id - A {Number} representing the marker to change
|
||||
#
|
||||
# Returns a {Point} representing the new tail position.
|
||||
placeMarkerTail: (id) ->
|
||||
@getMarker(id).placeTail()
|
||||
|
||||
# Public: Removes the tail from the marker.
|
||||
#
|
||||
# id - A {Number} representing the marker to change
|
||||
clearMarkerTail: (id) ->
|
||||
@getMarker(id).clearTail()
|
||||
|
||||
# Public: Identifies if the ending position of a marker is greater than the starting position.
|
||||
#
|
||||
# This can happen when, for example, you highlight text "up" in a {Buffer}.
|
||||
#
|
||||
# id - A {Number} representing the marker to check
|
||||
#
|
||||
# Returns a {Boolean}.
|
||||
isMarkerReversed: (id) ->
|
||||
@buffer.isMarkerReversed(id)
|
||||
|
||||
# Public: Identifies if the marker's head position is equal to its tail.
|
||||
#
|
||||
# id - A {Number} representing the marker to check
|
||||
#
|
||||
# Returns a {Boolean}.
|
||||
isMarkerRangeEmpty: (id) ->
|
||||
@buffer.isMarkerRangeEmpty(id)
|
||||
|
||||
# Public: Sets a callback to be fired whenever a marker is changed.
|
||||
#
|
||||
# id - A {Number} representing the marker to watch
|
||||
# callback - A {Function} to execute
|
||||
observeMarker: (id, callback) ->
|
||||
@getMarker(id).observe(callback)
|
||||
|
||||
### Internal ###
|
||||
|
||||
pauseMarkerObservers: ->
|
||||
marker.pauseEvents() for marker in @getMarkers()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user