Merge branch 'hide-selection-cursor'

This commit is contained in:
Nathan Sobo
2012-10-29 16:54:34 -06:00
9 changed files with 96 additions and 35 deletions

View File

@@ -10,7 +10,7 @@ class CursorView extends View
@pre class: 'cursor idle', => @raw ' '
editor: null
hidden: false
visible: true
initialize: (@cursor, @editor) ->
@cursor.on 'change-screen-position.cursor-view', (screenPosition, { bufferChange }) =>
@@ -18,6 +18,7 @@ class CursorView extends View
@removeIdleClassTemporarily() unless bufferChange
@trigger 'cursor-move', {bufferChange}
@cursor.on 'change-visibility.cursor-view', (visible) => @setVisible(visible)
@cursor.on 'destroy.cursor-view', => @remove()
afterAttach: (onDom) ->
@@ -38,12 +39,16 @@ class CursorView extends View
if @cursor == @editor.getLastCursor()
@editor.scrollTo(pixelPosition)
if @editor.isFoldedAtScreenRow(screenPosition.row)
@hide() unless @hidden
@hidden = true
@setVisible(@cursor.isVisible() and not @editor.isFoldedAtScreenRow(screenPosition.row))
setVisible: (visible) ->
return if visible == @visible
@visible = visible
if @visible
@show()
else
@show() if @hidden
@hidden = false
@hide()
getBufferPosition: ->
@cursor.getBufferPosition()

View File

@@ -10,6 +10,7 @@ class Cursor
bufferPosition: null
goalColumn: null
wordRegex: /(\w+)|([^\w\s]+)/g
visible: true
constructor: ({@editSession, screenPosition, bufferPosition}) ->
@anchor = @editSession.addAnchor(strong: true)
@@ -38,6 +39,13 @@ class Cursor
getBufferPosition: ->
@anchor.getBufferPosition()
setVisible: (visible) ->
if @visible != visible
@visible = visible
@trigger 'change-visibility', @visible
isVisible: -> @visible
clearSelection: ->
if @selection
@selection.clear() unless @selection.retainSelection

View File

@@ -286,8 +286,8 @@ class EditSession
autoDecreaseIndentForRow: (bufferRow) ->
@languageMode.autoDecreaseIndentForBufferRow(bufferRow)
toggleLineCommentsInRange: (range) ->
@languageMode.toggleLineCommentsInRange(range)
toggleLineCommentsForBufferRows: (start, end) ->
@languageMode.toggleLineCommentsForBufferRows(start, end)
mutateSelectedText: (fn) ->
@transact => fn(selection) for selection in @getSelections()

View File

@@ -66,7 +66,7 @@ class Gutter extends View
currentLineNumberRow.removeClass('cursor-line-number')
currentLineNumberRow.removeClass('cursor-line-number-background')
newLineNumberRow = @find(".line-number:eq(#{screenRowIndex})")
newLineNumberRow.addClass('cursor-line-number')
if @editor().getSelection().isSingleScreenLine()
newLineNumberRow = @find(".line-number:eq(#{screenRowIndex})")
newLineNumberRow.addClass('cursor-line-number')
newLineNumberRow.addClass('cursor-line-number-background')

View File

@@ -68,18 +68,17 @@ class LanguageMode
@invertedPairedCharacters[close] = open
@invertedPairedCharacters
toggleLineCommentsInRange: (range) ->
range = Range.fromObject(range)
scopes = @getTokenizedBuffer().scopesForPosition(range.start)
toggleLineCommentsForBufferRows: (start, end) ->
scopes = @getTokenizedBuffer().scopesForPosition([start, 0])
return unless commentString = TextMateBundle.lineCommentStringForScope(scopes[0])
commentRegexString = _.escapeRegExp(commentString)
commentRegexString = commentRegexString.replace(/(\s+)$/, '($1)?')
commentRegex = new OnigRegExp("^\s*#{commentRegexString}")
shouldUncomment = commentRegex.test(@editSession.lineForBufferRow(range.start.row))
shouldUncomment = commentRegex.test(@editSession.lineForBufferRow(start))
for row in [range.start.row..range.end.row]
for row in [start..end]
line = @editSession.lineForBufferRow(row)
if shouldUncomment
if match = commentRegex.search(line)

View File

@@ -11,7 +11,7 @@ class Selection
@cursor.selection = this
@cursor.on 'change-screen-position.selection', (e) =>
@emitChangeScreenRangeEvent() unless e.bufferChanged
@screenRangeChanged() unless e.bufferChanged
@cursor.on 'destroy.selection', =>
@cursor = null
@@ -67,13 +67,25 @@ class Selection
else
new Range(@cursor.getBufferPosition(), @cursor.getBufferPosition())
getBufferRowRange: ->
range = @getBufferRange()
start = range.start.row
end = range.end.row
end = Math.max(start, end - 1) if range.end.column == 0
[start, end]
screenRangeChanged: ->
screenRange = @getScreenRange()
@trigger 'change-screen-range', screenRange
@cursor?.setVisible(screenRange.isEmpty())
getText: ->
@editSession.buffer.getTextInRange(@getBufferRange())
clear: ->
@anchor?.destroy()
@anchor = null
@emitChangeScreenRangeEvent()
@screenRangeChanged()
selectWord: ->
@setBufferRange(@cursor.getCurrentWordBufferRange())
@@ -161,8 +173,8 @@ class Selection
@indentSelectedRows()
indentSelectedRows: ->
range = @getBufferRange()
for row in [range.start.row..range.end.row]
[start, end] = @getBufferRowRange()
for row in [start..end]
@editSession.buffer.insert([row, 0], @editSession.getTabText()) unless @editSession.buffer.lineLengthForRow(row) == 0
normalizeIndent: (text, options) ->
@@ -258,16 +270,16 @@ class Selection
@editSession.buffer.deleteRows(start, end)
outdentSelectedRows: ->
range = @getBufferRange()
[start, end] = @getBufferRowRange()
buffer = @editSession.buffer
leadingTabRegex = new RegExp("^ {1,#{@editSession.getTabLength()}}|\t")
for row in [range.start.row..range.end.row]
for row in [start..end]
if matchLength = buffer.lineForRow(row).match(leadingTabRegex)?[0].length
buffer.delete [[row, 0], [row, matchLength]]
toggleLineComments: ->
@modifySelection =>
@editSession.toggleLineCommentsInRange(@getBufferRange())
@editSession.toggleLineCommentsForBufferRows(@getBufferRowRange()...)
cutToEndOfLine: (maintainPasteboard) ->
@selectToEndOfLine() if @isEmpty()
@@ -310,10 +322,7 @@ class Selection
placeAnchor: ->
@anchor = @editSession.addAnchor(strong: true)
@anchor.setScreenPosition(@cursor.getScreenPosition())
@anchor.on 'change-screen-position.selection', => @emitChangeScreenRangeEvent()
emitChangeScreenRangeEvent: ->
@trigger 'change-screen-range', @getScreenRange()
@anchor.on 'change-screen-position.selection', => @screenRangeChanged()
intersectsBufferRange: (bufferRange) ->
@getBufferRange().intersectsWith(bufferRange)