mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 07:58:04 +03:00
meta-c copies text in selection
This commit is contained in:
parent
99cbb5e0a2
commit
7dba7dc3de
@ -88,3 +88,20 @@ describe "Selection", ->
|
||||
expect(selection.regions.length).toBe 3
|
||||
expect(selection.find('.selection').length).toBe 3
|
||||
|
||||
describe ".copy()", ->
|
||||
beforeEach ->
|
||||
atom.native.writeToPasteboard('first')
|
||||
expect(atom.native.readFromPasteboard()).toBe 'first'
|
||||
|
||||
it "places selected text on the clipboard", ->
|
||||
selection.setRange new Range([0,4], [0,13])
|
||||
selection.copy()
|
||||
expect(atom.native.readFromPasteboard()).toBe 'quicksort'
|
||||
|
||||
it "places nothing on the clipboard when there is no selection", ->
|
||||
selection.setRange new Range([0,4], [0,4])
|
||||
selection.copy()
|
||||
expect(atom.native.readFromPasteboard()).toBe 'first'
|
||||
|
||||
|
||||
|
||||
|
@ -17,6 +17,15 @@ class Buffer
|
||||
setText: (text) ->
|
||||
@lines = text.split('\n')
|
||||
|
||||
getTextInRange: (range) ->
|
||||
if range.start.row == range.end.row
|
||||
return @lines[range.start.row][range.start.column...range.end.column]
|
||||
|
||||
text = @lines[range.start.row][range.start.column..]
|
||||
for row in [range.start.row...range.end.row]
|
||||
text += @lines[row]
|
||||
text += @lines[range.end.row][0...range.end.column]
|
||||
|
||||
getLines: ->
|
||||
@lines
|
||||
|
||||
|
@ -41,6 +41,7 @@ class Editor extends Template
|
||||
enter: 'newline'
|
||||
backspace: 'backspace'
|
||||
delete: 'delete'
|
||||
'meta-c': 'copy'
|
||||
|
||||
@on 'move-right', => @moveCursorRight()
|
||||
@on 'move-left', => @moveCursorLeft()
|
||||
@ -53,6 +54,7 @@ class Editor extends Template
|
||||
@on 'newline', => @insertNewline()
|
||||
@on 'backspace', => @backspace()
|
||||
@on 'delete', => @delete()
|
||||
@on 'copy', => @copyText()
|
||||
|
||||
|
||||
buildCursorAndSelection: ->
|
||||
@ -190,4 +192,6 @@ class Editor extends Template
|
||||
insertNewline: -> @selection.insertNewline()
|
||||
backspace: -> @selection.backspace()
|
||||
delete: -> @selection.delete()
|
||||
copySelection: -> @selection().copy()
|
||||
|
||||
|
||||
|
@ -150,3 +150,9 @@ class Selection extends Template
|
||||
moveCursorToLineStart: ->
|
||||
@cursor.moveToLineStart()
|
||||
|
||||
copy: ->
|
||||
return if @isEmpty()
|
||||
|
||||
text = @editor.buffer.getTextInRange @getRange()
|
||||
atom.native.writeToPasteboard text
|
||||
|
||||
|
@ -42,6 +42,11 @@ class Native
|
||||
pb.declareTypes_owner [OSX.NSStringPboardType], null
|
||||
pb.setString_forType text, OSX.NSStringPboardType
|
||||
|
||||
readFromPasteboard: (text) ->
|
||||
pb = OSX.NSPasteboard.generalPasteboard
|
||||
results = pb.readObjectsForClasses_options [OSX.NSString], null
|
||||
results?[0]?.toString()
|
||||
|
||||
resetMainMenu: (menu) ->
|
||||
OSX.NSApp.resetMainMenu
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user