2015-06-02 04:01:34 +03:00
path = require ' path '
2015-04-14 11:50:09 +03:00
clipboard = require ' ../src/safe-clipboard '
2014-09-23 01:35:13 +04:00
TextEditor = require ' ../src/text-editor '
2016-08-18 20:40:16 +03:00
TextBuffer = require ' text-buffer '
2012-08-28 02:36:36 +04:00
2014-09-23 01:35:13 +04:00
describe " TextEditor " , ->
2013-11-20 03:22:47 +04:00
[ buffer , editor , lineLengths ] = [ ]
2012-08-28 02:36:36 +04:00
2012-10-26 21:03:59 +04:00
convertToHardTabs = (buffer) ->
buffer . setText ( buffer . getText ( ) . replace ( /[ ]{2}/g , " \t " ) )
2014-03-06 08:32:11 +04:00
beforeEach ->
2014-04-23 04:52:28 +04:00
waitsForPromise ->
2016-01-13 05:07:24 +03:00
atom . workspace . open ( ' sample.js ' , { autoIndent: false } ) . then (o) -> editor = o
2014-04-23 04:52:28 +04:00
runs ->
buffer = editor . buffer
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: false } )
2014-04-23 04:52:28 +04:00
lineLengths = buffer . getLines ( ) . map (line) -> line . length
2014-03-06 08:32:11 +04:00
waitsForPromise ->
atom . packages . activatePackage ( ' language-javascript ' )
describe " when the editor is deserialized " , ->
it " restores selections and folds based on markers in the buffer " , ->
editor . setSelectedBufferRange ( [ [ 1 , 2 ] , [ 3 , 4 ] ] )
2014-04-23 04:52:28 +04:00
editor . addSelectionForBufferRange ( [ [ 5 , 6 ] , [ 7 , 5 ] ] , reversed: true )
2014-03-06 08:32:11 +04:00
editor . foldBufferRow ( 4 )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
2017-05-17 03:44:26 +03:00
waitsForPromise ->
TextBuffer . deserialize ( editor . buffer . serialize ( ) ) . then (buffer2) ->
editor2 = TextEditor . deserialize ( editor . serialize ( ) , {
assert: atom . assert ,
textEditors: atom . textEditors ,
project: { bufferForIdSync: -> buffer2 }
} )
2014-03-06 08:32:11 +04:00
2017-05-17 03:44:26 +03:00
expect ( editor2 . id ) . toBe editor . id
expect ( editor2 . getBuffer ( ) . getPath ( ) ) . toBe editor . getBuffer ( ) . getPath ( )
expect ( editor2 . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 1 , 2 ] , [ 3 , 4 ] ] , [ [ 5 , 6 ] , [ 7 , 5 ] ] ]
expect ( editor2 . getSelections ( ) [ 1 ] . isReversed ( ) ) . toBeTruthy ( )
expect ( editor2 . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
editor2 . destroy ( )
2014-03-06 08:32:11 +04:00
2016-08-16 01:51:22 +03:00
it " restores the editor ' s layout configuration " , ->
editor . update ( {
softTabs: true
2016-08-18 20:40:16 +03:00
atomicSoftTabs: false
2016-08-16 01:51:22 +03:00
tabLength: 12
softWrapped: true
softWrapAtPreferredLineLength: true
softWrapHangingIndentLength: 8
invisibles: { space: ' S ' }
showInvisibles: true
editorWidthInChars: 120
} )
2016-08-18 20:40:16 +03:00
# Force buffer and display layer to be deserialized as well, rather than
# reusing the same buffer instance
2017-05-17 03:44:26 +03:00
waitsForPromise ->
TextBuffer . deserialize ( editor . buffer . serialize ( ) ) . then (buffer2) ->
editor2 = TextEditor . deserialize ( editor . serialize ( ) , {
assert: atom . assert ,
textEditors: atom . textEditors ,
project: { bufferForIdSync: -> buffer2 }
} )
2016-08-16 01:51:22 +03:00
2017-05-17 03:44:26 +03:00
expect ( editor2 . getSoftTabs ( ) ) . toBe ( editor . getSoftTabs ( ) )
expect ( editor2 . hasAtomicSoftTabs ( ) ) . toBe ( editor . hasAtomicSoftTabs ( ) )
expect ( editor2 . getTabLength ( ) ) . toBe ( editor . getTabLength ( ) )
expect ( editor2 . getSoftWrapColumn ( ) ) . toBe ( editor . getSoftWrapColumn ( ) )
expect ( editor2 . getSoftWrapHangingIndentLength ( ) ) . toBe ( editor . getSoftWrapHangingIndentLength ( ) )
expect ( editor2 . getInvisibles ( ) ) . toEqual ( editor . getInvisibles ( ) )
expect ( editor2 . getEditorWidthInChars ( ) ) . toBe ( editor . getEditorWidthInChars ( ) )
expect ( editor2 . displayLayer . tabLength ) . toBe ( editor2 . getTabLength ( ) )
2016-08-16 01:51:22 +03:00
2015-06-06 00:40:29 +03:00
describe " when the editor is constructed with the largeFileMode option set to true " , ->
it " loads the editor but doesn ' t tokenize " , ->
editor = null
waitsForPromise ->
2015-10-03 06:13:42 +03:00
atom . workspace . openTextFile ( ' sample.js ' , largeFileMode: true ) . then (o) -> editor = o
2015-06-06 00:40:29 +03:00
runs ->
buffer = editor . getBuffer ( )
2016-03-22 16:49:29 +03:00
expect ( editor . lineTextForScreenRow ( 0 ) ) . toBe buffer . lineForRow ( 0 )
expect ( editor . tokensForScreenRow ( 0 ) . length ) . toBe 1
expect ( editor . tokensForScreenRow ( 1 ) . length ) . toBe 2 # soft tab
expect ( editor . lineTextForScreenRow ( 12 ) ) . toBe buffer . lineForRow ( 12 )
2015-06-06 00:40:29 +03:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 0 , 0 ]
editor . insertText ( ' hey " ' )
2016-03-22 16:49:29 +03:00
expect ( editor . tokensForScreenRow ( 0 ) . length ) . toBe 1
expect ( editor . tokensForScreenRow ( 1 ) . length ) . toBe 2 # soft tab
2015-06-06 00:40:29 +03:00
2014-03-06 08:32:11 +04:00
describe " .copy() " , ->
2016-08-08 21:07:14 +03:00
it " returns a different editor with the same initial state " , ->
2017-01-20 06:30:06 +03:00
expect ( editor . getAutoHeight ( ) ) . toBeFalsy ( )
expect ( editor . getAutoWidth ( ) ) . toBeFalsy ( )
expect ( editor . getShowCursorOnSelection ( ) ) . toBeTruthy ( )
2017-04-19 06:28:05 +03:00
element = editor . getElement ( )
element . setHeight ( 100 )
element . setWidth ( 100 )
jasmine . attachToDOM ( element )
editor . update ( { showCursorOnSelection: false } )
2014-03-06 08:32:11 +04:00
editor . setSelectedBufferRange ( [ [ 1 , 2 ] , [ 3 , 4 ] ] )
2014-04-23 04:52:28 +04:00
editor . addSelectionForBufferRange ( [ [ 5 , 6 ] , [ 7 , 8 ] ] , reversed: true )
2017-04-19 06:28:05 +03:00
editor . setScrollTopRow ( 3 )
expect ( editor . getScrollTopRow ( ) ) . toBe ( 3 )
editor . setScrollLeftColumn ( 4 )
expect ( editor . getScrollLeftColumn ( ) ) . toBe ( 4 )
2014-03-06 08:32:11 +04:00
editor . foldBufferRow ( 4 )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
editor2 = editor . copy ( )
2017-04-19 06:28:05 +03:00
element2 = editor2 . getElement ( )
element2 . setHeight ( 100 )
element2 . setWidth ( 100 )
jasmine . attachToDOM ( element2 )
2014-03-06 08:32:11 +04:00
expect ( editor2 . id ) . not . toBe editor . id
expect ( editor2 . getSelectedBufferRanges ( ) ) . toEqual editor . getSelectedBufferRanges ( )
2014-08-29 05:16:33 +04:00
expect ( editor2 . getSelections ( ) [ 1 ] . isReversed ( ) ) . toBeTruthy ( )
2017-04-19 06:28:05 +03:00
expect ( editor2 . getScrollTopRow ( ) ) . toBe ( 3 )
expect ( editor2 . getScrollLeftColumn ( ) ) . toBe ( 4 )
2014-03-06 08:32:11 +04:00
expect ( editor2 . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
2017-04-19 06:28:05 +03:00
expect ( editor2 . getAutoWidth ( ) ) . toBe ( false )
expect ( editor2 . getAutoHeight ( ) ) . toBe ( false )
2017-01-20 06:30:06 +03:00
expect ( editor2 . getShowCursorOnSelection ( ) ) . toBeFalsy ( )
2014-03-06 08:32:11 +04:00
# editor2 can now diverge from its origin edit session
2014-08-29 04:51:16 +04:00
editor2 . getLastSelection ( ) . setBufferRange ( [ [ 2 , 1 ] , [ 4 , 3 ] ] )
2014-03-06 08:32:11 +04:00
expect ( editor2 . getSelectedBufferRanges ( ) ) . not . toEqual editor . getSelectedBufferRanges ( )
editor2 . unfoldBufferRow ( 4 )
expect ( editor2 . isFoldedAtBufferRow ( 4 ) ) . not . toBe editor . isFoldedAtBufferRow ( 4 )
2016-06-30 13:42:15 +03:00
describe " .update() " , ->
it " updates the editor with the supplied config parameters " , ->
2016-07-08 10:42:08 +03:00
element = editor . element # force element initialization
2016-08-17 14:17:54 +03:00
element . setUpdatedSynchronously ( false )
2016-08-16 02:45:05 +03:00
editor . update ( { showInvisibles: true } )
2016-06-30 13:42:15 +03:00
editor . onDidChange ( changeSpy = jasmine . createSpy ( ' onDidChange ' ) )
2016-08-11 21:10:54 +03:00
2016-08-17 14:17:54 +03:00
returnedPromise = editor . update ( {
2016-06-30 13:42:15 +03:00
tabLength: 6 , softTabs: false , softWrapped: true , editorWidthInChars: 40 ,
2016-08-11 21:10:54 +03:00
showInvisibles: false , mini: false , lineNumberGutterVisible: false , scrollPastEnd: true ,
2016-06-30 16:30:05 +03:00
autoHeight: false
2016-06-30 13:42:15 +03:00
} )
2016-07-08 10:42:08 +03:00
2017-04-13 15:57:35 +03:00
expect ( returnedPromise ) . toBe ( element . component . getNextUpdatePromise ( ) )
2016-08-17 14:17:54 +03:00
expect ( changeSpy . callCount ) . toBe ( 1 )
expect ( editor . getTabLength ( ) ) . toBe ( 6 )
expect ( editor . getSoftTabs ( ) ) . toBe ( false )
expect ( editor . isSoftWrapped ( ) ) . toBe ( true )
expect ( editor . getEditorWidthInChars ( ) ) . toBe ( 40 )
expect ( editor . getInvisibles ( ) ) . toEqual ( { } )
expect ( editor . isMini ( ) ) . toBe ( false )
expect ( editor . isLineNumberGutterVisible ( ) ) . toBe ( false )
expect ( editor . getScrollPastEnd ( ) ) . toBe ( true )
expect ( editor . getAutoHeight ( ) ) . toBe ( false )
2016-06-30 13:42:15 +03:00
2014-03-06 08:32:11 +04:00
describe " title " , ->
describe " .getTitle() " , ->
it " uses the basename of the buffer ' s path as its title, or ' untitled ' if the path is undefined " , ->
expect ( editor . getTitle ( ) ) . toBe ' sample.js '
buffer . setPath ( undefined )
expect ( editor . getTitle ( ) ) . toBe ' untitled '
2013-12-11 07:07:50 +04:00
2014-03-06 08:32:11 +04:00
describe " .getLongTitle() " , ->
2015-10-02 11:19:38 +03:00
it " returns file name when there is no opened file with identical name " , ->
2015-11-17 19:53:13 +03:00
expect ( editor . getLongTitle ( ) ) . toBe ' sample.js '
2013-09-13 21:49:01 +04:00
buffer . setPath ( undefined )
2014-03-06 08:32:11 +04:00
expect ( editor . getLongTitle ( ) ) . toBe ' untitled '
2015-11-16 21:46:53 +03:00
it " returns ' <filename> — <parent-directory> ' when opened files have identical file names " , ->
2015-10-02 11:19:38 +03:00
editor1 = null
editor2 = null
waitsForPromise ->
atom . workspace . open ( path . join ( ' sample-theme-1 ' , ' readme ' ) ) . then (o) ->
editor1 = o
atom . workspace . open ( path . join ( ' sample-theme-2 ' , ' readme ' ) ) . then (o) ->
editor2 = o
runs ->
2015-11-16 21:46:53 +03:00
expect ( editor1 . getLongTitle ( ) ) . toBe " readme \u 2014 sample-theme-1 "
expect ( editor2 . getLongTitle ( ) ) . toBe " readme \u 2014 sample-theme-2 "
2015-10-02 11:19:38 +03:00
2016-04-15 21:25:05 +03:00
it " returns ' <filename> — <parent-directories> ' when opened files have identical file names in subdirectories " , ->
2015-10-02 11:19:38 +03:00
editor1 = null
editor2 = null
2016-04-15 21:25:05 +03:00
path1 = path . join ( ' sample-theme-1 ' , ' src ' , ' js ' )
path2 = path . join ( ' sample-theme-2 ' , ' src ' , ' js ' )
2015-10-02 11:19:38 +03:00
waitsForPromise ->
2016-04-15 21:25:05 +03:00
atom . workspace . open ( path . join ( path1 , ' main.js ' ) ) . then (o) ->
2015-10-02 11:19:38 +03:00
editor1 = o
2016-04-15 21:25:05 +03:00
atom . workspace . open ( path . join ( path2 , ' main.js ' ) ) . then (o) ->
2015-10-02 11:19:38 +03:00
editor2 = o
runs ->
2016-04-15 21:25:05 +03:00
expect ( editor1 . getLongTitle ( ) ) . toBe " main.js \u 2014 #{ path1 } "
expect ( editor2 . getLongTitle ( ) ) . toBe " main.js \u 2014 #{ path2 } "
2015-10-02 11:19:38 +03:00
2015-11-16 21:46:53 +03:00
it " returns ' <filename> — <parent-directories> ' when opened files have identical file and same parent dir name " , ->
editor1 = null
editor2 = null
waitsForPromise ->
atom . workspace . open ( path . join ( ' sample-theme-2 ' , ' src ' , ' js ' , ' main.js ' ) ) . then (o) ->
editor1 = o
atom . workspace . open ( path . join ( ' sample-theme-2 ' , ' src ' , ' js ' , ' plugin ' , ' main.js ' ) ) . then (o) ->
editor2 = o
runs ->
expect ( editor1 . getLongTitle ( ) ) . toBe " main.js \u 2014 js "
2016-04-15 21:25:05 +03:00
expect ( editor2 . getLongTitle ( ) ) . toBe " main.js \u 2014 " + path . join ( ' js ' , ' plugin ' )
2015-10-02 11:19:38 +03:00
2014-09-04 18:12:51 +04:00
it " notifies ::onDidChangeTitle observers when the underlying buffer path changes " , ->
observed = [ ]
editor . onDidChangeTitle (title) -> observed . push ( title )
2014-03-06 08:32:11 +04:00
buffer . setPath ( ' /foo/bar/baz.txt ' )
buffer . setPath ( undefined )
2014-09-04 18:12:51 +04:00
expect ( observed ) . toEqual [ ' baz.txt ' , ' untitled ' ]
2014-03-06 08:32:11 +04:00
2014-09-04 18:15:19 +04:00
describe " path " , ->
it " notifies ::onDidChangePath observers when the underlying buffer path changes " , ->
2014-09-05 23:44:56 +04:00
observed = [ ]
editor . onDidChangePath (filePath) -> observed . push ( filePath )
2014-09-04 18:15:19 +04:00
2014-09-10 21:22:48 +04:00
buffer . setPath ( __filename )
2014-09-05 23:44:56 +04:00
buffer . setPath ( undefined )
2014-09-04 18:15:19 +04:00
2014-09-10 21:22:48 +04:00
expect ( observed ) . toEqual [ __filename , undefined ]
2014-09-04 18:15:19 +04:00
2014-10-29 20:46:41 +03:00
describe " encoding " , ->
it " notifies ::onDidChangeEncoding observers when the editor encoding changes " , ->
observed = [ ]
editor . onDidChangeEncoding (encoding) -> observed . push ( encoding )
editor . setEncoding ( ' utf16le ' )
editor . setEncoding ( ' utf16le ' )
editor . setEncoding ( ' utf16be ' )
editor . setEncoding ( )
editor . setEncoding ( )
expect ( observed ) . toEqual [ ' utf16le ' , ' utf16be ' , ' utf8 ' ]
2014-03-06 08:32:11 +04:00
describe " cursor " , ->
2014-08-29 05:10:18 +04:00
describe " .getLastCursor() " , ->
2014-03-06 08:32:11 +04:00
it " returns the most recently created cursor " , ->
editor . addCursorAtScreenPosition ( [ 1 , 0 ] )
lastCursor = editor . addCursorAtScreenPosition ( [ 2 , 0 ] )
2014-08-29 05:10:18 +04:00
expect ( editor . getLastCursor ( ) ) . toBe lastCursor
2014-03-06 08:32:11 +04:00
2015-08-27 02:59:19 +03:00
it " creates a new cursor at (0, 0) if the last cursor has been destroyed " , ->
editor . getLastCursor ( ) . destroy ( )
expect ( editor . getLastCursor ( ) . getBufferPosition ( ) ) . toEqual ( [ 0 , 0 ] )
describe " .getCursors() " , ->
it " creates a new cursor at (0, 0) if the last cursor has been destroyed " , ->
editor . getLastCursor ( ) . destroy ( )
expect ( editor . getCursors ( ) [ 0 ] . getBufferPosition ( ) ) . toEqual ( [ 0 , 0 ] )
2014-03-06 08:32:11 +04:00
describe " when the cursor moves " , ->
it " clears a goal column established by vertical movement " , ->
editor . setText ( ' b ' )
2015-05-23 00:03:06 +03:00
editor . setCursorBufferPosition ( [ 0 , 0 ] )
2014-03-06 08:32:11 +04:00
editor . insertNewline ( )
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
editor . insertText ( ' a ' )
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 1 ]
2014-09-23 02:37:41 +04:00
it " emits an event with the old position, new position, and the cursor that moved " , ->
2014-12-10 04:21:03 +03:00
cursorCallback = jasmine . createSpy ( ' cursor-changed-position ' )
editorCallback = jasmine . createSpy ( ' editor-changed-cursor-position ' )
editor . getLastCursor ( ) . onDidChangePosition ( cursorCallback )
editor . onDidChangeCursorPosition ( editorCallback )
2014-09-23 02:37:41 +04:00
editor . setCursorBufferPosition ( [ 2 , 4 ] )
2014-12-10 04:21:03 +03:00
expect ( editorCallback ) . toHaveBeenCalled ( )
expect ( cursorCallback ) . toHaveBeenCalled ( )
eventObject = editorCallback . mostRecentCall . args [ 0 ]
expect ( cursorCallback . mostRecentCall . args [ 0 ] ) . toEqual ( eventObject )
2014-09-23 02:37:41 +04:00
expect ( eventObject . oldBufferPosition ) . toEqual [ 0 , 0 ]
expect ( eventObject . oldScreenPosition ) . toEqual [ 0 , 0 ]
expect ( eventObject . newBufferPosition ) . toEqual [ 2 , 4 ]
expect ( eventObject . newScreenPosition ) . toEqual [ 2 , 4 ]
expect ( eventObject . cursor ) . toBe editor . getLastCursor ( )
2014-03-06 08:32:11 +04:00
describe " .setCursorScreenPosition(screenPosition) " , ->
it " clears a goal column established by vertical movement " , ->
# set a goal column by moving down
editor . setCursorScreenPosition ( row: 3 , column: lineLengths [ 3 ] )
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . not . toBe 6
# clear the goal column by explicitly setting the cursor position
2015-05-23 00:03:06 +03:00
editor . setCursorScreenPosition ( [ 4 , 6 ] )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe 6
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe 6
it " merges multiple cursors " , ->
editor . setCursorScreenPosition ( [ 0 , 0 ] )
editor . addCursorAtScreenPosition ( [ 0 , 1 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
editor . setCursorScreenPosition ( [ 4 , 7 ] )
expect ( editor . getCursors ( ) . length ) . toBe 1
expect ( editor . getCursors ( ) ) . toEqual [ cursor1 ]
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 4 , 7 ]
describe " when soft-wrap is enabled and code is folded " , ->
beforeEach ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2014-03-06 08:32:11 +04:00
editor . setEditorWidthInChars ( 50 )
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 2 , 3 )
2013-12-12 06:01:12 +04:00
2014-03-06 08:32:11 +04:00
it " positions the cursor at the buffer position that corresponds to the given screen position " , ->
editor . setCursorScreenPosition ( [ 9 , 0 ] )
2016-12-13 04:05:18 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 8 , 11 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveUp() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor up " , ->
editor . setCursorScreenPosition ( [ 2 , 2 ] )
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 1 , 2 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " retains the goal column across lines of differing length " , ->
expect ( lineLengths [ 6 ] ) . toBeGreaterThan ( 32 )
editor . setCursorScreenPosition ( row: 6 , column: 32 )
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe lineLengths [ 5 ]
2013-07-24 01:06:21 +04:00
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe lineLengths [ 4 ]
2013-09-13 21:49:01 +04:00
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe 32
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is on the first line " , ->
it " moves the cursor to the beginning of the line, but retains the goal column " , ->
editor . setCursorScreenPosition ( [ 0 , 4 ] )
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual ( [ 0 , 0 ] )
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual ( [ 1 , 4 ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when there is a selection " , ->
beforeEach ->
2015-05-23 00:03:06 +03:00
editor . setSelectedBufferRange ( [ [ 4 , 9 ] , [ 5 , 10 ] ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " moves above the selection " , ->
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getBufferPosition ( ) ) . toEqual [ 3 , 9 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " merges cursors when they overlap " , ->
editor . addCursorAtScreenPosition ( [ 1 , 0 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursors ( ) ) . toEqual [ cursor1 ]
2015-05-23 00:03:06 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 0 ]
2012-08-28 02:36:36 +04:00
2015-02-19 22:01:37 +03:00
describe " when the cursor was moved down from the beginning of an indented soft-wrapped line " , ->
it " moves to the beginning of the previous line " , ->
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2015-02-19 22:01:37 +03:00
editor . setEditorWidthInChars ( 50 )
editor . setCursorScreenPosition ( [ 3 , 0 ] )
editor . moveDown ( )
editor . moveDown ( )
editor . moveUp ( )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 4 , 4 ]
2014-08-29 02:25:12 +04:00
describe " .moveDown() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor down " , ->
editor . setCursorScreenPosition ( [ 2 , 2 ] )
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 3 , 2 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " retains the goal column across lines of differing length " , ->
editor . setCursorScreenPosition ( row: 3 , column: lineLengths [ 3 ] )
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe lineLengths [ 4 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe lineLengths [ 5 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe lineLengths [ 3 ]
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is on the last line " , ->
it " moves the cursor to the end of line, but retains the goal column when moving back up " , ->
lastLineIndex = buffer . getLines ( ) . length - 1
lastLine = buffer . lineForRow ( lastLineIndex )
expect ( lastLine . length ) . toBeGreaterThan ( 0 )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
editor . setCursorScreenPosition ( row: lastLineIndex , column: editor . getTabLength ( ) )
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual ( row: lastLineIndex , column: lastLine . length )
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe editor . getTabLength ( )
2012-11-06 21:03:54 +04:00
2014-03-06 08:32:11 +04:00
it " retains a goal column of 0 when moving back up " , ->
lastLineIndex = buffer . getLines ( ) . length - 1
lastLine = buffer . lineForRow ( lastLineIndex )
expect ( lastLine . length ) . toBeGreaterThan ( 0 )
2013-07-23 02:31:39 +04:00
2014-03-06 08:32:11 +04:00
editor . setCursorScreenPosition ( row: lastLineIndex , column: 0 )
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) . column ) . toBe 0
2013-07-23 02:31:39 +04:00
2015-02-19 22:01:37 +03:00
describe " when the cursor is at the beginning of an indented soft-wrapped line " , ->
it " moves to the beginning of the line ' s continuation on the next screen row " , ->
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2015-02-19 22:01:37 +03:00
editor . setEditorWidthInChars ( 50 )
editor . setCursorScreenPosition ( [ 3 , 0 ] )
editor . moveDown ( )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 4 , 4 ]
2014-03-06 08:32:11 +04:00
describe " when there is a selection " , ->
beforeEach ->
2015-05-23 00:03:06 +03:00
editor . setSelectedBufferRange ( [ [ 4 , 9 ] , [ 5 , 10 ] ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " moves below the selection " , ->
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getBufferPosition ( ) ) . toEqual [ 6 , 10 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " merges cursors when they overlap " , ->
editor . setCursorScreenPosition ( [ 12 , 2 ] )
editor . addCursorAtScreenPosition ( [ 11 , 2 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursors ( ) ) . toEqual [ cursor1 ]
2015-05-23 00:03:06 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 12 , 2 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveLeft() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor by one column to the left " , ->
editor . setCursorScreenPosition ( [ 1 , 8 ] )
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 1 , 7 ]
2012-08-28 02:36:36 +04:00
2014-09-03 04:29:05 +04:00
it " moves the cursor by n columns to the left " , ->
editor . setCursorScreenPosition ( [ 1 , 8 ] )
editor . moveLeft ( 4 )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 1 , 4 ]
2014-09-04 02:27:42 +04:00
it " moves the cursor by two rows up when the columnCount is longer than an entire line " , ->
editor . setCursorScreenPosition ( [ 2 , 2 ] )
editor . moveLeft ( 34 )
2014-09-04 04:19:06 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 0 , 29 ]
2014-09-04 02:27:42 +04:00
it " moves the cursor to the beginning columnCount is longer than the position in the buffer " , ->
editor . setCursorScreenPosition ( [ 1 , 0 ] )
editor . moveLeft ( 100 )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 0 , 0 ]
2014-03-06 08:32:11 +04:00
describe " when the cursor is in the first column " , ->
describe " when there is a previous line " , ->
it " wraps to the end of the previous line " , ->
editor . setCursorScreenPosition ( row: 1 , column: 0 )
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual ( row: 0 , column: buffer . lineForRow ( 0 ) . length )
2012-08-28 02:36:36 +04:00
2014-09-04 02:54:46 +04:00
it " moves the cursor by one row up and n columns to the left " , ->
2014-09-03 04:29:30 +04:00
editor . setCursorScreenPosition ( [ 1 , 0 ] )
editor . moveLeft ( 4 )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 0 , 26 ]
2014-09-04 04:19:06 +04:00
describe " when the next line is empty " , ->
it " wraps to the beginning of the previous line " , ->
editor . setCursorScreenPosition ( [ 11 , 0 ] )
editor . moveLeft ( )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 10 , 0 ]
2015-02-18 23:18:37 +03:00
describe " when line is wrapped and follow previous line indentation " , ->
beforeEach ->
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2015-02-18 23:18:37 +03:00
editor . setEditorWidthInChars ( 50 )
it " wraps to the end of the previous line " , ->
editor . setCursorScreenPosition ( [ 4 , 4 ] )
editor . moveLeft ( )
2016-03-22 18:05:38 +03:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 3 , 46 ]
2015-02-18 23:18:37 +03:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is on the first line " , ->
it " remains in the same position (0,0) " , ->
editor . setCursorScreenPosition ( row: 0 , column: 0 )
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual ( row: 0 , column: 0 )
2012-08-28 02:36:36 +04:00
2014-09-04 02:27:42 +04:00
it " remains in the same position (0,0) when columnCount is specified " , ->
2014-09-03 04:29:30 +04:00
editor . setCursorScreenPosition ( [ 0 , 0 ] )
editor . moveLeft ( 4 )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 0 , 0 ]
2014-03-06 08:32:11 +04:00
describe " when softTabs is enabled and the cursor is preceded by leading whitespace " , ->
it " skips tabLength worth of whitespace at a time " , ->
editor . setCursorBufferPosition ( [ 5 , 6 ] )
2013-07-23 02:31:39 +04:00
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 5 , 4 ]
2013-07-23 02:31:39 +04:00
2014-03-06 08:32:11 +04:00
describe " when there is a selection " , ->
beforeEach ->
2015-05-23 00:03:06 +03:00
editor . setSelectedBufferRange ( [ [ 5 , 22 ] , [ 5 , 27 ] ] )
2013-07-23 02:31:39 +04:00
2014-03-06 08:32:11 +04:00
it " moves to the left of the selection " , ->
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getBufferPosition ( ) ) . toEqual [ 5 , 22 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getBufferPosition ( ) ) . toEqual [ 5 , 21 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " merges cursors when they overlap " , ->
editor . setCursorScreenPosition ( [ 0 , 0 ] )
editor . addCursorAtScreenPosition ( [ 0 , 1 ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursors ( ) ) . toEqual [ cursor1 ]
2015-05-23 00:03:06 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 0 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveRight() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor by one column to the right " , ->
editor . setCursorScreenPosition ( [ 3 , 3 ] )
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 3 , 4 ]
2013-08-06 20:53:52 +04:00
2014-09-04 02:54:46 +04:00
it " moves the cursor by n columns to the right " , ->
editor . setCursorScreenPosition ( [ 3 , 7 ] )
editor . moveRight ( 4 )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 3 , 11 ]
it " moves the cursor by two rows down when the columnCount is longer than an entire line " , ->
2014-09-04 04:19:06 +04:00
editor . setCursorScreenPosition ( [ 0 , 29 ] )
editor . moveRight ( 34 )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 2 , 2 ]
2014-09-04 02:54:46 +04:00
it " moves the cursor to the end of the buffer when columnCount is longer than the number of characters following the cursor position " , ->
editor . setCursorScreenPosition ( [ 11 , 5 ] )
editor . moveRight ( 100 )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 12 , 2 ]
2014-03-06 08:32:11 +04:00
describe " when the cursor is on the last column of a line " , ->
describe " when there is a subsequent line " , ->
it " wraps to the beginning of the next line " , ->
editor . setCursorScreenPosition ( [ 0 , buffer . lineForRow ( 0 ) . length ] )
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 1 , 0 ]
2013-09-13 21:49:01 +04:00
2014-09-04 02:54:46 +04:00
it " moves the cursor by one row down and n columns to the right " , ->
editor . setCursorScreenPosition ( [ 0 , buffer . lineForRow ( 0 ) . length ] )
editor . moveRight ( 4 )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 1 , 3 ]
2014-09-04 04:19:06 +04:00
describe " when the next line is empty " , ->
it " wraps to the beginning of the next line " , ->
editor . setCursorScreenPosition ( [ 9 , 4 ] )
editor . moveRight ( )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 10 , 0 ]
2014-03-06 08:32:11 +04:00
describe " when the cursor is on the last line " , ->
it " remains in the same position " , ->
lastLineIndex = buffer . getLines ( ) . length - 1
lastLine = buffer . lineForRow ( lastLineIndex )
expect ( lastLine . length ) . toBeGreaterThan ( 0 )
2015-04-07 06:45:02 +03:00
lastPosition = { row: lastLineIndex , column: lastLine . length }
2014-03-06 08:32:11 +04:00
editor . setCursorScreenPosition ( lastPosition )
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual ( lastPosition )
describe " when there is a selection " , ->
beforeEach ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 5 , 22 ] , [ 5 , 27 ] ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " moves to the left of the selection " , ->
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getBufferPosition ( ) ) . toEqual [ 5 , 27 ]
2013-08-06 20:53:52 +04:00
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getBufferPosition ( ) ) . toEqual [ 5 , 28 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " merges cursors when they overlap " , ->
editor . setCursorScreenPosition ( [ 12 , 2 ] )
editor . addCursorAtScreenPosition ( [ 12 , 1 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursors ( ) ) . toEqual [ cursor1 ]
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 12 , 2 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveToTop() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor to the top of the buffer " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 11 , 1 ]
editor . addCursorAtScreenPosition [ 12 , 0 ]
2014-08-29 02:25:12 +04:00
editor . moveToTop ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursors ( ) . length ) . toBe 1
2015-05-23 00:03:06 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
2013-08-06 20:53:52 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveToBottom() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cusor to the bottom of the buffer " , ->
2015-05-23 00:03:06 +03:00
editor . setCursorScreenPosition [ 0 , 0 ]
editor . addCursorAtScreenPosition [ 1 , 0 ]
2014-08-29 02:25:12 +04:00
editor . moveToBottom ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursors ( ) . length ) . toBe 1
2015-05-23 00:03:06 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 12 , 2 ]
2013-08-06 20:53:52 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveToBeginningOfScreenLine() " , ->
2014-03-06 08:32:11 +04:00
describe " when soft wrap is on " , ->
it " moves cursor to the beginning of the screen line " , ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2013-12-31 05:53:21 +04:00
editor . setEditorWidthInChars ( 10 )
editor . setCursorScreenPosition ( [ 1 , 2 ] )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfScreenLine ( )
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getScreenPosition ( ) ) . toEqual [ 1 , 0 ]
describe " when soft wrap is off " , ->
2015-05-23 00:03:06 +03:00
it " moves cursor to the beginning of the line " , ->
editor . setCursorScreenPosition [ 0 , 5 ]
editor . addCursorAtScreenPosition [ 1 , 7 ]
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfScreenLine ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursors ( ) . length ) . toBe 2
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 00:03:06 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 0 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 0 ]
2013-12-31 05:53:21 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveToEndOfScreenLine() " , ->
2014-03-06 08:32:11 +04:00
describe " when soft wrap is on " , ->
it " moves cursor to the beginning of the screen line " , ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2013-12-31 05:53:21 +04:00
editor . setEditorWidthInChars ( 10 )
2014-03-06 08:32:11 +04:00
editor . setCursorScreenPosition ( [ 1 , 2 ] )
2014-08-29 02:25:12 +04:00
editor . moveToEndOfScreenLine ( )
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getScreenPosition ( ) ) . toEqual [ 1 , 9 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when soft wrap is off " , ->
it " moves cursor to the end of line " , ->
2015-05-23 00:03:06 +03:00
editor . setCursorScreenPosition [ 0 , 0 ]
editor . addCursorAtScreenPosition [ 1 , 0 ]
2014-08-29 02:25:12 +04:00
editor . moveToEndOfScreenLine ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursors ( ) . length ) . toBe 2
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 00:03:06 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 29 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 30 ]
2014-03-06 08:32:11 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveToBeginningOfLine() " , ->
2014-03-06 08:32:11 +04:00
it " moves cursor to the beginning of the buffer line " , ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2014-03-06 08:32:11 +04:00
editor . setEditorWidthInChars ( 10 )
editor . setCursorScreenPosition ( [ 1 , 2 ] )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfLine ( )
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getScreenPosition ( ) ) . toEqual [ 0 , 0 ]
2014-08-29 02:25:12 +04:00
describe " .moveToEndOfLine() " , ->
2014-03-06 08:32:11 +04:00
it " moves cursor to the end of the buffer line " , ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2014-03-06 08:32:11 +04:00
editor . setEditorWidthInChars ( 10 )
editor . setCursorScreenPosition ( [ 0 , 2 ] )
2014-08-29 02:25:12 +04:00
editor . moveToEndOfLine ( )
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2016-03-22 18:05:38 +03:00
expect ( cursor . getScreenPosition ( ) ) . toEqual [ 4 , 4 ]
2014-03-06 08:32:11 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveToFirstCharacterOfLine() " , ->
2014-03-06 08:32:11 +04:00
describe " when soft wrap is on " , ->
it " moves to the first character of the current screen line or the beginning of the screen line if it ' s already on the first character " , ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2014-03-06 08:32:11 +04:00
editor . setEditorWidthInChars ( 10 )
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 2 , 5 ]
editor . addCursorAtScreenPosition [ 8 , 7 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveToFirstCharacterOfLine ( )
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getScreenPosition ( ) ) . toEqual [ 2 , 0 ]
expect ( cursor2 . getScreenPosition ( ) ) . toEqual [ 8 , 2 ]
2013-09-13 21:49:01 +04:00
2014-08-29 02:25:12 +04:00
editor . moveToFirstCharacterOfLine ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getScreenPosition ( ) ) . toEqual [ 2 , 0 ]
expect ( cursor2 . getScreenPosition ( ) ) . toEqual [ 8 , 2 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when soft wrap is off " , ->
it " moves to the first character of the current line or the beginning of the line if it ' s already on the first character " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 0 , 5 ]
editor . addCursorAtScreenPosition [ 1 , 7 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveToFirstCharacterOfLine ( )
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 0 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 2 ]
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveToFirstCharacterOfLine ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 0 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 0 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " moves to the beginning of the line if it only contains whitespace " , ->
editor . setText ( " first \n \n third " )
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 1 , 2 ]
2014-08-29 02:25:12 +04:00
editor . moveToFirstCharacterOfLine ( )
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2015-05-23 02:50:04 +03:00
expect ( cursor . getBufferPosition ( ) ) . toEqual [ 1 , 0 ]
2012-08-28 02:36:36 +04:00
2014-08-19 21:49:54 +04:00
describe " when invisible characters are enabled with soft tabs " , ->
2014-08-13 00:09:05 +04:00
it " moves to the first character of the current line without being confused by the invisible characters " , ->
2016-08-16 02:45:05 +03:00
editor . update ( { showInvisibles: true } )
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 1 , 7 ]
2014-08-29 02:25:12 +04:00
editor . moveToFirstCharacterOfLine ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 2 ]
2014-08-29 02:25:12 +04:00
editor . moveToFirstCharacterOfLine ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 0 ]
2014-08-13 00:09:05 +04:00
2014-08-19 21:49:54 +04:00
describe " when invisible characters are enabled with hard tabs " , ->
it " moves to the first character of the current line without being confused by the invisible characters " , ->
2016-08-16 02:45:05 +03:00
editor . update ( { showInvisibles: true } )
2014-11-26 02:05:07 +03:00
buffer . setTextInRange ( [ [ 1 , 0 ] , [ 1 , Infinity ] ] , ' \t \t \t a ' , normalizeLineEndings: false )
2014-08-19 21:49:54 +04:00
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 1 , 7 ]
2014-08-29 02:25:12 +04:00
editor . moveToFirstCharacterOfLine ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 3 ]
2014-08-29 02:25:12 +04:00
editor . moveToFirstCharacterOfLine ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 0 ]
2014-08-19 21:49:54 +04:00
2014-08-29 02:25:12 +04:00
describe " .moveToBeginningOfWord() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor to the beginning of the word " , ->
editor . setCursorBufferPosition [ 0 , 8 ]
editor . addCursorAtBufferPosition [ 1 , 12 ]
editor . addCursorAtBufferPosition [ 3 , 0 ]
[ cursor1 , cursor2 , cursor3 ] = editor . getCursors ( )
2012-08-28 02:36:36 +04:00
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfWord ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 4 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 11 ]
expect ( cursor3 . getBufferPosition ( ) ) . toEqual [ 2 , 39 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " does not fail at position [0, 0] " , ->
editor . setCursorBufferPosition ( [ 0 , 0 ] )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfWord ( )
2014-03-06 08:32:11 +04:00
it " treats lines with only whitespace as a word " , ->
editor . setCursorBufferPosition ( [ 11 , 0 ] )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 10 , 0 ]
2015-12-03 21:30:09 +03:00
it " treats lines with only whitespace as a word (CRLF line ending) " , ->
editor . buffer . setText ( buffer . getText ( ) . replace ( /\n/g , " \r \n " ) )
editor . setCursorBufferPosition ( [ 11 , 0 ] )
editor . moveToBeginningOfWord ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 10 , 0 ]
2015-12-03 22:52:45 +03:00
2014-03-06 08:32:11 +04:00
it " works when the current line is blank " , ->
editor . setCursorBufferPosition ( [ 10 , 0 ] )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 9 , 2 ]
2015-12-03 21:30:09 +03:00
it " works when the current line is blank (CRLF line ending) " , ->
editor . buffer . setText ( buffer . getText ( ) . replace ( /\n/g , " \r \n " ) )
editor . setCursorBufferPosition ( [ 10 , 0 ] )
editor . moveToBeginningOfWord ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 9 , 2 ]
editor . buffer . setText ( buffer . getText ( ) . replace ( /\r\n/g , " \n " ) )
2014-08-29 02:25:12 +04:00
describe " .moveToPreviousWordBoundary() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor to the previous word boundary " , ->
editor . setCursorBufferPosition [ 0 , 8 ]
editor . addCursorAtBufferPosition [ 2 , 0 ]
editor . addCursorAtBufferPosition [ 2 , 4 ]
editor . addCursorAtBufferPosition [ 3 , 14 ]
[ cursor1 , cursor2 , cursor3 , cursor4 ] = editor . getCursors ( )
2014-08-29 02:25:12 +04:00
editor . moveToPreviousWordBoundary ( )
2014-03-06 08:32:11 +04:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 4 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 30 ]
expect ( cursor3 . getBufferPosition ( ) ) . toEqual [ 2 , 0 ]
expect ( cursor4 . getBufferPosition ( ) ) . toEqual [ 3 , 13 ]
2014-08-29 02:25:12 +04:00
describe " .moveToNextWordBoundary() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor to the previous word boundary " , ->
editor . setCursorBufferPosition [ 0 , 8 ]
editor . addCursorAtBufferPosition [ 2 , 40 ]
editor . addCursorAtBufferPosition [ 3 , 0 ]
editor . addCursorAtBufferPosition [ 3 , 30 ]
[ cursor1 , cursor2 , cursor3 , cursor4 ] = editor . getCursors ( )
2014-08-29 02:25:12 +04:00
editor . moveToNextWordBoundary ( )
2014-03-06 08:32:11 +04:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 13 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 3 , 0 ]
expect ( cursor3 . getBufferPosition ( ) ) . toEqual [ 3 , 4 ]
expect ( cursor4 . getBufferPosition ( ) ) . toEqual [ 3 , 31 ]
2014-08-29 02:25:12 +04:00
describe " .moveToEndOfWord() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor to the end of the word " , ->
editor . setCursorBufferPosition [ 0 , 6 ]
editor . addCursorAtBufferPosition [ 1 , 10 ]
editor . addCursorAtBufferPosition [ 2 , 40 ]
[ cursor1 , cursor2 , cursor3 ] = editor . getCursors ( )
2014-08-29 02:25:12 +04:00
editor . moveToEndOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 13 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 12 ]
expect ( cursor3 . getBufferPosition ( ) ) . toEqual [ 3 , 7 ]
it " does not blow up when there is no next word " , ->
editor . setCursorBufferPosition [ Infinity , Infinity ]
endPosition = editor . getCursorBufferPosition ( )
2014-08-29 02:25:12 +04:00
editor . moveToEndOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual endPosition
it " treats lines with only whitespace as a word " , ->
editor . setCursorBufferPosition ( [ 9 , 4 ] )
2014-08-29 02:25:12 +04:00
editor . moveToEndOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 10 , 0 ]
2015-12-03 21:30:09 +03:00
it " treats lines with only whitespace as a word (CRLF line ending) " , ->
editor . buffer . setText ( buffer . getText ( ) . replace ( /\n/g , " \r \n " ) )
editor . setCursorBufferPosition ( [ 9 , 4 ] )
editor . moveToEndOfWord ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 10 , 0 ]
2014-03-06 08:32:11 +04:00
it " works when the current line is blank " , ->
editor . setCursorBufferPosition ( [ 10 , 0 ] )
2014-08-29 02:25:12 +04:00
editor . moveToEndOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 11 , 8 ]
2015-12-03 21:30:09 +03:00
it " works when the current line is blank (CRLF line ending) " , ->
editor . buffer . setText ( buffer . getText ( ) . replace ( /\n/g , " \r \n " ) )
editor . setCursorBufferPosition ( [ 10 , 0 ] )
editor . moveToEndOfWord ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 11 , 8 ]
2014-08-29 02:25:12 +04:00
describe " .moveToBeginningOfNextWord() " , ->
2014-03-06 08:32:11 +04:00
it " moves the cursor before the first character of the next word " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorBufferPosition [ 0 , 6 ]
editor . addCursorAtBufferPosition [ 1 , 11 ]
editor . addCursorAtBufferPosition [ 2 , 0 ]
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 , cursor3 ] = editor . getCursors ( )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfNextWord ( )
2014-03-06 08:32:11 +04:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 14 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 13 ]
expect ( cursor3 . getBufferPosition ( ) ) . toEqual [ 2 , 4 ]
# When the cursor is on whitespace
editor . setText ( " ab cde- " )
2015-05-23 02:50:04 +03:00
editor . setCursorBufferPosition [ 0 , 2 ]
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfNextWord ( )
2014-03-06 08:32:11 +04:00
expect ( cursor . getBufferPosition ( ) ) . toEqual [ 0 , 3 ]
it " does not blow up when there is no next word " , ->
editor . setCursorBufferPosition [ Infinity , Infinity ]
endPosition = editor . getCursorBufferPosition ( )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfNextWord ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual endPosition
it " treats lines with only whitespace as a word " , ->
editor . setCursorBufferPosition ( [ 9 , 4 ] )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfNextWord ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 10 , 0 ]
it " works when the current line is blank " , ->
editor . setCursorBufferPosition ( [ 10 , 0 ] )
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfNextWord ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 11 , 9 ]
2015-11-04 00:17:58 +03:00
describe " .moveToPreviousSubwordBoundary " , ->
it " does not move the cursor when there is no previous subword boundary " , ->
editor . setText ( ' ' )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 0 ] )
it " stops at word and underscore boundaries " , ->
editor . setText ( " sub_word \n " )
editor . setCursorBufferPosition ( [ 0 , 9 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 8 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 4 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 0 ] )
editor . setText ( " word \n " )
editor . setCursorBufferPosition ( [ 0 , 3 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
it " stops at camelCase boundaries " , ->
editor . setText ( " getPreviousWord \n " )
editor . setCursorBufferPosition ( [ 0 , 16 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 12 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 4 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
it " skips consecutive non-word characters " , ->
editor . setText ( " e, => \n " )
editor . setCursorBufferPosition ( [ 0 , 6 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 3 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
it " skips consecutive uppercase characters " , ->
editor . setText ( " AAADF \n " )
editor . setCursorBufferPosition ( [ 0 , 7 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 6 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
editor . setText ( " ALPhA \n " )
editor . setCursorBufferPosition ( [ 0 , 4 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 2 ] )
it " skips consecutive numbers " , ->
editor . setText ( " 88 \n " )
editor . setCursorBufferPosition ( [ 0 , 4 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 3 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
it " works with multiple cursors " , ->
editor . setText ( " curOp \n cursorOptions \n " )
editor . setCursorBufferPosition ( [ 0 , 8 ] )
editor . addCursorAtBufferPosition ( [ 1 , 13 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
editor . moveToPreviousSubwordBoundary ( )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual ( [ 0 , 3 ] )
expect ( cursor2 . getBufferPosition ( ) ) . toEqual ( [ 1 , 6 ] )
it " works with non-English characters " , ->
editor . setText ( " supåTøåst \n " )
editor . setCursorBufferPosition ( [ 0 , 9 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 4 ] )
editor . setText ( " supaÖast \n " )
editor . setCursorBufferPosition ( [ 0 , 8 ] )
editor . moveToPreviousSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 4 ] )
describe " .moveToNextSubwordBoundary " , ->
it " does not move the cursor when there is no next subword boundary " , ->
editor . setText ( ' ' )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 0 ] )
it " stops at word and underscore boundaries " , ->
editor . setText ( " sub_word \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 4 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 9 ] )
editor . setText ( " word \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 4 ] )
it " stops at camelCase boundaries " , ->
editor . setText ( " getPreviousWord \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 3 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 11 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 15 ] )
it " skips consecutive non-word characters " , ->
editor . setText ( " , => \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 4 ] )
it " skips consecutive uppercase characters " , ->
editor . setText ( " AAADF \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 6 ] )
editor . setText ( " ALPhA \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 2 ] )
it " skips consecutive numbers " , ->
editor . setText ( " 88 \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 3 ] )
it " works with multiple cursors " , ->
editor . setText ( " curOp \n cursorOptions \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . addCursorAtBufferPosition ( [ 1 , 0 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
editor . moveToNextSubwordBoundary ( )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual ( [ 0 , 3 ] )
expect ( cursor2 . getBufferPosition ( ) ) . toEqual ( [ 1 , 6 ] )
it " works with non-English characters " , ->
editor . setText ( " supåTøåst \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 4 ] )
editor . setText ( " supaÖast \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveToNextSubwordBoundary ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 0 , 4 ] )
2014-08-29 02:25:12 +04:00
describe " .moveToBeginningOfNextParagraph() " , ->
2014-05-23 08:51:01 +04:00
it " moves the cursor before the first line of the next paragraph " , ->
2015-04-03 20:34:21 +03:00
editor . setCursorBufferPosition [ 0 , 6 ]
editor . foldBufferRow ( 4 )
2014-05-23 08:51:01 +04:00
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfNextParagraph ( )
2015-04-03 20:34:21 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 10 , 0 ]
2014-05-23 08:51:01 +04:00
editor . setText ( " " )
2015-04-03 20:34:21 +03:00
editor . setCursorBufferPosition [ 0 , 0 ]
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfNextParagraph ( )
2015-04-03 20:34:21 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
2014-05-23 08:51:01 +04:00
2015-12-03 23:07:15 +03:00
it " moves the cursor before the first line of the next paragraph (CRLF line endings) " , ->
editor . setText ( editor . getText ( ) . replace ( /\n/g , ' \r \n ' ) )
editor . setCursorBufferPosition [ 0 , 6 ]
editor . foldBufferRow ( 4 )
editor . moveToBeginningOfNextParagraph ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 10 , 0 ]
editor . setText ( " " )
editor . setCursorBufferPosition [ 0 , 0 ]
editor . moveToBeginningOfNextParagraph ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
2014-08-29 02:25:12 +04:00
describe " .moveToBeginningOfPreviousParagraph() " , ->
2015-12-03 23:07:15 +03:00
it " moves the cursor before the first line of the previous paragraph " , ->
editor . setCursorBufferPosition [ 10 , 0 ]
editor . foldBufferRow ( 4 )
editor . moveToBeginningOfPreviousParagraph ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
editor . setText ( " " )
editor . setCursorBufferPosition [ 0 , 0 ]
editor . moveToBeginningOfPreviousParagraph ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
it " moves the cursor before the first line of the previous paragraph (CRLF line endings) " , ->
editor . setText ( editor . getText ( ) . replace ( /\n/g , ' \r \n ' ) )
2015-04-03 20:34:21 +03:00
editor . setCursorBufferPosition [ 10 , 0 ]
editor . foldBufferRow ( 4 )
2014-05-23 08:51:01 +04:00
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfPreviousParagraph ( )
2015-04-03 20:34:21 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
2014-05-23 08:51:01 +04:00
editor . setText ( " " )
2015-04-03 20:34:21 +03:00
editor . setCursorBufferPosition [ 0 , 0 ]
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfPreviousParagraph ( )
2015-04-03 20:34:21 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
2014-05-23 08:51:01 +04:00
2014-03-06 08:32:11 +04:00
describe " .getCurrentParagraphBufferRange() " , ->
it " returns the buffer range of the current paragraph, delimited by blank lines or the beginning / end of the file " , ->
buffer . setText """
I am the first paragraph ,
bordered by the beginning of
the file
#{' '}
I am the second paragraph
with blank lines above and below
me .
I am the last paragraph ,
bordered by the end of the file .
"""
# in a paragraph
editor . setCursorBufferPosition ( [ 1 , 7 ] )
expect ( editor . getCurrentParagraphBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 2 , 8 ] ]
editor . setCursorBufferPosition ( [ 7 , 1 ] )
expect ( editor . getCurrentParagraphBufferRange ( ) ) . toEqual [ [ 5 , 0 ] , [ 7 , 3 ] ]
editor . setCursorBufferPosition ( [ 9 , 10 ] )
expect ( editor . getCurrentParagraphBufferRange ( ) ) . toEqual [ [ 9 , 0 ] , [ 10 , 32 ] ]
# between paragraphs
editor . setCursorBufferPosition ( [ 3 , 1 ] )
expect ( editor . getCurrentParagraphBufferRange ( ) ) . toBeUndefined ( )
2015-06-11 14:02:14 +03:00
describe " getCursorAtScreenPosition(screenPosition) " , ->
it " returns the cursor at the given screenPosition " , ->
cursor1 = editor . addCursorAtScreenPosition ( [ 0 , 2 ] )
cursor2 = editor . getCursorAtScreenPosition ( cursor1 . getScreenPosition ( ) )
2015-06-12 20:21:37 +03:00
expect ( cursor2 ) . toBe cursor1
2015-06-11 14:02:14 +03:00
2014-08-29 03:06:44 +04:00
describe " ::getCursorScreenPositions() " , ->
2014-09-03 01:38:11 +04:00
it " returns the cursor positions in the order they were added " , ->
2014-08-29 03:06:44 +04:00
editor . foldBufferRow ( 4 )
cursor1 = editor . addCursorAtBufferPosition ( [ 8 , 5 ] )
cursor2 = editor . addCursorAtBufferPosition ( [ 3 , 5 ] )
2014-09-03 01:38:11 +04:00
expect ( editor . getCursorScreenPositions ( ) ) . toEqual [ [ 0 , 0 ] , [ 5 , 5 ] , [ 3 , 5 ] ]
2014-08-29 03:06:44 +04:00
describe " ::getCursorsOrderedByBufferPosition() " , ->
it " returns all cursors ordered by buffer positions " , ->
2014-08-29 05:10:18 +04:00
originalCursor = editor . getLastCursor ( )
2014-08-29 03:06:44 +04:00
cursor1 = editor . addCursorAtBufferPosition ( [ 8 , 5 ] )
cursor2 = editor . addCursorAtBufferPosition ( [ 4 , 5 ] )
expect ( editor . getCursorsOrderedByBufferPosition ( ) ) . toEqual [ originalCursor , cursor2 , cursor1 ]
2014-03-06 08:32:11 +04:00
describe " addCursorAtScreenPosition(screenPosition) " , ->
describe " when a cursor already exists at the position " , ->
it " returns the existing cursor " , ->
2015-05-23 02:50:04 +03:00
cursor1 = editor . addCursorAtScreenPosition ( [ 0 , 2 ] )
cursor2 = editor . addCursorAtScreenPosition ( [ 0 , 2 ] )
2015-06-12 09:37:40 +03:00
expect ( cursor2 ) . toBe cursor1
2014-03-06 08:32:11 +04:00
describe " addCursorAtBufferPosition(bufferPosition) " , ->
describe " when a cursor already exists at the position " , ->
it " returns the existing cursor " , ->
2015-05-23 02:50:04 +03:00
cursor1 = editor . addCursorAtBufferPosition ( [ 1 , 4 ] )
cursor2 = editor . addCursorAtBufferPosition ( [ 1 , 4 ] )
2014-03-06 08:32:11 +04:00
expect ( cursor2 . marker ) . toBe cursor1 . marker
2016-04-25 21:12:42 +03:00
describe ' .getCursorScope() ' , ->
it ' returns the current scope ' , ->
descriptor = editor . getCursorScope ( )
2016-04-25 21:20:54 +03:00
expect ( descriptor . scopes ) . toContain ( ' source.js ' )
2015-01-10 03:33:48 +03:00
2014-03-06 08:32:11 +04:00
describe " selection " , ->
selection = null
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
beforeEach ->
2014-08-29 04:51:16 +04:00
selection = editor . getLastSelection ( )
2014-03-06 08:32:11 +04:00
2015-08-27 02:59:19 +03:00
describe " .getLastSelection() " , ->
it " creates a new selection at (0, 0) if the last selection has been destroyed " , ->
editor . getLastSelection ( ) . destroy ( )
expect ( editor . getLastSelection ( ) . getBufferRange ( ) ) . toEqual ( [ [ 0 , 0 ] , [ 0 , 0 ] ] )
2017-01-24 14:18:09 +03:00
it " doesn ' t get stuck in a infinite loop when called from ::onDidAddCursor after the last selection has been destroyed (regression) " , ->
callCount = 0
editor . getLastSelection ( ) . destroy ( )
editor . onDidAddCursor (cursor) ->
callCount ++
editor . getLastSelection ( )
expect ( editor . getLastSelection ( ) . getBufferRange ( ) ) . toEqual ( [ [ 0 , 0 ] , [ 0 , 0 ] ] )
expect ( callCount ) . toBe ( 1 )
2015-08-27 02:59:19 +03:00
describe " .getSelections() " , ->
it " creates a new selection at (0, 0) if the last selection has been destroyed " , ->
editor . getLastSelection ( ) . destroy ( )
expect ( editor . getSelections ( ) [ 0 ] . getBufferRange ( ) ) . toEqual ( [ [ 0 , 0 ] , [ 0 , 0 ] ] )
2014-09-23 03:08:12 +04:00
describe " when the selection range changes " , ->
it " emits an event with the old range, new range, and the selection that moved " , ->
editor . setSelectedBufferRange ( [ [ 3 , 0 ] , [ 4 , 5 ] ] )
editor . onDidChangeSelectionRange rangeChangedHandler = jasmine . createSpy ( )
editor . selectToBufferPosition ( [ 6 , 2 ] )
expect ( rangeChangedHandler ) . toHaveBeenCalled ( )
eventObject = rangeChangedHandler . mostRecentCall . args [ 0 ]
expect ( eventObject . oldBufferRange ) . toEqual [ [ 3 , 0 ] , [ 4 , 5 ] ]
expect ( eventObject . oldScreenRange ) . toEqual [ [ 3 , 0 ] , [ 4 , 5 ] ]
expect ( eventObject . newBufferRange ) . toEqual [ [ 3 , 0 ] , [ 6 , 2 ] ]
expect ( eventObject . newScreenRange ) . toEqual [ [ 3 , 0 ] , [ 6 , 2 ] ]
expect ( eventObject . selection ) . toBe selection
2014-03-06 08:32:11 +04:00
describe " .selectUp/Down/Left/Right() " , ->
it " expands each selection to its cursor ' s new location " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 9 ] , [ 0 , 13 ] ] , [ [ 3 , 16 ] , [ 3 , 21 ] ] ] )
2014-03-06 08:32:11 +04:00
[ selection1 , selection2 ] = editor . getSelections ( )
editor . selectRight ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 9 ] , [ 0 , 14 ] ]
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 16 ] , [ 3 , 22 ] ]
2014-03-06 08:32:11 +04:00
editor . selectLeft ( )
editor . selectLeft ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 9 ] , [ 0 , 12 ] ]
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 16 ] , [ 3 , 20 ] ]
2014-03-06 08:32:11 +04:00
editor . selectDown ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 9 ] , [ 1 , 12 ] ]
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 16 ] , [ 4 , 20 ] ]
2014-03-06 08:32:11 +04:00
editor . selectUp ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 9 ] , [ 0 , 12 ] ]
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 16 ] , [ 3 , 20 ] ]
2014-03-06 08:32:11 +04:00
it " merges selections when they intersect when moving down " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 9 ] , [ 0 , 13 ] ] , [ [ 1 , 10 ] , [ 1 , 20 ] ] , [ [ 2 , 15 ] , [ 3 , 25 ] ] ] )
2014-03-06 08:32:11 +04:00
[ selection1 , selection2 , selection3 ] = editor . getSelections ( )
editor . selectDown ( )
expect ( editor . getSelections ( ) ) . toEqual [ selection1 ]
expect ( selection1 . getScreenRange ( ) ) . toEqual ( [ [ 0 , 9 ] , [ 4 , 25 ] ] )
expect ( selection1 . isReversed ( ) ) . toBeFalsy ( )
it " merges selections when they intersect when moving up " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 9 ] , [ 0 , 13 ] ] , [ [ 1 , 10 ] , [ 1 , 20 ] ] ] , reversed: true )
2014-03-06 08:32:11 +04:00
[ selection1 , selection2 ] = editor . getSelections ( )
editor . selectUp ( )
expect ( editor . getSelections ( ) . length ) . toBe 1
expect ( editor . getSelections ( ) ) . toEqual [ selection1 ]
expect ( selection1 . getScreenRange ( ) ) . toEqual ( [ [ 0 , 0 ] , [ 1 , 20 ] ] )
expect ( selection1 . isReversed ( ) ) . toBeTruthy ( )
it " merges selections when they intersect when moving left " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 9 ] , [ 0 , 13 ] ] , [ [ 0 , 13 ] , [ 1 , 20 ] ] ] , reversed: true )
2014-03-06 08:32:11 +04:00
[ selection1 , selection2 ] = editor . getSelections ( )
editor . selectLeft ( )
expect ( editor . getSelections ( ) ) . toEqual [ selection1 ]
expect ( selection1 . getScreenRange ( ) ) . toEqual ( [ [ 0 , 8 ] , [ 1 , 20 ] ] )
expect ( selection1 . isReversed ( ) ) . toBeTruthy ( )
it " merges selections when they intersect when moving right " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 9 ] , [ 0 , 14 ] ] , [ [ 0 , 14 ] , [ 1 , 20 ] ] ] )
2014-03-06 08:32:11 +04:00
[ selection1 , selection2 ] = editor . getSelections ( )
editor . selectRight ( )
expect ( editor . getSelections ( ) ) . toEqual [ selection1 ]
expect ( selection1 . getScreenRange ( ) ) . toEqual ( [ [ 0 , 9 ] , [ 1 , 21 ] ] )
expect ( selection1 . isReversed ( ) ) . toBeFalsy ( )
2014-09-04 03:20:25 +04:00
describe " when counts are passed into the selection functions " , ->
it " expands each selection to its cursor ' s new location " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 9 ] , [ 0 , 13 ] ] , [ [ 3 , 16 ] , [ 3 , 21 ] ] ] )
2014-09-04 03:20:25 +04:00
[ selection1 , selection2 ] = editor . getSelections ( )
editor . selectRight ( 2 )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 9 ] , [ 0 , 15 ] ]
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 16 ] , [ 3 , 23 ] ]
2014-09-04 03:20:25 +04:00
editor . selectLeft ( 3 )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 9 ] , [ 0 , 12 ] ]
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 16 ] , [ 3 , 20 ] ]
2014-09-04 03:20:25 +04:00
editor . selectDown ( 3 )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 9 ] , [ 3 , 12 ] ]
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 16 ] , [ 6 , 20 ] ]
2014-09-04 03:20:25 +04:00
editor . selectUp ( 2 )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 9 ] , [ 1 , 12 ] ]
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 16 ] , [ 4 , 20 ] ]
2014-09-04 03:20:25 +04:00
2014-09-03 01:09:56 +04:00
describe " .selectToBufferPosition(bufferPosition) " , ->
it " expands the last selection to the given position " , ->
editor . setSelectedBufferRange ( [ [ 3 , 0 ] , [ 4 , 5 ] ] )
editor . addCursorAtBufferPosition ( [ 5 , 6 ] )
editor . selectToBufferPosition ( [ 6 , 2 ] )
selections = editor . getSelections ( )
expect ( selections . length ) . toBe 2
[ selection1 , selection2 ] = selections
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 3 , 0 ] , [ 4 , 5 ] ]
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 5 , 6 ] , [ 6 , 2 ] ]
2014-03-06 08:32:11 +04:00
describe " .selectToScreenPosition(screenPosition) " , ->
it " expands the last selection to the given position " , ->
editor . setSelectedBufferRange ( [ [ 3 , 0 ] , [ 4 , 5 ] ] )
editor . addCursorAtScreenPosition ( [ 5 , 6 ] )
editor . selectToScreenPosition ( [ 6 , 2 ] )
selections = editor . getSelections ( )
expect ( selections . length ) . toBe 2
[ selection1 , selection2 ] = selections
expect ( selection1 . getScreenRange ( ) ) . toEqual [ [ 3 , 0 ] , [ 4 , 5 ] ]
expect ( selection2 . getScreenRange ( ) ) . toEqual [ [ 5 , 6 ] , [ 6 , 2 ] ]
2015-07-29 20:48:33 +03:00
describe " when selecting with an initial screen range " , ->
it " switches the direction of the selection when selecting to positions before/after the start of the initial range " , ->
editor . setCursorScreenPosition ( [ 5 , 10 ] )
editor . selectWordsContainingCursors ( )
editor . selectToScreenPosition ( [ 3 , 0 ] )
expect ( editor . getLastSelection ( ) . isReversed ( ) ) . toBe true
editor . selectToScreenPosition ( [ 9 , 0 ] )
expect ( editor . getLastSelection ( ) . isReversed ( ) ) . toBe false
2014-06-06 16:40:15 +04:00
describe " .selectToBeginningOfNextParagraph() " , ->
2014-06-06 16:37:59 +04:00
it " selects from the cursor to first line of the next paragraph " , ->
editor . setSelectedBufferRange ( [ [ 3 , 0 ] , [ 4 , 5 ] ] )
editor . addCursorAtScreenPosition ( [ 5 , 6 ] )
editor . selectToScreenPosition ( [ 6 , 2 ] )
editor . selectToBeginningOfNextParagraph ( )
selections = editor . getSelections ( )
expect ( selections . length ) . toBe 1
expect ( selections [ 0 ] . getScreenRange ( ) ) . toEqual [ [ 3 , 0 ] , [ 10 , 0 ] ]
2014-06-06 16:40:15 +04:00
describe " .selectToBeginningOfPreviousParagraph() " , ->
2014-06-06 16:37:59 +04:00
it " selects from the cursor to the first line of the pevious paragraph " , ->
editor . setSelectedBufferRange ( [ [ 3 , 0 ] , [ 4 , 5 ] ] )
editor . addCursorAtScreenPosition ( [ 5 , 6 ] )
editor . selectToScreenPosition ( [ 6 , 2 ] )
editor . selectToBeginningOfPreviousParagraph ( )
selections = editor . getSelections ( )
expect ( selections . length ) . toBe 1
expect ( selections [ 0 ] . getScreenRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 5 , 6 ] ]
2014-03-06 08:32:11 +04:00
it " merges selections if they intersect, maintaining the directionality of the last selection " , ->
editor . setCursorScreenPosition ( [ 4 , 10 ] )
editor . selectToScreenPosition ( [ 5 , 27 ] )
editor . addCursorAtScreenPosition ( [ 3 , 10 ] )
editor . selectToScreenPosition ( [ 6 , 27 ] )
selections = editor . getSelections ( )
expect ( selections . length ) . toBe 1
[ selection1 ] = selections
expect ( selection1 . getScreenRange ( ) ) . toEqual [ [ 3 , 10 ] , [ 6 , 27 ] ]
expect ( selection1 . isReversed ( ) ) . toBeFalsy ( )
editor . addCursorAtScreenPosition ( [ 7 , 4 ] )
editor . selectToScreenPosition ( [ 4 , 11 ] )
selections = editor . getSelections ( )
expect ( selections . length ) . toBe 1
[ selection1 ] = selections
expect ( selection1 . getScreenRange ( ) ) . toEqual [ [ 3 , 10 ] , [ 7 , 4 ] ]
expect ( selection1 . isReversed ( ) ) . toBeTruthy ( )
describe " .selectToTop() " , ->
it " selects text from cusor position to the top of the buffer " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 11 , 2 ]
editor . addCursorAtScreenPosition [ 10 , 0 ]
2014-03-06 08:32:11 +04:00
editor . selectToTop ( )
expect ( editor . getCursors ( ) . length ) . toBe 1
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
expect ( editor . getLastSelection ( ) . getBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 11 , 2 ] ]
2014-08-29 04:51:16 +04:00
expect ( editor . getLastSelection ( ) . isReversed ( ) ) . toBeTruthy ( )
2014-03-06 08:32:11 +04:00
describe " .selectToBottom() " , ->
it " selects text from cusor position to the bottom of the buffer " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 10 , 0 ]
editor . addCursorAtScreenPosition [ 9 , 3 ]
2014-03-06 08:32:11 +04:00
editor . selectToBottom ( )
expect ( editor . getCursors ( ) . length ) . toBe 1
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 12 , 2 ]
expect ( editor . getLastSelection ( ) . getBufferRange ( ) ) . toEqual [ [ 9 , 3 ] , [ 12 , 2 ] ]
2014-08-29 04:51:16 +04:00
expect ( editor . getLastSelection ( ) . isReversed ( ) ) . toBeFalsy ( )
2014-03-06 08:32:11 +04:00
describe " .selectAll() " , ->
it " selects the entire buffer " , ->
editor . selectAll ( )
2014-08-29 04:51:16 +04:00
expect ( editor . getLastSelection ( ) . getBufferRange ( ) ) . toEqual buffer . getRange ( )
2014-03-06 08:32:11 +04:00
describe " .selectToBeginningOfLine() " , ->
it " selects text from cusor position to beginning of line " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 12 , 2 ]
editor . addCursorAtScreenPosition [ 11 , 3 ]
2014-03-06 08:32:11 +04:00
editor . selectToBeginningOfLine ( )
expect ( editor . getCursors ( ) . length ) . toBe 2
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 12 , 0 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 11 , 0 ]
2014-03-06 08:32:11 +04:00
expect ( editor . getSelections ( ) . length ) . toBe 2
[ selection1 , selection2 ] = editor . getSelections ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 12 , 0 ] , [ 12 , 2 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection1 . isReversed ( ) ) . toBeTruthy ( )
2015-05-23 02:50:04 +03:00
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 11 , 0 ] , [ 11 , 3 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection2 . isReversed ( ) ) . toBeTruthy ( )
describe " .selectToEndOfLine() " , ->
it " selects text from cusor position to end of line " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 12 , 0 ]
editor . addCursorAtScreenPosition [ 11 , 3 ]
2014-03-06 08:32:11 +04:00
editor . selectToEndOfLine ( )
expect ( editor . getCursors ( ) . length ) . toBe 2
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 12 , 2 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 11 , 44 ]
2014-03-06 08:32:11 +04:00
expect ( editor . getSelections ( ) . length ) . toBe 2
[ selection1 , selection2 ] = editor . getSelections ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 12 , 0 ] , [ 12 , 2 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection1 . isReversed ( ) ) . toBeFalsy ( )
2015-05-23 02:50:04 +03:00
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 11 , 3 ] , [ 11 , 44 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection2 . isReversed ( ) ) . toBeFalsy ( )
2014-09-03 00:59:48 +04:00
describe " .selectLinesContainingCursors() " , ->
2015-09-03 17:25:24 +03:00
it " selects to the entire line (including newlines) at given row " , ->
2014-03-06 08:32:11 +04:00
editor . setCursorScreenPosition ( [ 1 , 2 ] )
2014-09-03 00:59:48 +04:00
editor . selectLinesContainingCursors ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 1 , 0 ] , [ 2 , 0 ] ]
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedText ( ) ) . toBe " var sort = function(items) { \n "
editor . setCursorScreenPosition ( [ 12 , 2 ] )
2014-09-03 00:59:48 +04:00
editor . selectLinesContainingCursors ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 12 , 0 ] , [ 12 , 2 ] ]
2014-03-06 08:32:11 +04:00
editor . setCursorBufferPosition ( [ 0 , 2 ] )
2014-09-03 00:59:48 +04:00
editor . selectLinesContainingCursors ( )
editor . selectLinesContainingCursors ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 2 , 0 ] ]
2014-03-06 08:32:11 +04:00
2015-09-03 17:25:24 +03:00
describe " when the selection spans multiple row " , ->
it " selects from the beginning of the first line to the last line " , ->
2015-09-03 03:03:18 +03:00
selection = editor . getLastSelection ( )
selection . setBufferRange [ [ 1 , 10 ] , [ 3 , 20 ] ]
editor . selectLinesContainingCursors ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 1 , 0 ] , [ 4 , 0 ] ]
2014-11-11 01:49:46 +03:00
2014-03-06 08:32:11 +04:00
describe " .selectToBeginningOfWord() " , ->
it " selects text from cusor position to beginning of word " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 0 , 13 ]
editor . addCursorAtScreenPosition [ 3 , 49 ]
2014-03-06 08:32:11 +04:00
editor . selectToBeginningOfWord ( )
expect ( editor . getCursors ( ) . length ) . toBe 2
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 4 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 3 , 47 ]
2014-03-06 08:32:11 +04:00
expect ( editor . getSelections ( ) . length ) . toBe 2
[ selection1 , selection2 ] = editor . getSelections ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 4 ] , [ 0 , 13 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection1 . isReversed ( ) ) . toBeTruthy ( )
2015-05-23 02:50:04 +03:00
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 47 ] , [ 3 , 49 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection2 . isReversed ( ) ) . toBeTruthy ( )
describe " .selectToEndOfWord() " , ->
it " selects text from cusor position to end of word " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 0 , 4 ]
editor . addCursorAtScreenPosition [ 3 , 48 ]
2014-03-06 08:32:11 +04:00
editor . selectToEndOfWord ( )
expect ( editor . getCursors ( ) . length ) . toBe 2
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 13 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 3 , 50 ]
2014-03-06 08:32:11 +04:00
expect ( editor . getSelections ( ) . length ) . toBe 2
[ selection1 , selection2 ] = editor . getSelections ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 4 ] , [ 0 , 13 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection1 . isReversed ( ) ) . toBeFalsy ( )
2015-05-23 02:50:04 +03:00
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 48 ] , [ 3 , 50 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection2 . isReversed ( ) ) . toBeFalsy ( )
describe " .selectToBeginningOfNextWord() " , ->
it " selects text from cusor position to beginning of next word " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 0 , 4 ]
editor . addCursorAtScreenPosition [ 3 , 48 ]
2014-03-06 08:32:11 +04:00
editor . selectToBeginningOfNextWord ( )
expect ( editor . getCursors ( ) . length ) . toBe 2
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 14 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 3 , 51 ]
2014-03-06 08:32:11 +04:00
expect ( editor . getSelections ( ) . length ) . toBe 2
[ selection1 , selection2 ] = editor . getSelections ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 4 ] , [ 0 , 14 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection1 . isReversed ( ) ) . toBeFalsy ( )
2015-05-23 02:50:04 +03:00
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 3 , 48 ] , [ 3 , 51 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection2 . isReversed ( ) ) . toBeFalsy ( )
describe " .selectToPreviousWordBoundary() " , ->
it " select to the previous word boundary " , ->
editor . setCursorBufferPosition [ 0 , 8 ]
editor . addCursorAtBufferPosition [ 2 , 0 ]
editor . addCursorAtBufferPosition [ 3 , 4 ]
editor . addCursorAtBufferPosition [ 3 , 14 ]
editor . selectToPreviousWordBoundary ( )
expect ( editor . getSelections ( ) . length ) . toBe 4
[ selection1 , selection2 , selection3 , selection4 ] = editor . getSelections ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 8 ] , [ 0 , 4 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection1 . isReversed ( ) ) . toBeTruthy ( )
2015-05-23 02:50:04 +03:00
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 2 , 0 ] , [ 1 , 30 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection2 . isReversed ( ) ) . toBeTruthy ( )
2015-05-23 02:50:04 +03:00
expect ( selection3 . getBufferRange ( ) ) . toEqual [ [ 3 , 4 ] , [ 3 , 0 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection3 . isReversed ( ) ) . toBeTruthy ( )
2015-05-23 02:50:04 +03:00
expect ( selection4 . getBufferRange ( ) ) . toEqual [ [ 3 , 14 ] , [ 3 , 13 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection4 . isReversed ( ) ) . toBeTruthy ( )
describe " .selectToNextWordBoundary() " , ->
it " select to the next word boundary " , ->
editor . setCursorBufferPosition [ 0 , 8 ]
editor . addCursorAtBufferPosition [ 2 , 40 ]
editor . addCursorAtBufferPosition [ 4 , 0 ]
editor . addCursorAtBufferPosition [ 3 , 30 ]
editor . selectToNextWordBoundary ( )
expect ( editor . getSelections ( ) . length ) . toBe 4
[ selection1 , selection2 , selection3 , selection4 ] = editor . getSelections ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 8 ] , [ 0 , 13 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection1 . isReversed ( ) ) . toBeFalsy ( )
2015-05-23 02:50:04 +03:00
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 2 , 40 ] , [ 3 , 0 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection2 . isReversed ( ) ) . toBeFalsy ( )
2015-05-23 02:50:04 +03:00
expect ( selection3 . getBufferRange ( ) ) . toEqual [ [ 4 , 0 ] , [ 4 , 4 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection3 . isReversed ( ) ) . toBeFalsy ( )
2015-05-23 02:50:04 +03:00
expect ( selection4 . getBufferRange ( ) ) . toEqual [ [ 3 , 30 ] , [ 3 , 31 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection4 . isReversed ( ) ) . toBeFalsy ( )
2015-11-04 00:17:58 +03:00
describe " .selectToPreviousSubwordBoundary " , ->
it " selects subwords " , ->
editor . setText ( " " )
editor . insertText ( " _word \n " )
editor . insertText ( " getPreviousWord \n " )
editor . insertText ( " e, => \n " )
editor . insertText ( " 88 \n " )
editor . setCursorBufferPosition ( [ 0 , 5 ] )
editor . addCursorAtBufferPosition ( [ 1 , 7 ] )
editor . addCursorAtBufferPosition ( [ 2 , 5 ] )
editor . addCursorAtBufferPosition ( [ 3 , 3 ] )
[ selection1 , selection2 , selection3 , selection4 ] = editor . getSelections ( )
editor . selectToPreviousSubwordBoundary ( )
expect ( selection1 . getBufferRange ( ) ) . toEqual ( [ [ 0 , 1 ] , [ 0 , 5 ] ] )
expect ( selection1 . isReversed ( ) ) . toBeTruthy ( )
expect ( selection2 . getBufferRange ( ) ) . toEqual ( [ [ 1 , 4 ] , [ 1 , 7 ] ] )
expect ( selection2 . isReversed ( ) ) . toBeTruthy ( )
expect ( selection3 . getBufferRange ( ) ) . toEqual ( [ [ 2 , 3 ] , [ 2 , 5 ] ] )
expect ( selection3 . isReversed ( ) ) . toBeTruthy ( )
expect ( selection4 . getBufferRange ( ) ) . toEqual ( [ [ 3 , 1 ] , [ 3 , 3 ] ] )
expect ( selection4 . isReversed ( ) ) . toBeTruthy ( )
describe " .selectToNextSubwordBoundary " , ->
it " selects subwords " , ->
editor . setText ( " " )
editor . insertText ( " word_ \n " )
editor . insertText ( " getPreviousWord \n " )
editor . insertText ( " e, => \n " )
editor . insertText ( " 88 \n " )
editor . setCursorBufferPosition ( [ 0 , 1 ] )
editor . addCursorAtBufferPosition ( [ 1 , 7 ] )
editor . addCursorAtBufferPosition ( [ 2 , 2 ] )
editor . addCursorAtBufferPosition ( [ 3 , 1 ] )
[ selection1 , selection2 , selection3 , selection4 ] = editor . getSelections ( )
editor . selectToNextSubwordBoundary ( )
expect ( selection1 . getBufferRange ( ) ) . toEqual ( [ [ 0 , 1 ] , [ 0 , 4 ] ] )
expect ( selection1 . isReversed ( ) ) . toBeFalsy ( )
expect ( selection2 . getBufferRange ( ) ) . toEqual ( [ [ 1 , 7 ] , [ 1 , 11 ] ] )
expect ( selection2 . isReversed ( ) ) . toBeFalsy ( )
expect ( selection3 . getBufferRange ( ) ) . toEqual ( [ [ 2 , 2 ] , [ 2 , 5 ] ] )
expect ( selection3 . isReversed ( ) ) . toBeFalsy ( )
expect ( selection4 . getBufferRange ( ) ) . toEqual ( [ [ 3 , 1 ] , [ 3 , 3 ] ] )
expect ( selection4 . isReversed ( ) ) . toBeFalsy ( )
describe " .deleteToBeginningOfSubword " , ->
it " deletes subwords " , ->
editor . setText ( " " )
editor . insertText ( " _word \n " )
editor . insertText ( " getPreviousWord \n " )
editor . insertText ( " e, => \n " )
editor . insertText ( " 88 \n " )
editor . setCursorBufferPosition ( [ 0 , 5 ] )
editor . addCursorAtBufferPosition ( [ 1 , 7 ] )
editor . addCursorAtBufferPosition ( [ 2 , 5 ] )
editor . addCursorAtBufferPosition ( [ 3 , 3 ] )
[ cursor1 , cursor2 , cursor3 , cursor4 ] = editor . getCursors ( )
editor . deleteToBeginningOfSubword ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe ( ' _ ' )
expect ( buffer . lineForRow ( 1 ) ) . toBe ( ' getviousWord ' )
expect ( buffer . lineForRow ( 2 ) ) . toBe ( ' e, ' )
expect ( buffer . lineForRow ( 3 ) ) . toBe ( ' ' )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual ( [ 0 , 1 ] )
expect ( cursor2 . getBufferPosition ( ) ) . toEqual ( [ 1 , 4 ] )
expect ( cursor3 . getBufferPosition ( ) ) . toEqual ( [ 2 , 3 ] )
expect ( cursor4 . getBufferPosition ( ) ) . toEqual ( [ 3 , 1 ] )
editor . deleteToBeginningOfSubword ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe ( ' ' )
expect ( buffer . lineForRow ( 1 ) ) . toBe ( ' viousWord ' )
expect ( buffer . lineForRow ( 2 ) ) . toBe ( ' e ' )
expect ( buffer . lineForRow ( 3 ) ) . toBe ( ' ' )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual ( [ 0 , 0 ] )
expect ( cursor2 . getBufferPosition ( ) ) . toEqual ( [ 1 , 1 ] )
expect ( cursor3 . getBufferPosition ( ) ) . toEqual ( [ 2 , 1 ] )
expect ( cursor4 . getBufferPosition ( ) ) . toEqual ( [ 3 , 0 ] )
editor . deleteToBeginningOfSubword ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe ( ' ' )
expect ( buffer . lineForRow ( 1 ) ) . toBe ( ' viousWord ' )
expect ( buffer . lineForRow ( 2 ) ) . toBe ( ' ' )
expect ( buffer . lineForRow ( 3 ) ) . toBe ( ' ' )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual ( [ 0 , 0 ] )
expect ( cursor2 . getBufferPosition ( ) ) . toEqual ( [ 1 , 0 ] )
expect ( cursor3 . getBufferPosition ( ) ) . toEqual ( [ 2 , 0 ] )
expect ( cursor4 . getBufferPosition ( ) ) . toEqual ( [ 2 , 1 ] )
describe " .deleteToEndOfSubword " , ->
it " deletes subwords " , ->
editor . setText ( " " )
editor . insertText ( " word_ \n " )
editor . insertText ( " getPreviousWord \n " )
editor . insertText ( " e, => \n " )
editor . insertText ( " 88 \n " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . addCursorAtBufferPosition ( [ 1 , 0 ] )
editor . addCursorAtBufferPosition ( [ 2 , 2 ] )
editor . addCursorAtBufferPosition ( [ 3 , 0 ] )
[ cursor1 , cursor2 , cursor3 , cursor4 ] = editor . getCursors ( )
editor . deleteToEndOfSubword ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe ( ' _ ' )
expect ( buffer . lineForRow ( 1 ) ) . toBe ( ' PreviousWord ' )
expect ( buffer . lineForRow ( 2 ) ) . toBe ( ' e, ' )
expect ( buffer . lineForRow ( 3 ) ) . toBe ( ' 88 ' )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual ( [ 0 , 0 ] )
expect ( cursor2 . getBufferPosition ( ) ) . toEqual ( [ 1 , 0 ] )
expect ( cursor3 . getBufferPosition ( ) ) . toEqual ( [ 2 , 2 ] )
expect ( cursor4 . getBufferPosition ( ) ) . toEqual ( [ 3 , 0 ] )
editor . deleteToEndOfSubword ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe ( ' ' )
expect ( buffer . lineForRow ( 1 ) ) . toBe ( ' Word ' )
expect ( buffer . lineForRow ( 2 ) ) . toBe ( ' e, ' )
expect ( buffer . lineForRow ( 3 ) ) . toBe ( ' ' )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual ( [ 0 , 0 ] )
expect ( cursor2 . getBufferPosition ( ) ) . toEqual ( [ 1 , 0 ] )
expect ( cursor3 . getBufferPosition ( ) ) . toEqual ( [ 2 , 2 ] )
expect ( cursor4 . getBufferPosition ( ) ) . toEqual ( [ 3 , 0 ] )
2014-09-03 01:03:57 +04:00
describe " .selectWordsContainingCursors() " , ->
2014-03-06 08:32:11 +04:00
describe " when the cursor is inside a word " , ->
it " selects the entire word " , ->
editor . setCursorScreenPosition ( [ 0 , 8 ] )
2014-09-03 01:03:57 +04:00
editor . selectWordsContainingCursors ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedText ( ) ) . toBe ' quicksort '
describe " when the cursor is between two words " , ->
it " selects the word the cursor is on " , ->
editor . setCursorScreenPosition ( [ 0 , 4 ] )
2014-09-03 01:03:57 +04:00
editor . selectWordsContainingCursors ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedText ( ) ) . toBe ' quicksort '
editor . setCursorScreenPosition ( [ 0 , 3 ] )
2014-09-03 01:03:57 +04:00
editor . selectWordsContainingCursors ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedText ( ) ) . toBe ' var '
describe " when the cursor is inside a region of whitespace " , ->
it " selects the whitespace region " , ->
editor . setCursorScreenPosition ( [ 5 , 2 ] )
2014-09-03 01:03:57 +04:00
editor . selectWordsContainingCursors ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 5 , 0 ] , [ 5 , 6 ] ]
editor . setCursorScreenPosition ( [ 5 , 0 ] )
2014-09-03 01:03:57 +04:00
editor . selectWordsContainingCursors ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 5 , 0 ] , [ 5 , 6 ] ]
describe " when the cursor is at the end of the text " , ->
it " select the previous word " , ->
editor . buffer . append ' word '
2014-08-29 02:25:12 +04:00
editor . moveToBottom ( )
2014-09-03 01:03:57 +04:00
editor . selectWordsContainingCursors ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 12 , 2 ] , [ 12 , 6 ] ]
2016-07-12 21:30:41 +03:00
it " selects words based on the non-word characters configured at the cursor ' s current scope " , ->
2016-07-15 21:43:03 +03:00
editor . setText ( " one-one; ' two-two ' ; three-three " )
2016-07-12 21:30:41 +03:00
editor . setCursorBufferPosition ( [ 0 , 1 ] )
editor . addCursorAtBufferPosition ( [ 0 , 12 ] )
2014-10-08 05:01:29 +04:00
2016-07-12 21:30:41 +03:00
scopeDescriptors = editor . getCursors ( ) . map (c) -> c . getScopeDescriptor ( )
expect ( scopeDescriptors [ 0 ] . getScopesArray ( ) ) . toEqual ( [ ' source.js ' ] )
expect ( scopeDescriptors [ 1 ] . getScopesArray ( ) ) . toEqual ( [ ' source.js ' , ' string.quoted.single.js ' ] )
2014-10-08 05:01:29 +04:00
2016-07-12 21:30:41 +03:00
editor . setScopedSettingsDelegate ( {
getNonWordCharacters: (scopes) ->
result = ' / \( ) " \' :,.;<>~!@ # $%^&*|+=[]{}`? '
if ( scopes . some (scope) -> scope . startsWith ( ' string ' ) )
result
else
result + ' - '
} )
2014-10-08 05:01:29 +04:00
2016-07-12 21:30:41 +03:00
editor . selectWordsContainingCursors ( )
2014-10-08 05:01:29 +04:00
2016-07-12 21:30:41 +03:00
expect ( editor . getSelections ( ) [ 0 ] . getText ( ) ) . toBe ( ' one ' )
expect ( editor . getSelections ( ) [ 1 ] . getText ( ) ) . toBe ( ' two-two ' )
2014-10-08 05:01:29 +04:00
2014-03-06 08:32:11 +04:00
describe " .selectToFirstCharacterOfLine() " , ->
it " moves to the first character of the current line or the beginning of the line if it ' s already on the first character " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition [ 0 , 5 ]
editor . addCursorAtScreenPosition [ 1 , 7 ]
2014-03-06 08:32:11 +04:00
editor . selectToFirstCharacterOfLine ( )
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 0 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 2 ]
2014-03-06 08:32:11 +04:00
expect ( editor . getSelections ( ) . length ) . toBe 2
[ selection1 , selection2 ] = editor . getSelections ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 0 , 5 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection1 . isReversed ( ) ) . toBeTruthy ( )
2015-05-23 02:50:04 +03:00
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 1 , 2 ] , [ 1 , 7 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection2 . isReversed ( ) ) . toBeTruthy ( )
editor . selectToFirstCharacterOfLine ( )
[ selection1 , selection2 ] = editor . getSelections ( )
2015-05-23 02:50:04 +03:00
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 0 , 5 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection1 . isReversed ( ) ) . toBeTruthy ( )
2015-05-23 02:50:04 +03:00
expect ( selection2 . getBufferRange ( ) ) . toEqual [ [ 1 , 0 ] , [ 1 , 7 ] ]
2014-03-06 08:32:11 +04:00
expect ( selection2 . isReversed ( ) ) . toBeTruthy ( )
describe " .setSelectedBufferRanges(ranges) " , ->
it " clears existing selections and creates selections for each of the given ranges " , ->
editor . setSelectedBufferRanges ( [ [ [ 2 , 2 ] , [ 3 , 3 ] ] , [ [ 4 , 4 ] , [ 5 , 5 ] ] ] )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 2 , 2 ] , [ 3 , 3 ] ] , [ [ 4 , 4 ] , [ 5 , 5 ] ] ]
editor . setSelectedBufferRanges ( [ [ [ 5 , 5 ] , [ 6 , 6 ] ] ] )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 5 , 5 ] , [ 6 , 6 ] ] ]
it " merges intersecting selections " , ->
editor . setSelectedBufferRanges ( [ [ [ 2 , 2 ] , [ 3 , 3 ] ] , [ [ 3 , 0 ] , [ 5 , 5 ] ] ] )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 2 , 2 ] , [ 5 , 5 ] ] ]
2014-09-03 01:32:14 +04:00
it " does not merge non-empty adjacent selections " , ->
editor . setSelectedBufferRanges ( [ [ [ 2 , 2 ] , [ 3 , 3 ] ] , [ [ 3 , 3 ] , [ 5 , 5 ] ] ] )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 2 , 2 ] , [ 3 , 3 ] ] , [ [ 3 , 3 ] , [ 5 , 5 ] ] ]
2014-03-06 08:32:11 +04:00
it " recyles existing selection instances " , ->
2014-08-29 04:51:16 +04:00
selection = editor . getLastSelection ( )
2014-03-06 08:32:11 +04:00
editor . setSelectedBufferRanges ( [ [ [ 2 , 2 ] , [ 3 , 3 ] ] , [ [ 4 , 4 ] , [ 5 , 5 ] ] ] )
[ selection1 , selection2 ] = editor . getSelections ( )
expect ( selection1 ) . toBe selection
expect ( selection1 . getBufferRange ( ) ) . toEqual [ [ 2 , 2 ] , [ 3 , 3 ] ]
2014-04-18 01:24:40 +04:00
describe " when the ' preserveFolds ' option is false (the default) " , ->
2014-03-06 08:32:11 +04:00
it " removes folds that contain the selections " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 0 , 0 ] ] )
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 1 , 4 )
editor . foldBufferRowRange ( 2 , 3 )
editor . foldBufferRowRange ( 6 , 8 )
editor . foldBufferRowRange ( 10 , 11 )
2014-03-06 08:32:11 +04:00
editor . setSelectedBufferRanges ( [ [ [ 2 , 2 ] , [ 3 , 3 ] ] , [ [ 6 , 6 ] , [ 7 , 7 ] ] ] )
2016-03-22 18:05:38 +03:00
expect ( editor . isFoldedAtScreenRow ( 1 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtScreenRow ( 2 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtScreenRow ( 6 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtScreenRow ( 10 ) ) . toBeTruthy ( )
2014-03-06 08:32:11 +04:00
2014-04-18 01:24:40 +04:00
describe " when the ' preserveFolds ' option is true " , ->
2014-03-06 08:32:11 +04:00
it " does not remove folds that contain the selections " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 0 , 0 ] ] )
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 1 , 4 )
editor . foldBufferRowRange ( 6 , 8 )
2014-03-06 08:32:11 +04:00
editor . setSelectedBufferRanges ( [ [ [ 2 , 2 ] , [ 3 , 3 ] ] , [ [ 6 , 0 ] , [ 6 , 1 ] ] ] , preserveFolds: true )
expect ( editor . isFoldedAtBufferRow ( 1 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
2014-08-29 04:28:24 +04:00
describe " .setSelectedScreenRanges(ranges) " , ->
beforeEach ->
editor . foldBufferRow ( 4 )
it " clears existing selections and creates selections for each of the given ranges " , ->
editor . setSelectedScreenRanges ( [ [ [ 3 , 4 ] , [ 3 , 7 ] ] , [ [ 5 , 4 ] , [ 5 , 7 ] ] ] )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 3 , 4 ] , [ 3 , 7 ] ] , [ [ 8 , 4 ] , [ 8 , 7 ] ] ]
editor . setSelectedScreenRanges ( [ [ [ 6 , 2 ] , [ 6 , 4 ] ] ] )
expect ( editor . getSelectedScreenRanges ( ) ) . toEqual [ [ [ 6 , 2 ] , [ 6 , 4 ] ] ]
2015-03-11 18:16:45 +03:00
it " merges intersecting selections and unfolds the fold which contain them " , ->
editor . foldBufferRow ( 0 )
# Use buffer ranges because only the first line is on screen
editor . setSelectedBufferRanges ( [ [ [ 2 , 2 ] , [ 3 , 3 ] ] , [ [ 3 , 0 ] , [ 5 , 5 ] ] ] )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 2 , 2 ] , [ 5 , 5 ] ] ]
2014-08-29 04:28:24 +04:00
it " recyles existing selection instances " , ->
2014-08-29 04:51:16 +04:00
selection = editor . getLastSelection ( )
2014-08-29 04:28:24 +04:00
editor . setSelectedScreenRanges ( [ [ [ 2 , 2 ] , [ 3 , 4 ] ] , [ [ 4 , 4 ] , [ 5 , 5 ] ] ] )
[ selection1 , selection2 ] = editor . getSelections ( )
expect ( selection1 ) . toBe selection
expect ( selection1 . getScreenRange ( ) ) . toEqual [ [ 2 , 2 ] , [ 3 , 4 ] ]
2014-03-06 08:32:11 +04:00
describe " .selectMarker(marker) " , ->
describe " if the marker is valid " , ->
it " selects the marker ' s range and returns the selected range " , ->
marker = editor . markBufferRange ( [ [ 0 , 1 ] , [ 3 , 3 ] ] )
expect ( editor . selectMarker ( marker ) ) . toEqual [ [ 0 , 1 ] , [ 3 , 3 ] ]
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 1 ] , [ 3 , 3 ] ]
describe " if the marker is invalid " , ->
it " does not change the selection and returns a falsy value " , ->
marker = editor . markBufferRange ( [ [ 0 , 1 ] , [ 3 , 3 ] ] )
marker . destroy ( )
expect ( editor . selectMarker ( marker ) ) . toBeFalsy ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 0 , 0 ] ]
2014-06-21 02:53:23 +04:00
describe " .addSelectionForBufferRange(bufferRange) " , ->
it " adds a selection for the specified buffer range " , ->
editor . addSelectionForBufferRange ( [ [ 3 , 4 ] , [ 5 , 6 ] ] )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 0 ] , [ 0 , 0 ] ] , [ [ 3 , 4 ] , [ 5 , 6 ] ] ]
2014-03-06 08:32:11 +04:00
describe " .addSelectionBelow() " , ->
describe " when the selection is non-empty " , ->
it " selects the same region of the line below current selections if possible " , ->
editor . setSelectedBufferRange ( [ [ 3 , 16 ] , [ 3 , 21 ] ] )
editor . addSelectionForBufferRange ( [ [ 3 , 25 ] , [ 3 , 34 ] ] )
editor . addSelectionBelow ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 3 , 16 ] , [ 3 , 21 ] ]
[ [ 3 , 25 ] , [ 3 , 34 ] ]
[ [ 4 , 16 ] , [ 4 , 21 ] ]
[ [ 4 , 25 ] , [ 4 , 29 ] ]
]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " skips lines that are too short to create a non-empty selection " , ->
editor . setSelectedBufferRange ( [ [ 3 , 31 ] , [ 3 , 38 ] ] )
editor . addSelectionBelow ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 3 , 31 ] , [ 3 , 38 ] ]
[ [ 6 , 31 ] , [ 6 , 38 ] ]
]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " honors the original selection ' s range (goal range) when adding across shorter lines " , ->
editor . setSelectedBufferRange ( [ [ 3 , 22 ] , [ 3 , 38 ] ] )
editor . addSelectionBelow ( )
editor . addSelectionBelow ( )
editor . addSelectionBelow ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 3 , 22 ] , [ 3 , 38 ] ]
[ [ 4 , 22 ] , [ 4 , 29 ] ]
[ [ 5 , 22 ] , [ 5 , 30 ] ]
[ [ 6 , 22 ] , [ 6 , 38 ] ]
]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " clears selection goal ranges when the selection changes " , ->
editor . setSelectedBufferRange ( [ [ 3 , 22 ] , [ 3 , 38 ] ] )
editor . addSelectionBelow ( )
2013-11-20 03:22:47 +04:00
editor . selectLeft ( )
2014-03-06 08:32:11 +04:00
editor . addSelectionBelow ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 3 , 22 ] , [ 3 , 37 ] ]
[ [ 4 , 22 ] , [ 4 , 29 ] ]
[ [ 5 , 22 ] , [ 5 , 28 ] ]
]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
# goal range from previous add selection is honored next time
editor . addSelectionBelow ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 3 , 22 ] , [ 3 , 37 ] ]
[ [ 4 , 22 ] , [ 4 , 29 ] ]
[ [ 5 , 22 ] , [ 5 , 30 ] ] # select to end of line 5 because line 4's goal range was reset by line 3 previously
[ [ 6 , 22 ] , [ 6 , 28 ] ]
]
2012-08-28 02:36:36 +04:00
2015-03-14 11:26:29 +03:00
it " can add selections to soft-wrapped line segments " , ->
2015-03-13 13:32:42 +03:00
editor . setSoftWrapped ( true )
editor . setEditorWidthInChars ( 40 )
2015-10-16 12:22:03 +03:00
editor . setDefaultCharWidth ( 1 )
2015-03-13 13:32:42 +03:00
2015-03-14 11:26:29 +03:00
editor . setSelectedScreenRange ( [ [ 3 , 10 ] , [ 3 , 15 ] ] )
2015-03-13 13:32:42 +03:00
editor . addSelectionBelow ( )
expect ( editor . getSelectedScreenRanges ( ) ) . toEqual [
2015-03-14 11:26:29 +03:00
[ [ 3 , 10 ] , [ 3 , 15 ] ]
[ [ 4 , 10 ] , [ 4 , 15 ] ]
2015-03-13 13:32:42 +03:00
]
2015-03-13 13:56:00 +03:00
it " takes atomic tokens into account " , ->
waitsForPromise ->
2015-10-03 06:13:42 +03:00
atom . workspace . open ( ' sample-with-tabs-and-leading-comment.coffee ' , autoIndent: false ) . then (o) -> editor = o
2015-03-13 13:56:00 +03:00
runs ->
editor . setSelectedBufferRange ( [ [ 2 , 1 ] , [ 2 , 3 ] ] )
editor . addSelectionBelow ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 2 , 1 ] , [ 2 , 3 ] ]
[ [ 3 , 1 ] , [ 3 , 2 ] ]
]
2014-03-06 08:32:11 +04:00
describe " when the selection is empty " , ->
2015-03-13 14:05:18 +03:00
describe " when lines are soft-wrapped " , ->
beforeEach ->
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2015-03-13 14:05:18 +03:00
editor . setEditorWidthInChars ( 40 )
2015-03-13 13:32:42 +03:00
2015-03-13 14:05:18 +03:00
it " skips soft-wrap indentation tokens " , ->
2015-03-14 11:26:29 +03:00
editor . setCursorScreenPosition ( [ 3 , 0 ] )
2015-03-13 14:05:18 +03:00
editor . addSelectionBelow ( )
expect ( editor . getSelectedScreenRanges ( ) ) . toEqual [
2015-03-14 11:26:29 +03:00
[ [ 3 , 0 ] , [ 3 , 0 ] ]
[ [ 4 , 4 ] , [ 4 , 4 ] ]
2015-03-13 14:05:18 +03:00
]
it " does not skip them if they ' re shorter than the current column " , ->
2015-03-14 11:26:29 +03:00
editor . setCursorScreenPosition ( [ 3 , 37 ] )
2015-03-13 14:05:18 +03:00
editor . addSelectionBelow ( )
expect ( editor . getSelectedScreenRanges ( ) ) . toEqual [
2015-03-14 11:26:29 +03:00
[ [ 3 , 37 ] , [ 3 , 37 ] ]
[ [ 4 , 26 ] , [ 4 , 26 ] ]
2015-03-13 14:05:18 +03:00
]
2015-03-13 13:32:42 +03:00
2014-03-06 08:32:11 +04:00
it " does not skip lines that are shorter than the current column " , ->
editor . setCursorBufferPosition ( [ 3 , 36 ] )
editor . addSelectionBelow ( )
editor . addSelectionBelow ( )
editor . addSelectionBelow ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 3 , 36 ] , [ 3 , 36 ] ]
[ [ 4 , 29 ] , [ 4 , 29 ] ]
[ [ 5 , 30 ] , [ 5 , 30 ] ]
[ [ 6 , 36 ] , [ 6 , 36 ] ]
]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " skips empty lines when the column is non-zero " , ->
editor . setCursorBufferPosition ( [ 9 , 4 ] )
editor . addSelectionBelow ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 9 , 4 ] , [ 9 , 4 ] ]
[ [ 11 , 4 ] , [ 11 , 4 ] ]
]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " does not skip empty lines when the column is zero " , ->
editor . setCursorBufferPosition ( [ 9 , 0 ] )
editor . addSelectionBelow ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 9 , 0 ] , [ 9 , 0 ] ]
[ [ 10 , 0 ] , [ 10 , 0 ] ]
]
2012-08-28 02:36:36 +04:00
2014-09-03 04:44:01 +04:00
describe " .addSelectionAbove() " , ->
2014-03-06 08:32:11 +04:00
describe " when the selection is non-empty " , ->
it " selects the same region of the line above current selections if possible " , ->
editor . setSelectedBufferRange ( [ [ 3 , 16 ] , [ 3 , 21 ] ] )
editor . addSelectionForBufferRange ( [ [ 3 , 37 ] , [ 3 , 44 ] ] )
editor . addSelectionAbove ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 3 , 16 ] , [ 3 , 21 ] ]
[ [ 3 , 37 ] , [ 3 , 44 ] ]
2014-09-03 01:55:02 +04:00
[ [ 2 , 16 ] , [ 2 , 21 ] ]
[ [ 2 , 37 ] , [ 2 , 40 ] ]
2014-03-06 08:32:11 +04:00
]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " skips lines that are too short to create a non-empty selection " , ->
editor . setSelectedBufferRange ( [ [ 6 , 31 ] , [ 6 , 38 ] ] )
editor . addSelectionAbove ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 6 , 31 ] , [ 6 , 38 ] ]
2014-09-03 01:55:02 +04:00
[ [ 3 , 31 ] , [ 3 , 38 ] ]
2014-03-06 08:32:11 +04:00
]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " honors the original selection ' s range (goal range) when adding across shorter lines " , ->
editor . setSelectedBufferRange ( [ [ 6 , 22 ] , [ 6 , 38 ] ] )
editor . addSelectionAbove ( )
editor . addSelectionAbove ( )
editor . addSelectionAbove ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 6 , 22 ] , [ 6 , 38 ] ]
2014-09-03 01:55:02 +04:00
[ [ 5 , 22 ] , [ 5 , 30 ] ]
[ [ 4 , 22 ] , [ 4 , 29 ] ]
[ [ 3 , 22 ] , [ 3 , 38 ] ]
2014-03-06 08:32:11 +04:00
]
2013-05-04 03:24:08 +04:00
2015-03-14 11:26:29 +03:00
it " can add selections to soft-wrapped line segments " , ->
2015-03-13 13:32:42 +03:00
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2015-03-13 13:32:42 +03:00
editor . setEditorWidthInChars ( 40 )
2015-03-14 11:26:29 +03:00
editor . setSelectedScreenRange ( [ [ 4 , 10 ] , [ 4 , 15 ] ] )
2015-03-13 13:32:42 +03:00
editor . addSelectionAbove ( )
expect ( editor . getSelectedScreenRanges ( ) ) . toEqual [
2015-03-14 11:26:29 +03:00
[ [ 4 , 10 ] , [ 4 , 15 ] ]
[ [ 3 , 10 ] , [ 3 , 15 ] ]
2015-03-13 13:32:42 +03:00
]
2015-03-13 13:56:00 +03:00
it " takes atomic tokens into account " , ->
waitsForPromise ->
2015-10-03 06:13:42 +03:00
atom . workspace . open ( ' sample-with-tabs-and-leading-comment.coffee ' , autoIndent: false ) . then (o) -> editor = o
2015-03-13 13:56:00 +03:00
runs ->
editor . setSelectedBufferRange ( [ [ 3 , 1 ] , [ 3 , 2 ] ] )
editor . addSelectionAbove ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 3 , 1 ] , [ 3 , 2 ] ]
[ [ 2 , 1 ] , [ 2 , 3 ] ]
]
2014-03-06 08:32:11 +04:00
describe " when the selection is empty " , ->
2015-03-13 14:05:18 +03:00
describe " when lines are soft-wrapped " , ->
beforeEach ->
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2015-03-13 14:05:18 +03:00
editor . setEditorWidthInChars ( 40 )
2015-03-13 13:32:42 +03:00
2015-03-13 14:05:18 +03:00
it " skips soft-wrap indentation tokens " , ->
2015-03-14 11:26:29 +03:00
editor . setCursorScreenPosition ( [ 5 , 0 ] )
2015-03-13 14:05:18 +03:00
editor . addSelectionAbove ( )
expect ( editor . getSelectedScreenRanges ( ) ) . toEqual [
2015-03-14 11:26:29 +03:00
[ [ 5 , 0 ] , [ 5 , 0 ] ]
[ [ 4 , 4 ] , [ 4 , 4 ] ]
2015-03-13 14:05:18 +03:00
]
it " does not skip them if they ' re shorter than the current column " , ->
2015-03-14 11:26:29 +03:00
editor . setCursorScreenPosition ( [ 5 , 29 ] )
2015-03-13 14:05:18 +03:00
editor . addSelectionAbove ( )
expect ( editor . getSelectedScreenRanges ( ) ) . toEqual [
2015-03-14 11:26:29 +03:00
[ [ 5 , 29 ] , [ 5 , 29 ] ]
[ [ 4 , 26 ] , [ 4 , 26 ] ]
2015-03-13 14:05:18 +03:00
]
2015-03-13 13:32:42 +03:00
2014-03-06 08:32:11 +04:00
it " does not skip lines that are shorter than the current column " , ->
editor . setCursorBufferPosition ( [ 6 , 36 ] )
editor . addSelectionAbove ( )
editor . addSelectionAbove ( )
editor . addSelectionAbove ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 6 , 36 ] , [ 6 , 36 ] ]
2014-09-03 01:55:02 +04:00
[ [ 5 , 30 ] , [ 5 , 30 ] ]
[ [ 4 , 29 ] , [ 4 , 29 ] ]
[ [ 3 , 36 ] , [ 3 , 36 ] ]
2014-03-06 08:32:11 +04:00
]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " skips empty lines when the column is non-zero " , ->
editor . setCursorBufferPosition ( [ 11 , 4 ] )
editor . addSelectionAbove ( )
2014-01-08 06:17:34 +04:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
2014-03-06 08:32:11 +04:00
[ [ 11 , 4 ] , [ 11 , 4 ] ]
2014-09-03 01:55:02 +04:00
[ [ 9 , 4 ] , [ 9 , 4 ] ]
2014-01-08 06:17:34 +04:00
]
2014-03-06 08:32:11 +04:00
it " does not skip empty lines when the column is zero " , ->
editor . setCursorBufferPosition ( [ 10 , 0 ] )
editor . addSelectionAbove ( )
2014-01-08 06:17:34 +04:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
2014-03-06 08:32:11 +04:00
[ [ 10 , 0 ] , [ 10 , 0 ] ]
2014-09-03 01:55:02 +04:00
[ [ 9 , 0 ] , [ 9 , 0 ] ]
2014-01-08 06:17:34 +04:00
]
2014-03-06 08:32:11 +04:00
describe " .splitSelectionsIntoLines() " , ->
it " splits all multi-line selections into one selection per line " , ->
editor . setSelectedBufferRange ( [ [ 0 , 3 ] , [ 2 , 4 ] ] )
editor . splitSelectionsIntoLines ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 0 , 3 ] , [ 0 , 29 ] ]
[ [ 1 , 0 ] , [ 1 , 30 ] ]
[ [ 2 , 0 ] , [ 2 , 4 ] ]
]
editor . setSelectedBufferRange ( [ [ 0 , 3 ] , [ 1 , 10 ] ] )
editor . splitSelectionsIntoLines ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 0 , 3 ] , [ 0 , 29 ] ]
[ [ 1 , 0 ] , [ 1 , 10 ] ]
]
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 0 , 3 ] ] )
editor . splitSelectionsIntoLines ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 0 ] , [ 0 , 3 ] ] ]
2015-12-12 01:32:29 +03:00
describe " ::consolidateSelections() " , ->
makeMultipleSelections = ->
selection . setBufferRange [ [ 3 , 16 ] , [ 3 , 21 ] ]
2014-03-06 08:32:11 +04:00
selection2 = editor . addSelectionForBufferRange ( [ [ 3 , 25 ] , [ 3 , 34 ] ] )
selection3 = editor . addSelectionForBufferRange ( [ [ 8 , 4 ] , [ 8 , 10 ] ] )
2015-12-12 01:32:29 +03:00
selection4 = editor . addSelectionForBufferRange ( [ [ 1 , 6 ] , [ 1 , 10 ] ] )
expect ( editor . getSelections ( ) ) . toEqual [ selection , selection2 , selection3 , selection4 ]
[ selection , selection2 , selection3 , selection4 ]
2016-03-01 04:51:36 +03:00
it " destroys all selections but the oldest selection and autoscrolls to it, returning true if any selections were destroyed " , ->
2015-12-12 01:32:29 +03:00
[ selection1 ] = makeMultipleSelections ( )
2014-03-06 08:32:11 +04:00
2016-03-01 04:51:36 +03:00
autoscrollEvents = [ ]
editor . onDidRequestAutoscroll (event) -> autoscrollEvents . push ( event )
2014-03-06 08:32:11 +04:00
expect ( editor . consolidateSelections ( ) ) . toBeTruthy ( )
2015-08-31 21:22:24 +03:00
expect ( editor . getSelections ( ) ) . toEqual [ selection1 ]
expect ( selection1 . isEmpty ( ) ) . toBeFalsy ( )
2014-03-06 08:32:11 +04:00
expect ( editor . consolidateSelections ( ) ) . toBeFalsy ( )
2015-08-31 21:22:24 +03:00
expect ( editor . getSelections ( ) ) . toEqual [ selection1 ]
2014-03-06 08:32:11 +04:00
2016-03-01 04:51:36 +03:00
expect ( autoscrollEvents ) . toEqual ( [
{ screenRange: selection1 . getScreenRange ( ) , options: { center: true , reversed: false } }
] )
2014-03-06 08:32:11 +04:00
describe " when the cursor is moved while there is a selection " , ->
makeSelection = -> selection . setBufferRange [ [ 1 , 2 ] , [ 1 , 5 ] ]
it " clears the selection " , ->
makeSelection ( )
2014-08-29 02:25:12 +04:00
editor . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( selection . isEmpty ( ) ) . toBeTruthy ( )
makeSelection ( )
2014-08-29 02:25:12 +04:00
editor . moveUp ( )
2014-03-06 08:32:11 +04:00
expect ( selection . isEmpty ( ) ) . toBeTruthy ( )
makeSelection ( )
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( selection . isEmpty ( ) ) . toBeTruthy ( )
2014-01-08 06:17:34 +04:00
2014-03-06 08:32:11 +04:00
makeSelection ( )
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( selection . isEmpty ( ) ) . toBeTruthy ( )
makeSelection ( )
editor . setCursorScreenPosition ( [ 3 , 3 ] )
expect ( selection . isEmpty ( ) ) . toBeTruthy ( )
it " does not share selections between different edit sessions for the same buffer " , ->
2014-04-23 04:52:28 +04:00
editor2 = null
waitsForPromise ->
2015-10-03 06:13:42 +03:00
atom . workspace . getActivePane ( ) . splitRight ( )
2015-10-07 00:32:29 +03:00
atom . workspace . open ( editor . getPath ( ) ) . then (o) -> editor2 = o
2014-04-23 04:52:28 +04:00
runs ->
2015-10-03 06:13:42 +03:00
expect ( editor2 . getText ( ) ) . toBe ( editor . getText ( ) )
2014-04-23 04:52:28 +04:00
editor . setSelectedBufferRanges ( [ [ [ 1 , 2 ] , [ 3 , 4 ] ] , [ [ 5 , 6 ] , [ 7 , 8 ] ] ] )
editor2 . setSelectedBufferRanges ( [ [ [ 8 , 7 ] , [ 6 , 5 ] ] , [ [ 4 , 3 ] , [ 2 , 1 ] ] ] )
expect ( editor2 . getSelectedBufferRanges ( ) ) . not . toEqual editor . getSelectedBufferRanges ( )
2014-03-06 08:32:11 +04:00
describe " buffer manipulation " , ->
2015-08-05 16:43:26 +03:00
describe " .moveLineUp " , ->
2015-11-04 20:55:52 +03:00
it " moves the line under the cursor up " , ->
editor . setCursorBufferPosition ( [ 1 , 0 ] )
editor . moveLineUp ( )
expect ( editor . getTextInBufferRange ( [ [ 0 , 0 ] , [ 0 , 30 ] ] ) ) . toBe " var sort = function(items) { "
expect ( editor . indentationForBufferRow ( 0 ) ) . toBe 1
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 0
2016-07-12 03:37:51 +03:00
it " updates the line ' s indentation when the the autoIndent setting is true " , ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2015-11-04 20:55:52 +03:00
editor . setCursorBufferPosition ( [ 1 , 0 ] )
editor . moveLineUp ( )
expect ( editor . indentationForBufferRow ( 0 ) ) . toBe 0
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 0
2015-08-12 01:54:08 +03:00
describe " when there is a single selection " , ->
describe " when the selection spans a single line " , ->
2015-08-13 19:00:51 +03:00
describe " when there is no fold in the preceeding row " , ->
it " moves the line to the preceding row " , ->
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
editor . setSelectedBufferRange ( [ [ 3 , 2 ] , [ 3 , 9 ] ] )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 2 , 2 ] , [ 2 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " if (items.length <= 1) return items; "
2015-11-02 23:46:02 +03:00
describe " when the cursor is at the beginning of a fold " , ->
2015-11-03 01:37:56 +03:00
it " moves the line to the previous row without breaking the fold " , ->
2015-11-02 23:46:02 +03:00
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-11-02 23:46:02 +03:00
editor . setSelectedBufferRange ( [ [ 4 , 2 ] , [ 4 , 9 ] ] , preserveFolds: true )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 4 , 2 ] , [ 4 , 9 ] ]
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 3 , 2 ] , [ 3 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeFalsy ( )
2015-08-13 19:00:51 +03:00
describe " when the preceding row consists of folded code " , ->
it " moves the line above the folded row and preseveres the correct folds " , ->
2015-08-15 12:19:26 +03:00
expect ( editor . lineTextForBufferRow ( 8 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe " }; "
2015-08-13 19:00:51 +03:00
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-08-13 19:00:51 +03:00
2015-08-15 12:19:26 +03:00
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
2015-08-13 19:00:51 +03:00
2015-08-15 12:19:26 +03:00
editor . setSelectedBufferRange ( [ [ 8 , 0 ] , [ 8 , 4 ] ] )
editor . moveLineUp ( )
2015-08-13 19:00:51 +03:00
2015-08-15 12:19:26 +03:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 4 , 0 ] , [ 4 , 4 ] ]
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " while(items.length > 0) { "
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
2015-08-05 16:43:26 +03:00
2015-08-12 01:54:08 +03:00
describe " when the selection spans multiple lines " , ->
it " moves the lines spanned by the selection to the preceding row " , ->
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2015-08-05 16:43:26 +03:00
2015-08-12 01:54:08 +03:00
editor . setSelectedBufferRange ( [ [ 3 , 2 ] , [ 4 , 9 ] ] )
editor . moveLineUp ( )
2015-08-05 16:43:26 +03:00
2015-08-12 01:54:08 +03:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 2 , 2 ] , [ 3 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " if (items.length <= 1) return items; "
2015-08-05 16:43:26 +03:00
2015-11-02 23:46:02 +03:00
describe " when the selection ' s end intersects a fold " , ->
2015-11-03 01:37:56 +03:00
it " moves the lines to the previous row without breaking the fold " , ->
2015-11-02 23:46:02 +03:00
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-11-02 23:46:02 +03:00
editor . setSelectedBufferRange ( [ [ 3 , 2 ] , [ 4 , 9 ] ] , preserveFolds: true )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 2 , 2 ] , [ 3 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeFalsy ( )
describe " when the selection ' s start intersects a fold " , ->
2015-11-03 01:37:56 +03:00
it " moves the lines to the previous row without breaking the fold " , ->
2015-11-02 23:46:02 +03:00
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-11-02 23:46:02 +03:00
editor . setSelectedBufferRange ( [ [ 4 , 2 ] , [ 8 , 9 ] ] , preserveFolds: true )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 3 , 2 ] , [ 7 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
expect ( editor . lineTextForBufferRow ( 8 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
2015-08-12 01:54:08 +03:00
describe " when the selection spans multiple lines, but ends at column 0 " , ->
it " does not move the last line of the selection " , ->
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2015-08-05 16:43:26 +03:00
2015-08-12 01:54:08 +03:00
editor . setSelectedBufferRange ( [ [ 3 , 2 ] , [ 4 , 0 ] ] )
2015-08-05 16:43:26 +03:00
editor . moveLineUp ( )
2015-08-12 01:54:08 +03:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 2 , 2 ] , [ 3 , 0 ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2015-11-03 01:37:56 +03:00
describe " when the preceeding row is a folded row " , ->
2015-08-13 19:00:51 +03:00
it " moves the lines spanned by the selection to the preceeding row, but preserves the folded code " , ->
expect ( editor . lineTextForBufferRow ( 8 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
2015-08-15 12:19:26 +03:00
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe " }; "
2015-08-13 19:00:51 +03:00
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-08-13 19:00:51 +03:00
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
2015-08-15 12:19:26 +03:00
editor . setSelectedBufferRange ( [ [ 8 , 0 ] , [ 9 , 2 ] ] )
2015-08-05 16:43:26 +03:00
editor . moveLineUp ( )
2015-08-15 12:19:26 +03:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 4 , 0 ] , [ 5 , 2 ] ]
2015-08-13 19:00:51 +03:00
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
2015-08-15 12:19:26 +03:00
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " }; "
2015-08-13 19:00:51 +03:00
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe " while(items.length > 0) { "
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 10 ) ) . toBeFalsy ( )
describe " when there are multiple selections " , ->
describe " when all the selections span different lines " , ->
describe " when there is no folds " , ->
it " moves all lines that are spanned by a selection to the preceding row " , ->
editor . setSelectedBufferRanges ( [ [ [ 1 , 2 ] , [ 1 , 9 ] ] , [ [ 3 , 2 ] , [ 3 , 9 ] ] , [ [ 5 , 2 ] , [ 5 , 9 ] ] ] )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 2 ] , [ 0 , 9 ] ] , [ [ 2 , 2 ] , [ 2 , 9 ] ] , [ [ 4 , 2 ] , [ 4 , 9 ] ] ]
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe " var sort = function(items) { "
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe " var quicksort = function () { "
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " current = items.shift(); "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " while(items.length > 0) { "
2015-11-03 01:43:43 +03:00
describe " when one selection intersects a fold " , ->
it " moves the lines to the previous row without breaking the fold " , ->
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-11-03 01:43:43 +03:00
editor . setSelectedBufferRanges ( [
[ [ 2 , 2 ] , [ 2 , 9 ] ] ,
[ [ 4 , 2 ] , [ 4 , 9 ] ]
] , preserveFolds: true )
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual ( [
[ [ 1 , 2 ] , [ 1 , 9 ] ] ,
[ [ 3 , 2 ] , [ 3 , 9 ] ]
] )
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var sort = function(items) { "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . isFoldedAtBufferRow ( 1 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
2015-08-13 19:00:51 +03:00
describe " when there is a fold " , ->
it " moves all lines that spanned by a selection to preceding row, preserving all folds " , ->
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-08-13 19:00:51 +03:00
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
editor . setSelectedBufferRanges ( [ [ [ 8 , 0 ] , [ 8 , 3 ] ] , [ [ 11 , 0 ] , [ 11 , 5 ] ] ] )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 4 , 0 ] , [ 4 , 3 ] ] , [ [ 10 , 0 ] , [ 10 , 5 ] ] ]
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
expect ( editor . lineTextForBufferRow ( 10 ) ) . toBe " return sort(Array.apply(this, arguments)); "
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
2015-08-12 01:54:08 +03:00
2015-11-03 02:48:22 +03:00
describe ' when there are many folds ' , ->
beforeEach ->
waitsForPromise ->
atom . workspace . open ( ' sample-with-many-folds.js ' , autoIndent: false ) . then (o) -> editor = o
describe ' and many selections intersects folded rows ' , ->
it ' moves and preserves all the folds ' , ->
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 2 , 4 )
editor . foldBufferRowRange ( 7 , 9 )
2015-11-03 02:48:22 +03:00
editor . setSelectedBufferRanges ( [
[ [ 1 , 0 ] , [ 5 , 4 ] ] ,
[ [ 7 , 0 ] , [ 7 , 4 ] ]
] , preserveFolds: true )
editor . moveLineUp ( )
expect ( editor . lineTextForBufferRow ( 1 ) ) . toEqual " function f3() { "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toEqual " 6; "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toEqual " 1; "
expect ( editor . lineTextForBufferRow ( 6 ) ) . toEqual " function f8() { "
expect ( editor . lineTextForBufferRow ( 9 ) ) . toEqual " 7; "
expect ( editor . isFoldedAtBufferRow ( 1 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
2015-08-12 03:06:24 +03:00
describe " when some of the selections span the same lines " , ->
it " moves lines that contain multiple selections correctly " , ->
editor . setSelectedBufferRanges ( [ [ [ 3 , 2 ] , [ 3 , 9 ] ] , [ [ 3 , 12 ] , [ 3 , 13 ] ] ] )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 2 , 2 ] , [ 2 , 9 ] ] , [ [ 2 , 12 ] , [ 2 , 13 ] ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
2015-08-12 01:54:08 +03:00
describe " when one of the selections spans line 0 " , ->
it " doesn ' t move any lines, since line 0 can ' t move " , ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 2 ] , [ 1 , 9 ] ] , [ [ 2 , 2 ] , [ 2 , 9 ] ] , [ [ 4 , 2 ] , [ 4 , 9 ] ] ] )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 2 ] , [ 1 , 9 ] ] , [ [ 2 , 2 ] , [ 2 , 9 ] ] , [ [ 4 , 2 ] , [ 4 , 9 ] ] ]
expect ( buffer . isModified ( ) ) . toBe false
describe " when one of the selections spans the last line, and it is empty " , ->
it " doesn ' t move any lines, since the last line can ' t move " , ->
buffer . append ( ' \n ' )
editor . setSelectedBufferRanges ( [ [ [ 0 , 2 ] , [ 1 , 9 ] ] , [ [ 2 , 2 ] , [ 2 , 9 ] ] , [ [ 13 , 0 ] , [ 13 , 0 ] ] ] )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 2 ] , [ 1 , 9 ] ] , [ [ 2 , 2 ] , [ 2 , 9 ] ] , [ [ 13 , 0 ] , [ 13 , 0 ] ] ]
2015-08-05 16:43:26 +03:00
2015-11-03 02:51:01 +03:00
describe " .moveLineDown " , ->
2015-11-04 20:55:52 +03:00
it " moves the line under the cursor down " , ->
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveLineDown ( )
expect ( editor . getTextInBufferRange ( [ [ 1 , 0 ] , [ 1 , 31 ] ] ) ) . toBe " var quicksort = function () { "
expect ( editor . indentationForBufferRow ( 0 ) ) . toBe 1
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 0
it " updates the line ' s indentation when the editor.autoIndent setting is true " , ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2015-11-04 20:55:52 +03:00
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . moveLineDown ( )
expect ( editor . indentationForBufferRow ( 0 ) ) . toBe 1
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 2
2015-08-15 12:19:26 +03:00
describe " when there is a single selection " , ->
describe " when the selection spans a single line " , ->
describe " when there is no fold in the following row " , ->
it " moves the line to the following row " , ->
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
editor . setSelectedBufferRange ( [ [ 2 , 2 ] , [ 2 , 9 ] ] )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 3 , 2 ] , [ 3 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " if (items.length <= 1) return items; "
2015-11-02 23:46:02 +03:00
describe " when the cursor is at the beginning of a fold " , ->
it " moves the line to the following row without breaking the fold " , ->
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-11-02 23:46:02 +03:00
editor . setSelectedBufferRange ( [ [ 4 , 2 ] , [ 4 , 9 ] ] , preserveFolds: true )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 5 , 2 ] , [ 5 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " while(items.length > 0) { "
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
2015-08-15 12:19:26 +03:00
describe " when the following row is a folded row " , ->
it " moves the line below the folded row and preserves the fold " , ->
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-08-15 12:19:26 +03:00
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
editor . setSelectedBufferRange ( [ [ 3 , 0 ] , [ 3 , 4 ] ] )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 7 , 0 ] , [ 7 , 4 ] ]
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " while(items.length > 0) { "
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeFalsy ( )
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
2015-10-12 23:10:09 +03:00
describe " when the selection spans multiple lines " , ->
2015-08-15 12:19:26 +03:00
it " moves the lines spanned by the selection to the following row " , ->
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
editor . setSelectedBufferRange ( [ [ 2 , 2 ] , [ 3 , 9 ] ] )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 3 , 2 ] , [ 4 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
describe " when the selection spans multiple lines, but ends at column 0 " , ->
it " does not move the last line of the selection " , ->
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
editor . setSelectedBufferRange ( [ [ 2 , 2 ] , [ 3 , 0 ] ] )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 3 , 2 ] , [ 4 , 0 ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2015-11-02 23:46:02 +03:00
describe " when the selection ' s end intersects a fold " , ->
it " moves the lines to the following row without breaking the fold " , ->
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-11-02 23:46:02 +03:00
editor . setSelectedBufferRange ( [ [ 3 , 2 ] , [ 4 , 9 ] ] , preserveFolds: true )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 4 , 2 ] , [ 5 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " while(items.length > 0) { "
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
describe " when the selection ' s start intersects a fold " , ->
it " moves the lines to the following row without breaking the fold " , ->
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-11-02 23:46:02 +03:00
editor . setSelectedBufferRange ( [ [ 4 , 2 ] , [ 8 , 9 ] ] , preserveFolds: true )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 5 , 2 ] , [ 9 , 9 ] ]
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " }; "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 10 ) ) . toBeFalsy ( )
2015-10-12 22:16:07 +03:00
describe " when the following row is a folded row " , ->
2015-08-15 12:19:26 +03:00
it " moves the lines spanned by the selection to the following row, but preserves the folded code " , ->
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-08-15 12:19:26 +03:00
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
editor . setSelectedBufferRange ( [ [ 2 , 0 ] , [ 3 , 2 ] ] )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 6 , 0 ] , [ 7 , 2 ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " while(items.length > 0) { "
expect ( editor . isFoldedAtBufferRow ( 1 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeFalsy ( )
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe " if (items.length <= 1) return items; "
2016-10-12 00:22:25 +03:00
describe " when the last line of selection does not end with a valid line ending " , ->
it " appends line ending to last line and moves the lines spanned by the selection to the preceeding row " , ->
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe " }; "
expect ( editor . lineTextForBufferRow ( 10 ) ) . toBe " "
expect ( editor . lineTextForBufferRow ( 11 ) ) . toBe " return sort(Array.apply(this, arguments)); "
expect ( editor . lineTextForBufferRow ( 12 ) ) . toBe " }; "
editor . setSelectedBufferRange ( [ [ 10 , 0 ] , [ 12 , 2 ] ] )
editor . moveLineUp ( )
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 9 , 0 ] , [ 11 , 2 ] ]
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe " "
expect ( editor . lineTextForBufferRow ( 10 ) ) . toBe " return sort(Array.apply(this, arguments)); "
expect ( editor . lineTextForBufferRow ( 11 ) ) . toBe " }; "
expect ( editor . lineTextForBufferRow ( 12 ) ) . toBe " }; "
2015-08-15 12:19:26 +03:00
describe " when there are multiple selections " , ->
describe " when all the selections span different lines " , ->
describe " when there is no folds " , ->
it " moves all lines that are spanned by a selection to the following row " , ->
editor . setSelectedBufferRanges ( [ [ [ 1 , 2 ] , [ 1 , 9 ] ] , [ [ 3 , 2 ] , [ 3 , 9 ] ] , [ [ 5 , 2 ] , [ 5 , 9 ] ] ] )
editor . moveLineDown ( )
2015-08-05 16:43:26 +03:00
2015-08-28 13:06:25 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 6 , 2 ] , [ 6 , 9 ] ] , [ [ 4 , 2 ] , [ 4 , 9 ] ] , [ [ 2 , 2 ] , [ 2 , 9 ] ] ]
2015-08-15 12:19:26 +03:00
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var sort = function(items) { "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " current < pivot ? left.push(current) : right.push(current); "
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe " current = items.shift(); "
2015-08-05 16:43:26 +03:00
2015-11-03 02:48:22 +03:00
describe ' when there are many folds ' , ->
beforeEach ->
waitsForPromise ->
atom . workspace . open ( ' sample-with-many-folds.js ' , autoIndent: false ) . then (o) -> editor = o
describe ' and many selections intersects folded rows ' , ->
it ' moves and preserves all the folds ' , ->
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 2 , 4 )
editor . foldBufferRowRange ( 7 , 9 )
2015-11-03 02:48:22 +03:00
editor . setSelectedBufferRanges ( [
[ [ 2 , 0 ] , [ 2 , 4 ] ] ,
[ [ 6 , 0 ] , [ 10 , 4 ] ]
] , preserveFolds: true )
editor . moveLineDown ( )
expect ( editor . lineTextForBufferRow ( 2 ) ) . toEqual " 6; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toEqual " function f3() { "
expect ( editor . lineTextForBufferRow ( 6 ) ) . toEqual " 12; "
expect ( editor . lineTextForBufferRow ( 7 ) ) . toEqual " 7; "
expect ( editor . lineTextForBufferRow ( 8 ) ) . toEqual " function f8() { "
expect ( editor . lineTextForBufferRow ( 11 ) ) . toEqual " 11; "
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 10 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 11 ) ) . toBeFalsy ( )
2015-10-12 23:10:09 +03:00
describe " when there is a fold below one of the selected row " , ->
it " moves all lines spanned by a selection to the following row, preserving the fold " , ->
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-08-05 16:43:26 +03:00
2015-08-15 12:19:26 +03:00
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
2015-08-05 16:43:26 +03:00
2015-08-15 12:19:26 +03:00
editor . setSelectedBufferRanges ( [ [ [ 1 , 2 ] , [ 1 , 6 ] ] , [ [ 3 , 0 ] , [ 3 , 4 ] ] , [ [ 8 , 0 ] , [ 8 , 3 ] ] ] )
editor . moveLineDown ( )
2015-08-05 16:43:26 +03:00
2015-08-28 13:06:25 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 9 , 0 ] , [ 9 , 3 ] ] , [ [ 7 , 0 ] , [ 7 , 4 ] ] , [ [ 2 , 2 ] , [ 2 , 6 ] ] ]
2015-08-15 12:19:26 +03:00
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var sort = function(items) { "
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeFalsy ( )
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
2015-08-05 16:43:26 +03:00
2015-10-12 23:10:09 +03:00
describe " when there is a fold below a group of multiple selections without any lines with no selection in-between " , ->
it " moves all the lines below the fold, preserving the fold " , ->
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-10-12 23:10:09 +03:00
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
editor . setSelectedBufferRanges ( [ [ [ 2 , 2 ] , [ 2 , 6 ] ] , [ [ 3 , 0 ] , [ 3 , 4 ] ] ] )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 7 , 0 ] , [ 7 , 4 ] ] , [ [ 6 , 2 ] , [ 6 , 6 ] ] ]
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " while(items.length > 0) { "
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeFalsy ( )
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
2015-10-12 23:05:25 +03:00
2015-11-03 01:43:43 +03:00
describe " when one selection intersects a fold " , ->
it " moves the lines to the previous row without breaking the fold " , ->
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(items.length > 0) { "
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 4 , 7 )
2015-11-03 01:43:43 +03:00
editor . setSelectedBufferRanges ( [
[ [ 2 , 2 ] , [ 2 , 9 ] ] ,
[ [ 4 , 2 ] , [ 4 , 9 ] ]
] , preserveFolds: true )
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
editor . moveLineDown ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual ( [
[ [ 5 , 2 ] , [ 5 , 9 ] ]
[ [ 3 , 2 ] , [ 3 , 9 ] ] ,
] )
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " if (items.length <= 1) return items; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
2014-03-06 08:32:11 +04:00
2015-11-03 01:43:43 +03:00
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe " }; "
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 3 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 5 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 6 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 7 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 8 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeFalsy ( )
2015-08-15 12:19:26 +03:00
describe " when some of the selections span the same lines " , ->
it " moves lines that contain multiple selections correctly " , ->
editor . setSelectedBufferRanges ( [ [ [ 3 , 2 ] , [ 3 , 9 ] ] , [ [ 3 , 12 ] , [ 3 , 13 ] ] ] )
editor . moveLineDown ( )
2015-08-05 16:43:26 +03:00
2015-08-28 13:06:25 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 4 , 12 ] , [ 4 , 13 ] ] , [ [ 4 , 2 ] , [ 4 , 9 ] ] ]
2015-08-15 12:19:26 +03:00
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " while(items.length > 0) { "
2015-08-05 16:43:26 +03:00
2015-10-11 19:15:06 +03:00
describe " when the selections are above a wrapped line " , ->
beforeEach ->
editor . setSoftWrapped ( true )
editor . setEditorWidthInChars ( 80 )
editor . setText ( """
1
2
Lorem ipsum dolor sit amet , consectetuer adipiscing elit , sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat . Ut wisi enim ad minim veniam , quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat .
3
4
""" )
2014-03-06 08:32:11 +04:00
2015-10-11 19:15:06 +03:00
it ' moves the lines past the soft wrapped line ' , ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 0 ] , [ 0 , 0 ] ] , [ [ 1 , 0 ] , [ 1 , 0 ] ] ] )
2014-04-23 04:52:28 +04:00
2015-10-11 19:15:06 +03:00
editor . moveLineDown ( )
expect ( editor . lineTextForBufferRow ( 0 ) ) . not . toBe " 2 "
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe " 1 "
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " 2 "
2014-03-06 08:32:11 +04:00
2016-05-03 12:50:02 +03:00
describe " when the line is the last buffer row " , ->
it " doesn ' t move it " , ->
editor . setText ( " abc \n def " )
editor . setCursorBufferPosition ( [ 1 , 0 ] )
editor . moveLineDown ( )
expect ( editor . getText ( ) ) . toBe ( " abc \n def " )
2014-03-06 08:32:11 +04:00
describe " .insertText(text) " , ->
2014-07-31 01:40:25 +04:00
describe " when there is a single selection " , ->
beforeEach ->
editor . setSelectedBufferRange ( [ [ 1 , 0 ] , [ 1 , 2 ] ] )
2014-09-04 19:18:29 +04:00
it " replaces the selection with the given text " , ->
2014-07-31 01:40:25 +04:00
range = editor . insertText ( ' xxx ' )
expect ( range ) . toEqual [ [ [ 1 , 0 ] , [ 1 , 3 ] ] ]
expect ( buffer . lineForRow ( 1 ) ) . toBe ' xxxvar sort = function(items) { '
2014-03-06 08:32:11 +04:00
describe " when there are multiple empty selections " , ->
describe " when the cursors are on the same line " , ->
it " inserts the given text at the location of each cursor and moves the cursors to the end of each cursor ' s inserted text " , ->
editor . setCursorScreenPosition ( [ 1 , 2 ] )
editor . addCursorAtScreenPosition ( [ 1 , 5 ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
editor . insertText ( ' xxx ' )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' xxxvarxxx sort = function(items) { '
[ cursor1 , cursor2 ] = editor . getCursors ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 1 , 5 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 11 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursors are on different lines " , ->
it " inserts the given text at the location of each cursor and moves the cursors to the end of each cursor ' s inserted text " , ->
editor . setCursorScreenPosition ( [ 1 , 2 ] )
editor . addCursorAtScreenPosition ( [ 2 , 4 ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
editor . insertText ( ' xxx ' )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' xxxvar sort = function(items) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' xxxif (items.length <= 1) return items; '
[ cursor1 , cursor2 ] = editor . getCursors ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 1 , 5 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 2 , 7 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when there are multiple non-empty selections " , ->
describe " when the selections are on the same line " , ->
it " replaces each selection range with the inserted characters " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 0 , 22 ] , [ 0 , 24 ] ] ] )
2014-03-06 08:32:11 +04:00
editor . insertText ( " x " )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
[ selection1 , selection2 ] = editor . getSelections ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( cursor1 . getScreenPosition ( ) ) . toEqual [ 0 , 5 ]
expect ( cursor2 . getScreenPosition ( ) ) . toEqual [ 0 , 15 ]
expect ( selection1 . isEmpty ( ) ) . toBeTruthy ( )
expect ( selection2 . isEmpty ( ) ) . toBeTruthy ( )
2013-09-13 21:49:01 +04:00
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe " var x = functix () { "
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the selections are on different lines " , ->
it " replaces each selection with the given text, clears the selections, and places the cursor at the end of each selection ' s inserted text " , ->
editor . setSelectedBufferRanges ( [ [ [ 1 , 0 ] , [ 1 , 2 ] ] , [ [ 2 , 0 ] , [ 2 , 4 ] ] ] )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . insertText ( ' xxx ' )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' xxxvar sort = function(items) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' xxxif (items.length <= 1) return items; '
[ selection1 , selection2 ] = editor . getSelections ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( selection1 . isEmpty ( ) ) . toBeTruthy ( )
expect ( selection1 . cursor . getBufferPosition ( ) ) . toEqual [ 1 , 3 ]
expect ( selection2 . isEmpty ( ) ) . toBeTruthy ( )
expect ( selection2 . cursor . getBufferPosition ( ) ) . toEqual [ 2 , 3 ]
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when there is a selection that ends on a folded line " , ->
it " destroys the selection " , ->
2016-01-01 01:23:05 +03:00
editor . foldBufferRowRange ( 2 , 4 )
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 1 , 0 ] , [ 2 , 0 ] ] )
2014-03-06 08:32:11 +04:00
editor . insertText ( ' holy cow ' )
2016-03-22 18:05:38 +03:00
expect ( editor . isFoldedAtScreenRow ( 2 ) ) . toBeFalsy ( )
2012-08-28 02:36:36 +04:00
2014-09-04 19:18:29 +04:00
describe " when there are ::onWillInsertText and ::onDidInsertText observers " , ->
2014-07-31 00:56:09 +04:00
beforeEach ->
editor . setSelectedBufferRange ( [ [ 1 , 0 ] , [ 1 , 2 ] ] )
2014-09-04 19:18:29 +04:00
it " notifies the observers when inserting text " , ->
2014-07-31 00:56:09 +04:00
willInsertSpy = jasmine . createSpy ( ) . andCallFake ->
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(items) { '
didInsertSpy = jasmine . createSpy ( ) . andCallFake ->
expect ( buffer . lineForRow ( 1 ) ) . toBe ' xxxvar sort = function(items) { '
2014-09-04 19:18:29 +04:00
editor . onWillInsertText ( willInsertSpy )
editor . onDidInsertText ( didInsertSpy )
2014-07-31 00:56:09 +04:00
2014-07-31 01:40:25 +04:00
expect ( editor . insertText ( ' xxx ' ) ) . toBeTruthy ( )
2014-07-31 00:56:09 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' xxxvar sort = function(items) { '
expect ( willInsertSpy ) . toHaveBeenCalled ( )
expect ( didInsertSpy ) . toHaveBeenCalled ( )
options = willInsertSpy . mostRecentCall . args [ 0 ]
expect ( options . text ) . toBe ' xxx '
2014-08-13 02:44:58 +04:00
expect ( options . cancel ) . toBeDefined ( )
2014-07-31 00:56:09 +04:00
options = didInsertSpy . mostRecentCall . args [ 0 ]
expect ( options . text ) . toBe ' xxx '
2014-09-04 19:18:29 +04:00
it " cancels text insertion when an ::onWillInsertText observer calls cancel on an event " , ->
2014-08-13 02:44:58 +04:00
willInsertSpy = jasmine . createSpy ( ) . andCallFake ({cancel}) ->
cancel ( )
2014-07-31 00:56:09 +04:00
didInsertSpy = jasmine . createSpy ( )
2014-09-04 19:18:29 +04:00
editor . onWillInsertText ( willInsertSpy )
editor . onDidInsertText ( didInsertSpy )
2014-07-31 00:56:09 +04:00
expect ( editor . insertText ( ' xxx ' ) ) . toBe false
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(items) { '
expect ( willInsertSpy ) . toHaveBeenCalled ( )
expect ( didInsertSpy ) . not . toHaveBeenCalled ( )
2014-10-31 21:38:24 +03:00
describe " when the undo option is set to ' skip ' " , ->
beforeEach ->
editor . setSelectedBufferRange ( [ [ 1 , 2 ] , [ 1 , 2 ] ] )
2014-10-31 21:39:56 +03:00
it " does not undo the skipped operation " , ->
2014-10-31 21:38:24 +03:00
range = editor . insertText ( ' x ' )
range = editor . insertText ( ' y ' , undo: ' skip ' )
editor . undo ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' yvar sort = function(items) { '
2014-03-06 08:32:11 +04:00
describe " .insertNewline() " , ->
describe " when there is a single cursor " , ->
describe " when the cursor is at the beginning of a line " , ->
it " inserts an empty line before it " , ->
editor . setCursorScreenPosition ( row: 1 , column: 0 )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . insertNewline ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' '
expect ( editor . getCursorScreenPosition ( ) ) . toEqual ( row: 2 , column: 0 )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is in the middle of a line " , ->
it " splits the current line to form a new line " , ->
editor . setCursorScreenPosition ( row: 1 , column: 6 )
originalLine = buffer . lineForRow ( 1 )
lineBelowOriginalLine = buffer . lineForRow ( 2 )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . insertNewline ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe originalLine [ 0 . . . 6 ]
expect ( buffer . lineForRow ( 2 ) ) . toBe originalLine [ 6 . . ]
expect ( buffer . lineForRow ( 3 ) ) . toBe lineBelowOriginalLine
expect ( editor . getCursorScreenPosition ( ) ) . toEqual ( row: 2 , column: 0 )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is on the end of a line " , ->
it " inserts an empty line after it " , ->
editor . setCursorScreenPosition ( row: 1 , column: buffer . lineForRow ( 1 ) . length )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . insertNewline ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 2 ) ) . toBe ' '
expect ( editor . getCursorScreenPosition ( ) ) . toEqual ( row: 2 , column: 0 )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when there are multiple cursors " , ->
describe " when the cursors are on the same line " , ->
it " breaks the line at the cursor locations " , ->
editor . setCursorScreenPosition ( [ 3 , 13 ] )
editor . addCursorAtScreenPosition ( [ 3 , 38 ] )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . insertNewline ( )
2013-09-13 21:49:01 +04:00
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " = items.shift(), current "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " , left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe " while(items.length > 0) { "
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 4 , 0 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 5 , 0 ]
describe " when the cursors are on different lines " , ->
it " inserts newlines at each cursor location " , ->
editor . setCursorScreenPosition ( [ 3 , 0 ] )
editor . addCursorAtScreenPosition ( [ 6 , 0 ] )
editor . insertText ( " \n " )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe " current = items.shift(); "
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " "
expect ( editor . lineTextForBufferRow ( 8 ) ) . toBe " current < pivot ? left.push(current) : right.push(current); "
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe " } "
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 4 , 0 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 8 , 0 ]
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " .insertNewlineBelow() " , ->
describe " when the operation is undone " , ->
it " places the cursor back at the previous location " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorBufferPosition ( [ 0 , 2 ] )
2014-03-06 08:32:11 +04:00
editor . insertNewlineBelow ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 0 ]
2014-03-06 08:32:11 +04:00
editor . undo ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 2 ]
2014-03-06 08:32:11 +04:00
it " inserts a newline below the cursor ' s current line, autoindents it, and moves the cursor to the end of the line " , ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2014-03-06 08:32:11 +04:00
editor . insertNewlineBelow ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " "
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 2 ]
describe " .insertNewlineAbove() " , ->
describe " when the cursor is on first line " , ->
it " inserts a newline on the first line and moves the cursor to the first line " , ->
editor . setCursorBufferPosition ( [ 0 ] )
editor . insertNewlineAbove ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' '
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe ' var quicksort = function () { '
2014-03-06 08:32:11 +04:00
expect ( editor . buffer . getLineCount ( ) ) . toBe 14
describe " when the cursor is not on the first line " , ->
it " inserts a newline above the current line and moves the cursor to the inserted line " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorBufferPosition ( [ 3 , 4 ] )
2014-03-06 08:32:11 +04:00
editor . insertNewlineAbove ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 3 , 0 ]
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe ' '
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe ' var pivot = items.shift(), current, left = [], right = []; '
2014-03-06 08:32:11 +04:00
expect ( editor . buffer . getLineCount ( ) ) . toBe 14
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . undo ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 3 , 4 ]
2013-09-13 21:49:01 +04:00
2014-04-11 21:05:56 +04:00
it " indents the new line to the correct level when editor.autoIndent is true " , ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2014-04-04 21:22:09 +04:00
editor . setText ( ' var test ' )
2015-05-23 02:50:04 +03:00
editor . setCursorBufferPosition ( [ 0 , 2 ] )
2014-04-04 21:22:09 +04:00
editor . insertNewlineAbove ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 2 ]
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' '
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe ' var test '
2014-04-04 21:22:09 +04:00
2014-04-04 21:02:24 +04:00
editor . setText ( ' \n var test ' )
2015-05-23 02:50:04 +03:00
editor . setCursorBufferPosition ( [ 1 , 2 ] )
2014-04-04 21:02:24 +04:00
editor . insertNewlineAbove ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 2 ]
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' '
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe ' '
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe ' var test '
2014-04-04 21:02:24 +04:00
2014-04-11 21:05:56 +04:00
editor . setText ( ' function() { \n } ' )
2015-05-23 02:50:04 +03:00
editor . setCursorBufferPosition ( [ 1 , 1 ] )
2014-04-11 21:05:56 +04:00
editor . insertNewlineAbove ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 2 ]
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' function() { '
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe ' '
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe ' } '
2014-04-11 21:05:56 +04:00
2015-05-15 14:08:40 +03:00
describe " .insertNewLine() " , ->
describe " when a new line is appended before a closing tag (e.g. by pressing enter before a selection) " , ->
it " moves the line down and keeps the indentation level the same when editor.autoIndent is true " , ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2015-05-15 14:08:40 +03:00
editor . setCursorBufferPosition ( [ 9 , 2 ] )
editor . insertNewline ( )
expect ( editor . lineTextForBufferRow ( 10 ) ) . toBe ' }; '
describe " when a newline is appended with a trailing closing tag behind the cursor (e.g. by pressing enter in the middel of a line) " , ->
it " indents the new line to the correct level when editor.autoIndent is true and using a curly-bracket language " , ->
waitsForPromise ->
atom . packages . activatePackage ( ' language-javascript ' )
runs ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2015-05-15 14:08:40 +03:00
editor . setGrammar ( atom . grammars . selectGrammar ( " file.js " ) )
editor . setText ( ' var test = function () { \n return true;}; ' )
editor . setCursorBufferPosition ( [ 1 , 14 ] )
editor . insertNewline ( )
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 1
expect ( editor . indentationForBufferRow ( 2 ) ) . toBe 0
2015-07-23 20:23:03 +03:00
it " indents the new line to the current level when editor.autoIndent is true and no increaseIndentPattern is specified " , ->
runs ->
editor . setGrammar ( atom . grammars . selectGrammar ( " file " ) )
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2015-07-23 20:23:03 +03:00
editor . setText ( ' if true ' )
editor . setCursorBufferPosition ( [ 0 , 8 ] )
editor . insertNewline ( )
expect ( editor . getGrammar ( ) ) . toBe atom . grammars . nullGrammar
expect ( editor . indentationForBufferRow ( 0 ) ) . toBe 1
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 1
2016-03-31 05:56:34 +03:00
it " indents the new line to the correct level when editor.autoIndent is true and using an off-side rule language " , ->
2015-05-15 14:08:40 +03:00
waitsForPromise ->
atom . packages . activatePackage ( ' language-coffee-script ' )
runs ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2015-05-15 14:08:40 +03:00
editor . setGrammar ( atom . grammars . selectGrammar ( " file.coffee " ) )
editor . setText ( ' if true \n return trueelse \n return false ' )
editor . setCursorBufferPosition ( [ 1 , 13 ] )
editor . insertNewline ( )
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 1
expect ( editor . indentationForBufferRow ( 2 ) ) . toBe 0
expect ( editor . indentationForBufferRow ( 3 ) ) . toBe 1
2015-07-12 23:51:46 +03:00
describe " when a newline is appended on a line that matches the decreaseNextIndentPattern " , ->
2015-05-15 14:08:40 +03:00
it " indents the new line to the correct level when editor.autoIndent is true " , ->
waitsForPromise ->
atom . packages . activatePackage ( ' language-go ' )
runs ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2015-05-15 14:08:40 +03:00
editor . setGrammar ( atom . grammars . selectGrammar ( " file.go " ) )
editor . setText ( ' fmt.Printf( " some%s " , \n " thing " ) ' )
editor . setCursorBufferPosition ( [ 1 , 10 ] )
editor . insertNewline ( )
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 1
expect ( editor . indentationForBufferRow ( 2 ) ) . toBe 0
2014-06-04 05:05:30 +04:00
2014-03-06 08:32:11 +04:00
describe " .backspace() " , ->
describe " when there is a single cursor " , ->
changeScreenRangeHandler = null
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
beforeEach ->
selection = editor . getLastSelection ( )
changeScreenRangeHandler = jasmine . createSpy ( ' changeScreenRangeHandler ' )
2014-09-05 00:40:12 +04:00
selection . onDidChangeRange changeScreenRangeHandler
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is on the middle of the line " , ->
it " removes the character before the cursor " , ->
editor . setCursorScreenPosition ( row: 1 , column: 7 )
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) { "
editor . backspace ( )
line = buffer . lineForRow ( 1 )
expect ( line ) . toBe " var ort = function(items) { "
expect ( editor . getCursorScreenPosition ( ) ) . toEqual { row: 1 , column: 6 }
expect ( changeScreenRangeHandler ) . toHaveBeenCalled ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is at the beginning of a line " , ->
it " joins it with the line above " , ->
originalLine0 = buffer . lineForRow ( 0 )
expect ( originalLine0 ) . toBe " var quicksort = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) { "
2013-11-20 03:22:47 +04:00
2014-03-06 08:32:11 +04:00
editor . setCursorScreenPosition ( row: 1 , column: 0 )
editor . backspace ( )
2013-11-20 03:22:47 +04:00
2014-03-06 08:32:11 +04:00
line0 = buffer . lineForRow ( 0 )
line1 = buffer . lineForRow ( 1 )
expect ( line0 ) . toBe " var quicksort = function () { var sort = function(items) { "
expect ( line1 ) . toBe " if (items.length <= 1) return items; "
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 0 , originalLine0 . length ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( changeScreenRangeHandler ) . toHaveBeenCalled ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is at the first column of the first line " , ->
it " does nothing, but doesn ' t raise an error " , ->
editor . setCursorScreenPosition ( row: 0 , column: 0 )
editor . backspace ( )
2012-08-28 02:36:36 +04:00
2016-03-24 15:43:42 +03:00
describe " when the cursor is after a fold " , ->
it " deletes the folded range " , ->
editor . foldBufferRange ( [ [ 4 , 7 ] , [ 5 , 8 ] ] )
editor . setCursorBufferPosition ( [ 5 , 8 ] )
2014-03-06 08:32:11 +04:00
editor . backspace ( )
2012-08-28 02:36:36 +04:00
2016-03-24 15:43:42 +03:00
expect ( buffer . lineForRow ( 4 ) ) . toBe " whirrent = items.shift(); "
expect ( editor . isFoldedAtBufferRow ( 4 ) ) . toBe ( false )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is in the middle of a line below a fold " , ->
it " backspaces as normal " , ->
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition ( [ 4 , 0 ] )
2014-03-06 08:32:11 +04:00
editor . foldCurrentRow ( )
2015-05-23 02:50:04 +03:00
editor . setCursorScreenPosition ( [ 5 , 5 ] )
2014-03-06 08:32:11 +04:00
editor . backspace ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 7 ) ) . toBe " } "
expect ( buffer . lineForRow ( 8 ) ) . toBe " eturn sort(left).concat(pivot).concat(sort(right)); "
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is on a folded screen line " , ->
2016-03-24 15:43:42 +03:00
it " deletes the contents of the fold before the cursor " , ->
2014-03-06 08:32:11 +04:00
editor . setCursorBufferPosition ( [ 3 , 0 ] )
editor . foldCurrentRow ( )
editor . backspace ( )
2012-10-30 21:55:00 +04:00
2016-03-24 15:43:42 +03:00
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 1 , 29 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when there are multiple cursors " , ->
describe " when cursors are on the same line " , ->
it " removes the characters preceding each cursor " , ->
editor . setCursorScreenPosition ( [ 3 , 13 ] )
editor . addCursorAtScreenPosition ( [ 3 , 38 ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
editor . backspace ( )
2012-12-29 05:24:47 +04:00
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivo = items.shift(), curren, left = [], right = []; "
2012-12-29 05:24:47 +04:00
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 3 , 12 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 3 , 36 ]
2012-12-29 05:24:47 +04:00
2014-03-06 08:32:11 +04:00
[ selection1 , selection2 ] = editor . getSelections ( )
expect ( selection1 . isEmpty ( ) ) . toBeTruthy ( )
expect ( selection2 . isEmpty ( ) ) . toBeTruthy ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when cursors are on different lines " , ->
describe " when the cursors are in the middle of their lines " , ->
2013-09-13 21:49:01 +04:00
it " removes the characters preceding each cursor " , ->
2013-11-20 03:22:47 +04:00
editor . setCursorScreenPosition ( [ 3 , 13 ] )
2014-03-06 08:32:11 +04:00
editor . addCursorAtScreenPosition ( [ 4 , 10 ] )
2012-08-28 02:36:36 +04:00
2013-11-20 03:22:47 +04:00
editor . backspace ( )
2012-08-28 02:36:36 +04:00
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivo = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " whileitems.length > 0) { "
2012-08-28 02:36:36 +04:00
2013-11-20 03:22:47 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
2013-09-13 21:49:01 +04:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 3 , 12 ]
2014-03-06 08:32:11 +04:00
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 4 , 9 ]
2012-08-28 02:36:36 +04:00
2013-11-20 03:22:47 +04:00
[ selection1 , selection2 ] = editor . getSelections ( )
2013-09-13 21:49:01 +04:00
expect ( selection1 . isEmpty ( ) ) . toBeTruthy ( )
expect ( selection2 . isEmpty ( ) ) . toBeTruthy ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursors are on the first column of their lines " , ->
it " removes the newlines preceding each cursor " , ->
editor . setCursorScreenPosition ( [ 3 , 0 ] )
editor . addCursorAtScreenPosition ( [ 6 , 0 ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
editor . backspace ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " if (items.length <= 1) return items; var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " current = items.shift(); current < pivot ? left.push(current) : right.push(current); "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " } "
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 2 , 40 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 4 , 30 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when there is a single selection " , ->
it " deletes the selection, but not the character before it " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 5 ] , [ 0 , 9 ] ] )
2014-03-06 08:32:11 +04:00
editor . backspace ( )
expect ( editor . buffer . lineForRow ( 0 ) ) . toBe ' var qsort = function () { '
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when the selection ends on a folded line " , ->
it " preserves the fold " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 3 , 0 ] , [ 4 , 0 ] ] )
2014-03-06 08:32:11 +04:00
editor . foldBufferRow ( 4 )
editor . backspace ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 3 ) ) . toBe " while(items.length > 0) { "
2016-03-24 15:43:42 +03:00
expect ( editor . isFoldedAtScreenRow ( 3 ) ) . toBe ( true )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when there are multiple selections " , ->
it " removes all selected text " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 0 , 16 ] , [ 0 , 24 ] ] ] )
2014-03-06 08:32:11 +04:00
editor . backspace ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' var = () { '
2013-09-13 21:49:01 +04:00
2015-04-30 04:16:49 +03:00
describe " .deleteToPreviousWordBoundary() " , ->
2015-03-25 03:50:16 +03:00
describe " when no text is selected " , ->
it " deletes to the previous word boundary " , ->
editor . setCursorBufferPosition ( [ 0 , 16 ] )
editor . addCursorAtBufferPosition ( [ 1 , 21 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
editor . deleteToPreviousWordBoundary ( )
2015-04-30 03:52:38 +03:00
expect ( buffer . lineForRow ( 0 ) ) . toBe ' var quicksort =function () { '
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = (items) { '
2015-03-25 03:50:16 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 15 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 13 ]
editor . deleteToPreviousWordBoundary ( )
2015-04-30 03:52:38 +03:00
expect ( buffer . lineForRow ( 0 ) ) . toBe ' var quicksort function () { '
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort =(items) { '
2015-03-25 03:50:16 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 14 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 12 ]
describe " when text is selected " , ->
it " deletes only selected text " , ->
editor . setSelectedBufferRange ( [ [ 1 , 24 ] , [ 1 , 27 ] ] )
2015-04-30 03:09:32 +03:00
editor . deleteToPreviousWordBoundary ( )
2015-03-25 03:50:16 +03:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it) { '
2015-04-30 04:16:49 +03:00
describe " .deleteToNextWordBoundary() " , ->
2015-03-25 03:50:16 +03:00
describe " when no text is selected " , ->
it " deletes to the next word boundary " , ->
editor . setCursorBufferPosition ( [ 0 , 15 ] )
editor . addCursorAtBufferPosition ( [ 1 , 24 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
editor . deleteToNextWordBoundary ( )
2015-04-30 03:52:38 +03:00
expect ( buffer . lineForRow ( 0 ) ) . toBe ' var quicksort =function () { '
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it) { '
2015-03-25 03:50:16 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 15 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 24 ]
editor . deleteToNextWordBoundary ( )
2015-04-30 03:52:38 +03:00
expect ( buffer . lineForRow ( 0 ) ) . toBe ' var quicksort = () { '
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it { '
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 15 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 24 ]
2015-03-25 03:50:16 +03:00
editor . deleteToNextWordBoundary ( )
2015-04-30 04:14:16 +03:00
expect ( buffer . lineForRow ( 0 ) ) . toBe ' var quicksort =() { '
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it{ '
2015-04-30 03:52:38 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 15 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 1 , 24 ]
2015-03-25 03:50:16 +03:00
describe " when text is selected " , ->
it " deletes only selected text " , ->
editor . setSelectedBufferRange ( [ [ 1 , 24 ] , [ 1 , 27 ] ] )
2015-04-30 03:09:32 +03:00
editor . deleteToNextWordBoundary ( )
2015-03-25 03:50:16 +03:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it) { '
2014-05-12 02:40:49 +04:00
describe " .deleteToBeginningOfWord() " , ->
2014-03-06 08:32:11 +04:00
describe " when no text is selected " , ->
it " deletes all text between the cursor and the beginning of the word " , ->
editor . setCursorBufferPosition ( [ 1 , 24 ] )
editor . addCursorAtBufferPosition ( [ 3 , 5 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
2013-09-13 21:49:01 +04:00
2014-05-12 02:40:49 +04:00
editor . deleteToBeginningOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(ems) { '
expect ( buffer . lineForRow ( 3 ) ) . toBe ' ar pivot = items.shift(), current, left = [], right = []; '
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 1 , 22 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 3 , 4 ]
2013-09-13 21:49:01 +04:00
2014-05-12 02:40:49 +04:00
editor . deleteToBeginningOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = functionems) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.length <= 1) return itemsar pivot = items.shift(), current, left = [], right = []; '
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 1 , 21 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 2 , 39 ]
2013-09-13 21:49:01 +04:00
2014-05-12 02:40:49 +04:00
editor . deleteToBeginningOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = ems) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.length <= 1) return ar pivot = items.shift(), current, left = [], right = []; '
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 1 , 13 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 2 , 34 ]
2013-09-13 21:49:01 +04:00
2014-04-03 23:04:22 +04:00
editor . setText ( ' var sort ' )
editor . setCursorBufferPosition ( [ 0 , 2 ] )
2014-05-12 02:40:49 +04:00
editor . deleteToBeginningOfWord ( )
2014-04-03 23:04:22 +04:00
expect ( buffer . lineForRow ( 0 ) ) . toBe ' var sort '
2014-03-06 08:32:11 +04:00
describe " when text is selected " , ->
it " deletes only selected text " , ->
editor . setSelectedBufferRanges ( [ [ [ 1 , 24 ] , [ 1 , 27 ] ] , [ [ 2 , 0 ] , [ 2 , 4 ] ] ] )
2014-05-12 02:40:49 +04:00
editor . deleteToBeginningOfWord ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.length <= 1) return items; '
2012-08-28 02:36:36 +04:00
2014-06-15 09:38:11 +04:00
describe ' .deleteToEndOfLine() ' , ->
describe ' when no text is selected ' , ->
it ' deletes all text between the cursor and the end of the line ' , ->
editor . setCursorBufferPosition ( [ 1 , 24 ] )
editor . addCursorAtBufferPosition ( [ 2 , 5 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
editor . deleteToEndOfLine ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' i '
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 1 , 24 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 2 , 5 ]
describe ' when at the end of the line ' , ->
it ' deletes the next newline ' , ->
editor . setCursorBufferPosition ( [ 1 , 30 ] )
editor . deleteToEndOfLine ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(items) { if (items.length <= 1) return items; '
describe ' when text is selected ' , ->
2014-06-17 01:13:40 +04:00
it ' deletes only the text in the selection ' , ->
2014-06-15 09:38:11 +04:00
editor . setSelectedBufferRanges ( [ [ [ 1 , 24 ] , [ 1 , 27 ] ] , [ [ 2 , 0 ] , [ 2 , 4 ] ] ] )
editor . deleteToEndOfLine ( )
2014-06-17 01:13:40 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.length <= 1) return items; '
2014-06-15 09:38:11 +04:00
2014-05-16 23:05:05 +04:00
describe " .deleteToBeginningOfLine() " , ->
2014-03-06 08:32:11 +04:00
describe " when no text is selected " , ->
it " deletes all text between the cursor and the beginning of the line " , ->
editor . setCursorBufferPosition ( [ 1 , 24 ] )
editor . addCursorAtBufferPosition ( [ 2 , 5 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
2012-08-28 02:36:36 +04:00
2014-05-16 23:05:05 +04:00
editor . deleteToBeginningOfLine ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' ems) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' f (items.length <= 1) return items; '
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 1 , 0 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 2 , 0 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when at the beginning of the line " , ->
it " deletes the newline " , ->
editor . setCursorBufferPosition ( [ 2 ] )
2014-05-16 23:05:05 +04:00
editor . deleteToBeginningOfLine ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(items) { if (items.length <= 1) return items; '
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when text is selected " , ->
it " still deletes all text to begginning of the line " , ->
editor . setSelectedBufferRanges ( [ [ [ 1 , 24 ] , [ 1 , 27 ] ] , [ [ 2 , 0 ] , [ 2 , 4 ] ] ] )
2014-05-16 23:05:05 +04:00
editor . deleteToBeginningOfLine ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe ' ems) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.length <= 1) return items; '
describe " .delete() " , ->
describe " when there is a single cursor " , ->
describe " when the cursor is on the middle of a line " , ->
it " deletes the character following the cursor " , ->
editor . setCursorScreenPosition ( [ 1 , 6 ] )
editor . delete ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var ort = function(items) { '
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is on the end of a line " , ->
it " joins the line with the following line " , ->
editor . setCursorScreenPosition ( [ 1 , buffer . lineForRow ( 1 ) . length ] )
editor . delete ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(items) { if (items.length <= 1) return items; '
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is on the last column of the last line " , ->
it " does nothing, but doesn ' t raise an error " , ->
editor . setCursorScreenPosition ( [ 12 , buffer . lineForRow ( 12 ) . length ] )
editor . delete ( )
expect ( buffer . lineForRow ( 12 ) ) . toBe ' }; '
2013-09-13 21:49:01 +04:00
2016-03-24 15:43:42 +03:00
describe " when the cursor is before a fold " , ->
2014-03-06 08:32:11 +04:00
it " only deletes the lines inside the fold " , ->
2016-03-24 15:43:42 +03:00
editor . foldBufferRange ( [ [ 3 , 6 ] , [ 4 , 8 ] ] )
editor . setCursorScreenPosition ( [ 3 , 6 ] )
2014-03-06 08:32:11 +04:00
cursorPositionBefore = editor . getCursorScreenPosition ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . delete ( )
2013-09-13 21:49:01 +04:00
2016-03-24 15:43:42 +03:00
expect ( buffer . lineForRow ( 3 ) ) . toBe " vae(items.length > 0) { "
expect ( buffer . lineForRow ( 4 ) ) . toBe " current = items.shift(); "
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual cursorPositionBefore
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when the cursor is in the middle a line above a fold " , ->
it " deletes as normal " , ->
editor . foldBufferRow ( 4 )
editor . setCursorScreenPosition ( [ 3 , 4 ] )
cursorPositionBefore = editor . getCursorScreenPosition ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . delete ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 3 ) ) . toBe " ar pivot = items.shift(), current, left = [], right = []; "
2016-03-24 15:43:42 +03:00
expect ( editor . isFoldedAtScreenRow ( 4 ) ) . toBe ( true )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 3 , 4 ]
2013-09-13 21:49:01 +04:00
2016-03-24 15:43:42 +03:00
describe " when the cursor is inside a fold " , ->
it " removes the folded content after the cursor " , ->
editor . foldBufferRange ( [ [ 2 , 6 ] , [ 6 , 21 ] ] )
editor . setCursorBufferPosition ( [ 4 , 9 ] )
2014-03-06 08:32:11 +04:00
editor . delete ( )
2016-03-24 15:43:42 +03:00
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.length <= 1) return items; '
expect ( buffer . lineForRow ( 3 ) ) . toBe ' var pivot = items.shift(), current, left = [], right = []; '
expect ( buffer . lineForRow ( 4 ) ) . toBe ' while ? left.push(current) : right.push(current); '
expect ( buffer . lineForRow ( 5 ) ) . toBe ' } '
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 4 , 9 ]
2014-03-06 08:32:11 +04:00
describe " when there are multiple cursors " , ->
describe " when cursors are on the same line " , ->
it " removes the characters following each cursor " , ->
editor . setCursorScreenPosition ( [ 3 , 13 ] )
editor . addCursorAtScreenPosition ( [ 3 , 38 ] )
editor . delete ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot= items.shift(), current left = [], right = []; "
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 3 , 13 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 3 , 37 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
[ selection1 , selection2 ] = editor . getSelections ( )
expect ( selection1 . isEmpty ( ) ) . toBeTruthy ( )
expect ( selection2 . isEmpty ( ) ) . toBeTruthy ( )
describe " when cursors are on different lines " , ->
describe " when the cursors are in the middle of the lines " , ->
2012-08-28 02:36:36 +04:00
it " removes the characters following each cursor " , ->
2013-11-20 03:22:47 +04:00
editor . setCursorScreenPosition ( [ 3 , 13 ] )
2014-03-06 08:32:11 +04:00
editor . addCursorAtScreenPosition ( [ 4 , 10 ] )
2012-08-28 02:36:36 +04:00
2013-11-20 03:22:47 +04:00
editor . delete ( )
2012-08-28 02:36:36 +04:00
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " var pivot= items.shift(), current, left = [], right = []; "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " while(tems.length > 0) { "
2012-08-28 02:36:36 +04:00
2013-11-20 03:22:47 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
2012-08-28 02:36:36 +04:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 3 , 13 ]
2014-03-06 08:32:11 +04:00
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 4 , 10 ]
2012-08-28 02:36:36 +04:00
2013-11-20 03:22:47 +04:00
[ selection1 , selection2 ] = editor . getSelections ( )
2012-08-28 02:36:36 +04:00
expect ( selection1 . isEmpty ( ) ) . toBeTruthy ( )
expect ( selection2 . isEmpty ( ) ) . toBeTruthy ( )
2014-03-06 08:32:11 +04:00
describe " when the cursors are at the end of their lines " , ->
it " removes the newlines following each cursor " , ->
editor . setCursorScreenPosition ( [ 0 , 29 ] )
editor . addCursorAtScreenPosition ( [ 1 , 30 ] )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
editor . delete ( )
2012-08-28 02:36:36 +04:00
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe " var quicksort = function () { var sort = function(items) { if (items.length <= 1) return items; "
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
[ cursor1 , cursor2 ] = editor . getCursors ( )
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 29 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 0 , 59 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when there is a single selection " , ->
it " deletes the selection, but not the character following it " , ->
editor . setSelectedBufferRanges ( [ [ [ 1 , 24 ] , [ 1 , 27 ] ] , [ [ 2 , 0 ] , [ 2 , 4 ] ] ] )
editor . delete ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.length <= 1) return items; '
2014-08-29 04:51:16 +04:00
expect ( editor . getLastSelection ( ) . isEmpty ( ) ) . toBeTruthy ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when there are multiple selections " , ->
describe " when selections are on the same line " , ->
it " removes all selected text " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 0 , 16 ] , [ 0 , 24 ] ] ] )
2014-03-06 08:32:11 +04:00
editor . delete ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' var = () { '
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " .deleteToEndOfWord() " , ->
describe " when no text is selected " , ->
it " deletes to the end of the word " , ->
editor . setCursorBufferPosition ( [ 1 , 24 ] )
editor . addCursorAtBufferPosition ( [ 2 , 5 ] )
[ cursor1 , cursor2 ] = editor . getCursors ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
editor . deleteToEndOfWord ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it) { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' i (items.length <= 1) return items; '
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 1 , 24 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 2 , 5 ]
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
editor . deleteToEndOfWord ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it { '
expect ( buffer . lineForRow ( 2 ) ) . toBe ' iitems.length <= 1) return items; '
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 1 , 24 ]
expect ( cursor2 . getBufferPosition ( ) ) . toEqual [ 2 , 5 ]
2012-10-26 02:56:18 +04:00
2014-03-06 08:32:11 +04:00
describe " when text is selected " , ->
it " deletes only selected text " , ->
editor . setSelectedBufferRange ( [ [ 1 , 24 ] , [ 1 , 27 ] ] )
editor . deleteToEndOfWord ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var sort = function(it) { '
describe " .indent() " , ->
describe " when the selection is empty " , ->
describe " when autoIndent is disabled " , ->
describe " if ' softTabs ' is true (the default) " , ->
it " inserts ' tabLength ' spaces into the buffer " , ->
tabRegex = new RegExp ( " ^[ ]{ #{ editor . getTabLength ( ) } } " )
expect ( buffer . lineForRow ( 0 ) ) . not . toMatch ( tabRegex )
editor . indent ( )
expect ( buffer . lineForRow ( 0 ) ) . toMatch ( tabRegex )
2013-09-13 21:49:01 +04:00
2014-07-12 04:03:42 +04:00
it " respects the tab stops when cursor is in the middle of a tab " , ->
editor . setTabLength ( 4 )
buffer . insert ( [ 12 , 2 ] , " \n " )
editor . setCursorBufferPosition [ 13 , 1 ]
editor . indent ( )
expect ( buffer . lineForRow ( 13 ) ) . toMatch / ^ \ s + $ /
expect ( buffer . lineForRow ( 13 ) . length ) . toBe 4
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 13 , 4 ]
buffer . insert ( [ 13 , 0 ] , " " )
editor . setCursorBufferPosition [ 13 , 6 ]
editor . indent ( )
expect ( buffer . lineForRow ( 13 ) . length ) . toBe 8
2014-03-06 08:32:11 +04:00
describe " if ' softTabs ' is false " , ->
it " insert a \t into the buffer " , ->
editor . setSoftTabs ( false )
expect ( buffer . lineForRow ( 0 ) ) . not . toMatch ( /^\t/ )
editor . indent ( )
expect ( buffer . lineForRow ( 0 ) ) . toMatch ( /^\t/ )
describe " when autoIndent is enabled " , ->
describe " when the cursor ' s column is less than the suggested level of indentation " , ->
describe " when ' softTabs ' is true (the default) " , ->
it " moves the cursor to the end of the leading whitespace and inserts enough whitespace to bring the line to the suggested level of indentaion " , ->
buffer . insert ( [ 5 , 0 ] , " \n " )
editor . setCursorBufferPosition [ 5 , 0 ]
editor . indent ( autoIndent: true )
expect ( buffer . lineForRow ( 5 ) ) . toMatch / ^ \ s + $ /
expect ( buffer . lineForRow ( 5 ) . length ) . toBe 6
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 5 , 6 ]
2014-07-12 04:03:42 +04:00
it " respects the tab stops when cursor is in the middle of a tab " , ->
editor . setTabLength ( 4 )
buffer . insert ( [ 12 , 2 ] , " \n " )
editor . setCursorBufferPosition [ 13 , 1 ]
editor . indent ( autoIndent: true )
expect ( buffer . lineForRow ( 13 ) ) . toMatch / ^ \ s + $ /
expect ( buffer . lineForRow ( 13 ) . length ) . toBe 4
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 13 , 4 ]
buffer . insert ( [ 13 , 0 ] , " " )
editor . setCursorBufferPosition [ 13 , 6 ]
editor . indent ( autoIndent: true )
expect ( buffer . lineForRow ( 13 ) . length ) . toBe 8
2014-03-06 08:32:11 +04:00
describe " when ' softTabs ' is false " , ->
it " moves the cursor to the end of the leading whitespace and inserts enough tabs to bring the line to the suggested level of indentaion " , ->
convertToHardTabs ( buffer )
2013-11-20 03:22:47 +04:00
editor . setSoftTabs ( false )
2014-03-06 08:32:11 +04:00
buffer . insert ( [ 5 , 0 ] , " \t \n " )
editor . setCursorBufferPosition [ 5 , 0 ]
editor . indent ( autoIndent: true )
expect ( buffer . lineForRow ( 5 ) ) . toMatch / ^ \ t \ t \ t$ /
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 5 , 3 ]
2014-09-19 02:36:31 +04:00
describe " when the difference between the suggested level of indentation and the current level of indentation is greater than 0 but less than 1 " , ->
it " inserts one tab " , ->
editor . setSoftTabs ( false )
buffer . setText ( " \n test " )
editor . setCursorBufferPosition [ 1 , 0 ]
editor . indent ( autoIndent: true )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' \t test '
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 1 ]
2014-03-06 08:32:11 +04:00
describe " when the line ' s indent level is greater than the suggested level of indentation " , ->
describe " when ' softTabs ' is true (the default) " , ->
it " moves the cursor to the end of the leading whitespace and inserts ' tabLength ' spaces into the buffer " , ->
buffer . insert ( [ 7 , 0 ] , " \n " )
editor . setCursorBufferPosition [ 7 , 2 ]
editor . indent ( autoIndent: true )
expect ( buffer . lineForRow ( 7 ) ) . toMatch / ^ \ s + $ /
expect ( buffer . lineForRow ( 7 ) . length ) . toBe 8
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 7 , 8 ]
describe " when ' softTabs ' is false " , ->
it " moves the cursor to the end of the leading whitespace and inserts \t into the buffer " , ->
convertToHardTabs ( buffer )
editor . setSoftTabs ( false )
buffer . insert ( [ 7 , 0 ] , " \t \t \t \n " )
editor . setCursorBufferPosition [ 7 , 1 ]
editor . indent ( autoIndent: true )
expect ( buffer . lineForRow ( 7 ) ) . toMatch / ^ \ t \ t \ t \ t$ /
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 7 , 4 ]
describe " when the selection is not empty " , ->
it " indents the selected lines " , ->
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 10 , 0 ] ] )
2014-08-29 04:51:16 +04:00
selection = editor . getLastSelection ( )
2014-03-06 08:32:11 +04:00
spyOn ( selection , " indentSelectedRows " )
editor . indent ( )
expect ( selection . indentSelectedRows ) . toHaveBeenCalled ( )
describe " if editor.softTabs is false " , ->
it " inserts a tab character into the buffer " , ->
editor . setSoftTabs ( false )
expect ( buffer . lineForRow ( 0 ) ) . not . toMatch ( /^\t/ )
editor . indent ( )
expect ( buffer . lineForRow ( 0 ) ) . toMatch ( /^\t/ )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 1 ]
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 0 , editor . getTabLength ( ) ]
editor . indent ( )
expect ( buffer . lineForRow ( 0 ) ) . toMatch ( /^\t\t/ )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 2 ]
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 0 , editor . getTabLength ( ) * 2 ]
describe " clipboard operations " , ->
describe " .cutSelectedText() " , ->
it " removes the selected text from the buffer and places it on the clipboard " , ->
2014-11-18 04:47:22 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 1 , 6 ] , [ 1 , 10 ] ] ] )
2014-03-06 08:32:11 +04:00
editor . cutSelectedText ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " var = function(items) { "
expect ( clipboard . readText ( ) ) . toBe ' quicksort \n sort '
2012-08-28 02:36:36 +04:00
2014-11-11 20:44:08 +03:00
describe " when no text is selected " , ->
beforeEach ->
2014-11-18 04:47:22 +03:00
editor . setSelectedBufferRanges ( [
[ [ 0 , 0 ] , [ 0 , 0 ] ] ,
[ [ 5 , 0 ] , [ 5 , 0 ] ] ,
] )
2014-11-11 20:44:08 +03:00
it " cuts the lines on which there are cursors " , ->
editor . cutSelectedText ( )
expect ( buffer . getLineCount ( ) ) . toBe ( 11 )
expect ( buffer . lineForRow ( 1 ) ) . toBe ( " if (items.length <= 1) return items; " )
expect ( buffer . lineForRow ( 4 ) ) . toBe ( " current < pivot ? left.push(current) : right.push(current); " )
2014-11-18 06:23:02 +03:00
expect ( atom . clipboard . read ( ) ) . toEqual """
var quicksort = function ( ) {
current = items . shift ( ) ;
"""
2014-11-11 20:44:08 +03:00
2015-04-02 17:35:26 +03:00
describe " when many selections get added in shuffle order " , ->
it " cuts them in order " , ->
editor . setSelectedBufferRanges ( [
2015-05-23 02:50:04 +03:00
[ [ 2 , 8 ] , [ 2 , 13 ] ]
[ [ 0 , 4 ] , [ 0 , 13 ] ] ,
[ [ 1 , 6 ] , [ 1 , 10 ] ] ,
2015-04-02 17:35:26 +03:00
] )
editor . cutSelectedText ( )
expect ( atom . clipboard . read ( ) ) . toEqual """
quicksort
sort
items
"""
2014-03-06 08:32:11 +04:00
describe " .cutToEndOfLine() " , ->
describe " when soft wrap is on " , ->
it " cuts up to the end of the line " , ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2015-10-15 17:41:27 +03:00
editor . setDefaultCharWidth ( 1 )
2016-03-24 16:15:06 +03:00
editor . setEditorWidthInChars ( 25 )
editor . setCursorScreenPosition ( [ 2 , 6 ] )
2014-03-06 08:32:11 +04:00
editor . cutToEndOfLine ( )
2016-03-24 16:15:06 +03:00
expect ( editor . lineTextForScreenRow ( 2 ) ) . toBe ' var function(items) { '
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when soft wrap is off " , ->
describe " when nothing is selected " , ->
it " cuts up to the end of the line " , ->
editor . setCursorBufferPosition ( [ 2 , 20 ] )
editor . addCursorAtBufferPosition ( [ 3 , 20 ] )
editor . cutToEndOfLine ( )
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.length '
expect ( buffer . lineForRow ( 3 ) ) . toBe ' var pivot = item '
expect ( atom . clipboard . read ( ) ) . toBe ' <= 1) return items; \n s.shift(), current, left = [], right = []; '
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when text is selected " , ->
it " only cuts the selected text, not to the end of the line " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 2 , 20 ] , [ 2 , 30 ] ] , [ [ 3 , 20 ] , [ 3 , 20 ] ] ] )
2013-08-06 22:46:59 +04:00
2013-11-20 03:22:47 +04:00
editor . cutToEndOfLine ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.lengthurn items; '
expect ( buffer . lineForRow ( 3 ) ) . toBe ' var pivot = item '
expect ( atom . clipboard . read ( ) ) . toBe ' <= 1) ret \n s.shift(), current, left = [], right = []; '
2012-08-28 02:36:36 +04:00
2015-09-17 20:24:52 +03:00
describe " .cutToEndOfBufferLine() " , ->
2015-09-18 13:42:06 +03:00
beforeEach ->
editor . setSoftWrapped ( true )
editor . setEditorWidthInChars ( 10 )
describe " when nothing is selected " , ->
2015-09-17 20:24:52 +03:00
it " cuts up to the end of the buffer line " , ->
2015-09-18 13:42:06 +03:00
editor . setCursorBufferPosition ( [ 2 , 20 ] )
editor . addCursorAtBufferPosition ( [ 3 , 20 ] )
2015-09-17 20:24:52 +03:00
editor . cutToEndOfBufferLine ( )
2015-09-18 13:42:06 +03:00
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.length '
expect ( buffer . lineForRow ( 3 ) ) . toBe ' var pivot = item '
expect ( atom . clipboard . read ( ) ) . toBe ' <= 1) return items; \n s.shift(), current, left = [], right = []; '
2015-09-17 20:24:52 +03:00
2015-09-18 13:42:06 +03:00
describe " when text is selected " , ->
it " only cuts the selected text, not to the end of the buffer line " , ->
editor . setSelectedBufferRanges ( [ [ [ 2 , 20 ] , [ 2 , 30 ] ] , [ [ 3 , 20 ] , [ 3 , 20 ] ] ] )
2015-09-17 20:24:52 +03:00
2015-09-18 13:42:06 +03:00
editor . cutToEndOfBufferLine ( )
2015-09-17 20:24:52 +03:00
2015-09-18 13:42:06 +03:00
expect ( buffer . lineForRow ( 2 ) ) . toBe ' if (items.lengthurn items; '
expect ( buffer . lineForRow ( 3 ) ) . toBe ' var pivot = item '
expect ( atom . clipboard . read ( ) ) . toBe ' <= 1) ret \n s.shift(), current, left = [], right = []; '
2015-09-17 20:24:52 +03:00
2014-03-06 08:32:11 +04:00
describe " .copySelectedText() " , ->
it " copies selected text onto the clipboard " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 1 , 6 ] , [ 1 , 10 ] ] , [ [ 2 , 8 ] , [ 2 , 13 ] ] ] )
2014-05-12 02:06:13 +04:00
2014-03-06 08:32:11 +04:00
editor . copySelectedText ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
2012-08-28 02:36:36 +04:00
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) { "
2014-05-12 02:06:13 +04:00
expect ( buffer . lineForRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( clipboard . readText ( ) ) . toBe ' quicksort \n sort \n items '
2014-11-18 06:23:02 +03:00
expect ( atom . clipboard . read ( ) ) . toEqual """
quicksort
sort
items
"""
2012-08-28 02:36:36 +04:00
2014-11-11 20:44:08 +03:00
describe " when no text is selected " , ->
beforeEach ->
2014-11-12 21:12:26 +03:00
editor . setSelectedBufferRanges ( [
[ [ 1 , 5 ] , [ 1 , 5 ] ] ,
[ [ 5 , 8 ] , [ 5 , 8 ] ]
] )
2014-11-11 20:44:08 +03:00
it " copies the lines on which there are cursors " , ->
editor . copySelectedText ( )
2014-11-18 06:23:02 +03:00
expect ( atom . clipboard . read ( ) ) . toEqual ( [
2014-11-12 21:12:26 +03:00
" var sort = function(items) { \n "
2014-11-11 20:44:08 +03:00
" current = items.shift(); \n "
2014-11-18 06:23:02 +03:00
] . join ( " \n " ) )
2014-11-12 21:12:26 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual ( [
[ [ 1 , 5 ] , [ 1 , 5 ] ] ,
[ [ 5 , 8 ] , [ 5 , 8 ] ]
] )
2014-11-11 20:44:08 +03:00
2015-04-02 17:28:22 +03:00
describe " when many selections get added in shuffle order " , ->
it " copies them in order " , ->
editor . setSelectedBufferRanges ( [
2015-05-23 02:50:04 +03:00
[ [ 2 , 8 ] , [ 2 , 13 ] ]
[ [ 0 , 4 ] , [ 0 , 13 ] ] ,
[ [ 1 , 6 ] , [ 1 , 10 ] ] ,
2015-04-02 17:28:22 +03:00
] )
editor . copySelectedText ( )
expect ( atom . clipboard . read ( ) ) . toEqual """
quicksort
sort
items
"""
2015-07-22 12:17:35 +03:00
describe " .copyOnlySelectedText() " , ->
2015-08-18 18:06:59 +03:00
describe " when thee are multiple selections " , ->
it " copies selected text onto the clipboard " , ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 1 , 6 ] , [ 1 , 10 ] ] , [ [ 2 , 8 ] , [ 2 , 13 ] ] ] )
2015-07-22 12:17:35 +03:00
2015-08-18 18:06:59 +03:00
editor . copyOnlySelectedText ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) { "
expect ( buffer . lineForRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( clipboard . readText ( ) ) . toBe ' quicksort \n sort \n items '
expect ( atom . clipboard . read ( ) ) . toEqual """
quicksort
sort
items
"""
2015-07-22 12:17:35 +03:00
describe " when no text is selected " , ->
2015-07-27 14:02:39 +03:00
it " does not copy anything " , ->
2015-07-22 12:17:35 +03:00
editor . setCursorBufferPosition ( [ 1 , 5 ] )
editor . copyOnlySelectedText ( )
expect ( atom . clipboard . read ( ) ) . toEqual " initial clipboard content "
2015-04-02 17:28:22 +03:00
2014-03-06 08:32:11 +04:00
describe " .pasteText() " , ->
2014-11-18 02:50:06 +03:00
copyText = (text, {startColumn, textEditor}={}) ->
startColumn ? = 0
textEditor ? = editor
textEditor . setCursorBufferPosition ( [ 0 , 0 ] )
textEditor . insertText ( text )
numberOfNewlines = text . match ( /\n/g ) ? . length
endColumn = text . match ( /[^\n]*$/ ) [ 0 ] ? . length
2015-05-23 02:50:04 +03:00
textEditor . getLastSelection ( ) . setBufferRange ( [ [ 0 , startColumn ] , [ numberOfNewlines , endColumn ] ] )
2014-11-18 02:50:06 +03:00
textEditor . cutSelectedText ( )
2014-03-06 08:32:11 +04:00
it " pastes text into the buffer " , ->
2014-11-18 04:47:22 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 1 , 6 ] , [ 1 , 10 ] ] ] )
2014-03-06 08:32:11 +04:00
atom . clipboard . write ( ' first ' )
editor . pasteText ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe " var first = function () { "
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe " var first = function(items) { "
2014-03-06 08:32:11 +04:00
2015-07-07 04:29:44 +03:00
it " notifies ::onWillInsertText observers " , ->
insertedStrings = [ ]
editor . onWillInsertText ({text, cancel}) ->
insertedStrings . push ( text )
cancel ( )
atom . clipboard . write ( " hello " )
editor . pasteText ( )
expect ( insertedStrings ) . toEqual [ " hello " ]
2015-07-28 11:38:11 +03:00
it " notifies ::onDidInsertText observers " , ->
insertedStrings = [ ]
editor . onDidInsertText ({text, range}) ->
insertedStrings . push ( text )
atom . clipboard . write ( " hello " )
editor . pasteText ( )
expect ( insertedStrings ) . toEqual [ " hello " ]
2014-11-18 02:50:06 +03:00
describe " when `autoIndentOnPaste` is true " , ->
2014-11-17 21:15:10 +03:00
beforeEach ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndentOnPaste: true } )
2014-11-17 21:15:10 +03:00
2015-06-17 20:57:21 +03:00
describe " when pasting multiple lines before any non-whitespace characters " , ->
2015-01-21 19:46:28 +03:00
it " auto-indents the lines spanned by the pasted text, based on the first pasted line " , ->
atom . clipboard . write ( " a(x); \n b(x); \n c(x); \n " , indentBasis: 0 )
editor . setCursorBufferPosition ( [ 5 , 0 ] )
2014-11-17 21:15:10 +03:00
editor . pasteText ( )
2015-01-21 19:46:28 +03:00
2015-06-17 20:57:21 +03:00
# Adjust the indentation of the pasted lines while preserving
# their indentation relative to each other. Also preserve the
# indentation of the following line.
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " a(x); "
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe " b(x); "
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " c(x); "
expect ( editor . lineTextForBufferRow ( 8 ) ) . toBe " current = items.shift(); "
2015-06-30 01:05:28 +03:00
it " auto-indents lines with a mix of hard tabs and spaces without removing spaces " , ->
editor . setSoftTabs ( false )
2015-01-21 19:46:28 +03:00
expect ( editor . indentationForBufferRow ( 5 ) ) . toBe ( 3 )
2015-06-30 01:05:28 +03:00
atom . clipboard . write ( " /** \n \t * testing \n \t * indent \n \t **/ \n " , indentBasis: 1 )
editor . setCursorBufferPosition ( [ 5 , 0 ] )
editor . pasteText ( )
# Do not lose the alignment spaces
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe ( " \t \t \t /** " )
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe ( " \t \t \t * testing " )
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe ( " \t \t \t * indent " )
expect ( editor . lineTextForBufferRow ( 8 ) ) . toBe ( " \t \t \t **/ " )
2014-11-17 21:15:10 +03:00
2015-07-12 23:51:46 +03:00
describe " when pasting line(s) above a line that matches the decreaseIndentPattern " , ->
it " auto-indents based on the pasted line(s) only " , ->
atom . clipboard . write ( " a(x); \n b(x); \n c(x); \n " , indentBasis: 0 )
editor . setCursorBufferPosition ( [ 7 , 0 ] )
editor . pasteText ( )
expect ( editor . lineTextForBufferRow ( 7 ) ) . toBe " a(x); "
expect ( editor . lineTextForBufferRow ( 8 ) ) . toBe " b(x); "
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe " c(x); "
expect ( editor . lineTextForBufferRow ( 10 ) ) . toBe " } "
describe " when pasting a line of text without line ending " , ->
2015-06-17 20:57:21 +03:00
it " does not auto-indent the text " , ->
atom . clipboard . write ( " a(x); " , indentBasis: 0 )
editor . setCursorBufferPosition ( [ 5 , 0 ] )
editor . pasteText ( )
2015-01-21 19:46:28 +03:00
2015-06-17 20:57:21 +03:00
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " a(x); current = items.shift(); "
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe " current < pivot ? left.push(current) : right.push(current); "
2014-11-17 21:15:10 +03:00
2015-06-17 20:57:21 +03:00
describe " when pasting on a line after non-whitespace characters " , ->
it " does not auto-indent the affected line " , ->
# Before the paste, the indentation is non-standard.
2014-11-17 21:15:10 +03:00
editor . setText """
2015-06-17 20:57:21 +03:00
if ( x ) {
y ( ) ;
}
2014-11-17 21:15:10 +03:00
"""
2015-06-17 20:57:21 +03:00
atom . clipboard . write ( " z(); \n h(); " )
2014-11-17 21:15:10 +03:00
editor . setCursorBufferPosition ( [ 1 , Infinity ] )
2015-06-17 20:57:21 +03:00
# The indentation of the non-standard line is unchanged.
2014-11-17 21:15:10 +03:00
editor . pasteText ( )
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe ( " y(); z(); " )
2015-06-17 20:57:21 +03:00
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe ( " h(); " )
2014-11-17 21:15:10 +03:00
2014-11-19 20:13:30 +03:00
describe " when `autoIndentOnPaste` is false " , ->
2014-11-18 02:50:06 +03:00
beforeEach ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndentOnPaste: false } )
2014-11-18 02:50:06 +03:00
2014-11-22 20:42:34 +03:00
describe " when the cursor is indented further than the original copied text " , ->
it " increases the indentation of the copied lines to match " , ->
editor . setSelectedBufferRange ( [ [ 1 , 2 ] , [ 3 , 0 ] ] )
editor . copySelectedText ( )
editor . setCursorBufferPosition ( [ 5 , 6 ] )
editor . pasteText ( )
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " var sort = function(items) { "
expect ( editor . lineTextForBufferRow ( 6 ) ) . toBe " if (items.length <= 1) return items; "
describe " when the cursor is indented less far than the original copied text " , ->
it " decreases the indentation of the copied lines to match " , ->
editor . setSelectedBufferRange ( [ [ 6 , 6 ] , [ 8 , 0 ] ] )
editor . copySelectedText ( )
editor . setCursorBufferPosition ( [ 1 , 2 ] )
editor . pasteText ( )
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe " current < pivot ? left.push(current) : right.push(current); "
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " } "
describe " when the first copied line has leading whitespace " , ->
it " preserves the line ' s leading whitespace " , ->
editor . setSelectedBufferRange ( [ [ 4 , 0 ] , [ 6 , 0 ] ] )
editor . copySelectedText ( )
2014-11-18 02:50:06 +03:00
2014-11-22 20:42:34 +03:00
editor . setCursorBufferPosition ( [ 0 , 0 ] )
2014-11-18 02:50:06 +03:00
editor . pasteText ( )
2014-11-22 20:42:34 +03:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe " while(items.length > 0) { "
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe " current = items.shift(); "
2014-11-18 02:50:06 +03:00
2014-05-09 01:59:55 +04:00
describe ' when the clipboard has many selections ' , ->
2014-11-18 04:47:22 +03:00
beforeEach ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndentOnPaste: false } )
2014-11-18 04:47:22 +03:00
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 1 , 6 ] , [ 1 , 10 ] ] ] )
2014-11-18 06:23:02 +03:00
editor . copySelectedText ( )
2014-11-18 04:47:22 +03:00
2015-04-02 17:35:26 +03:00
it " pastes each selection in order separately into the buffer " , ->
editor . setSelectedBufferRanges ( [
[ [ 1 , 6 ] , [ 1 , 10 ] ]
[ [ 0 , 4 ] , [ 0 , 13 ] ] ,
] )
2014-11-18 06:23:02 +03:00
editor . moveRight ( )
editor . insertText ( " _ " )
2014-05-07 02:13:04 +04:00
editor . pasteText ( )
2014-11-18 06:23:02 +03:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe " var quicksort_quicksort = function () { "
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe " var sort_sort = function(items) { "
2014-05-07 02:13:04 +04:00
describe ' and the selections count does not match ' , ->
2014-11-18 06:23:02 +03:00
beforeEach ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] ] )
2014-05-07 02:13:04 +04:00
it " pastes the whole text into the buffer " , ->
editor . pasteText ( )
2014-11-18 06:23:02 +03:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe " var quicksort "
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe " sort = function () { "
2014-03-06 08:32:11 +04:00
2014-11-19 05:58:25 +03:00
describe " when a full line was cut " , ->
beforeEach ->
editor . setCursorBufferPosition ( [ 2 , 13 ] )
editor . cutSelectedText ( )
editor . setCursorBufferPosition ( [ 2 , 13 ] )
it " pastes the line above the cursor and retains the cursor ' s column " , ->
editor . pasteText ( )
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe ( " if (items.length <= 1) return items; " )
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe ( " var pivot = items.shift(), current, left = [], right = []; " )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 3 , 13 ] )
describe " when a full line was copied " , ->
beforeEach ->
editor . setCursorBufferPosition ( [ 2 , 13 ] )
editor . copySelectedText ( )
describe " when there is a selection " , ->
it " overwrites the selection as with any copied text " , ->
editor . setSelectedBufferRange ( [ [ 1 , 2 ] , [ 1 , Infinity ] ] )
editor . pasteText ( )
expect ( editor . lineTextForBufferRow ( 1 ) ) . toBe ( " if (items.length <= 1) return items; " )
2015-01-21 19:46:28 +03:00
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe ( " " )
2014-11-19 05:58:25 +03:00
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe ( " if (items.length <= 1) return items; " )
2015-01-21 19:46:28 +03:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 2 , 0 ] )
2014-11-19 05:58:25 +03:00
describe " when there is no selection " , ->
it " pastes the line above the cursor and retains the cursor ' s column " , ->
editor . pasteText ( )
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe ( " if (items.length <= 1) return items; " )
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe ( " if (items.length <= 1) return items; " )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 3 , 13 ] )
2014-03-06 08:32:11 +04:00
describe " .indentSelectedRows() " , ->
describe " when nothing is selected " , ->
describe " when softTabs is enabled " , ->
it " indents line and retains selection " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 3 ] , [ 0 , 3 ] ] )
2014-03-06 08:32:11 +04:00
editor . indentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 3 + editor . getTabLength ( ) ] , [ 0 , 3 + editor . getTabLength ( ) ] ]
describe " when softTabs is disabled " , ->
it " indents line and retains selection " , ->
convertToHardTabs ( buffer )
editor . setSoftTabs ( false )
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 3 ] , [ 0 , 3 ] ] )
2014-03-06 08:32:11 +04:00
editor . indentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " \t var quicksort = function () { "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 3 + 1 ] , [ 0 , 3 + 1 ] ]
describe " when one line is selected " , ->
describe " when softTabs is enabled " , ->
it " indents line and retains selection " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 4 ] , [ 0 , 14 ] ] )
2014-03-06 08:32:11 +04:00
editor . indentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " #{ editor . getTabText ( ) } var quicksort = function () { "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 4 + editor . getTabLength ( ) ] , [ 0 , 14 + editor . getTabLength ( ) ] ]
describe " when softTabs is disabled " , ->
it " indents line and retains selection " , ->
convertToHardTabs ( buffer )
editor . setSoftTabs ( false )
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 4 ] , [ 0 , 14 ] ] )
2014-03-06 08:32:11 +04:00
editor . indentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " \t var quicksort = function () { "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 4 + 1 ] , [ 0 , 14 + 1 ] ]
describe " when multiple lines are selected " , ->
describe " when softTabs is enabled " , ->
it " indents selected lines (that are not empty) and retains selection " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 9 , 1 ] , [ 11 , 15 ] ] )
2014-03-06 08:32:11 +04:00
editor . indentSelectedRows ( )
expect ( buffer . lineForRow ( 9 ) ) . toBe " }; "
expect ( buffer . lineForRow ( 10 ) ) . toBe " "
expect ( buffer . lineForRow ( 11 ) ) . toBe " return sort(Array.apply(this, arguments)); "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 9 , 1 + editor . getTabLength ( ) ] , [ 11 , 15 + editor . getTabLength ( ) ] ]
it " does not indent the last row if the selection ends at column 0 " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 9 , 1 ] , [ 11 , 0 ] ] )
2014-03-06 08:32:11 +04:00
editor . indentSelectedRows ( )
expect ( buffer . lineForRow ( 9 ) ) . toBe " }; "
expect ( buffer . lineForRow ( 10 ) ) . toBe " "
expect ( buffer . lineForRow ( 11 ) ) . toBe " return sort(Array.apply(this, arguments)); "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 9 , 1 + editor . getTabLength ( ) ] , [ 11 , 0 ] ]
describe " when softTabs is disabled " , ->
it " indents selected lines (that are not empty) and retains selection " , ->
convertToHardTabs ( buffer )
editor . setSoftTabs ( false )
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 9 , 1 ] , [ 11 , 15 ] ] )
2014-03-06 08:32:11 +04:00
editor . indentSelectedRows ( )
expect ( buffer . lineForRow ( 9 ) ) . toBe " \t \t }; "
expect ( buffer . lineForRow ( 10 ) ) . toBe " "
expect ( buffer . lineForRow ( 11 ) ) . toBe " \t \t return sort(Array.apply(this, arguments)); "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 9 , 1 + 1 ] , [ 11 , 15 + 1 ] ]
describe " .outdentSelectedRows() " , ->
describe " when nothing is selected " , ->
it " outdents line and retains selection " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 1 , 3 ] , [ 1 , 3 ] ] )
2014-03-06 08:32:11 +04:00
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) { "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 1 , 3 - editor . getTabLength ( ) ] , [ 1 , 3 - editor . getTabLength ( ) ] ]
it " outdents when indent is less than a tab length " , ->
editor . insertText ( ' ' )
editor . outdentSelectedRows ( )
2012-10-23 20:57:30 +04:00
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
2014-03-06 08:32:11 +04:00
it " outdents a single hard tab when indent is multiple hard tabs and and the session is using soft tabs " , ->
editor . insertText ( ' \t \t ' )
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " \t var quicksort = function () { "
editor . outdentSelectedRows ( )
2012-10-30 02:16:19 +04:00
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
it " outdents when a mix of hard tabs and soft tabs are used " , ->
editor . insertText ( ' \t ' )
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
2012-08-28 02:36:36 +04:00
2014-06-11 21:02:14 +04:00
it " outdents only up to the first non-space non-tab character " , ->
editor . insertText ( ' \t foo \t ' )
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " \t foo \t var quicksort = function () { "
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " foo \t var quicksort = function () { "
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " foo \t var quicksort = function () { "
2014-03-06 08:32:11 +04:00
describe " when one line is selected " , ->
it " outdents line and retains editor " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 1 , 4 ] , [ 1 , 14 ] ] )
2014-03-06 08:32:11 +04:00
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) { "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 1 , 4 - editor . getTabLength ( ) ] , [ 1 , 14 - editor . getTabLength ( ) ] ]
describe " when multiple lines are selected " , ->
it " outdents selected lines and retains editor " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 1 ] , [ 3 , 15 ] ] )
2014-03-06 08:32:11 +04:00
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) { "
expect ( buffer . lineForRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( buffer . lineForRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 1 ] , [ 3 , 15 - editor . getTabLength ( ) ] ]
it " does not outdent the last line of the selection if it ends at column 0 " , ->
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 1 ] , [ 3 , 0 ] ] )
2014-03-06 08:32:11 +04:00
editor . outdentSelectedRows ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) { "
expect ( buffer . lineForRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
expect ( buffer . lineForRow ( 3 ) ) . toBe " var pivot = items.shift(), current, left = [], right = []; "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 1 ] , [ 3 , 0 ] ]
2014-11-18 03:53:11 +03:00
describe " .autoIndentSelectedRows " , ->
it " auto-indents the selection " , ->
editor . setCursorBufferPosition ( [ 2 , 0 ] )
editor . insertText ( " function() { \n inside=true \n } \n i=1 \n " )
2015-05-23 02:50:04 +03:00
editor . getLastSelection ( ) . setBufferRange ( [ [ 2 , 0 ] , [ 6 , 0 ] ] )
2014-11-18 03:53:11 +03:00
editor . autoIndentSelectedRows ( )
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " function() { "
expect ( editor . lineTextForBufferRow ( 3 ) ) . toBe " inside=true "
expect ( editor . lineTextForBufferRow ( 4 ) ) . toBe " } "
expect ( editor . lineTextForBufferRow ( 5 ) ) . toBe " i=1 "
2014-03-06 08:32:11 +04:00
describe " .toggleLineCommentsInSelection() " , ->
it " toggles comments on the selected lines " , ->
editor . setSelectedBufferRange ( [ [ 4 , 5 ] , [ 7 , 5 ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 4 ) ) . toBe " // while(items.length > 0) { "
expect ( buffer . lineForRow ( 5 ) ) . toBe " // current = items.shift(); "
expect ( buffer . lineForRow ( 6 ) ) . toBe " // current < pivot ? left.push(current) : right.push(current); "
expect ( buffer . lineForRow ( 7 ) ) . toBe " // } "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 4 , 8 ] , [ 7 , 8 ] ]
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 4 ) ) . toBe " while(items.length > 0) { "
expect ( buffer . lineForRow ( 5 ) ) . toBe " current = items.shift(); "
expect ( buffer . lineForRow ( 6 ) ) . toBe " current < pivot ? left.push(current) : right.push(current); "
expect ( buffer . lineForRow ( 7 ) ) . toBe " } "
it " does not comment the last line of a non-empty selection if it ends at column 0 " , ->
editor . setSelectedBufferRange ( [ [ 4 , 5 ] , [ 7 , 0 ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 4 ) ) . toBe " // while(items.length > 0) { "
expect ( buffer . lineForRow ( 5 ) ) . toBe " // current = items.shift(); "
expect ( buffer . lineForRow ( 6 ) ) . toBe " // current < pivot ? left.push(current) : right.push(current); "
expect ( buffer . lineForRow ( 7 ) ) . toBe " } "
it " uncomments lines if all lines match the comment regex " , ->
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 0 , 1 ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " // var quicksort = function () { "
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 2 , Infinity ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " // // var quicksort = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " // var sort = function(items) { "
expect ( buffer . lineForRow ( 2 ) ) . toBe " // if (items.length <= 1) return items; "
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 2 , Infinity ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " // var quicksort = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " var sort = function(items) { "
expect ( buffer . lineForRow ( 2 ) ) . toBe " if (items.length <= 1) return items; "
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 0 , Infinity ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
it " uncomments commented lines separated by an empty line " , ->
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 1 , Infinity ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " // var quicksort = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " // var sort = function(items) { "
buffer . insert ( [ 0 , Infinity ] , ' \n ' )
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 2 , Infinity ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe " var quicksort = function () { "
expect ( buffer . lineForRow ( 1 ) ) . toBe " "
expect ( buffer . lineForRow ( 2 ) ) . toBe " var sort = function(items) { "
it " preserves selection emptiness " , ->
editor . setCursorBufferPosition ( [ 4 , 0 ] )
editor . toggleLineCommentsInSelection ( )
2014-08-29 04:51:16 +04:00
expect ( editor . getLastSelection ( ) . isEmpty ( ) ) . toBeTruthy ( )
2014-03-06 08:32:11 +04:00
it " does not explode if the current language mode has no comment regex " , ->
2017-01-02 22:31:43 +03:00
editor = new TextEditor ( buffer: new TextBuffer ( text: ' hello ' ) )
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 0 , 5 ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe " hello "
2012-08-28 02:36:36 +04:00
2016-10-29 15:04:30 +03:00
it " does nothing for empty lines and null grammar " , ->
runs ->
editor . setGrammar ( atom . grammars . grammarForScopeName ( ' text.plain.null-grammar ' ) )
editor . setCursorBufferPosition ( [ 10 , 0 ] )
editor . toggleLineCommentsInSelection ( )
expect ( editor . buffer . lineForRow ( 10 ) ) . toBe " "
2014-03-06 08:32:11 +04:00
it " uncomments when the line lacks the trailing whitespace in the comment regex " , ->
editor . setCursorBufferPosition ( [ 10 , 0 ] )
editor . toggleLineCommentsInSelection ( )
2012-08-28 02:36:36 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 10 ) ) . toBe " // "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 10 , 3 ] , [ 10 , 3 ] ]
editor . backspace ( )
expect ( buffer . lineForRow ( 10 ) ) . toBe " // "
2013-01-04 23:42:09 +04:00
2014-03-06 08:32:11 +04:00
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 10 ) ) . toBe " "
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 10 , 0 ] , [ 10 , 0 ] ]
2013-01-04 23:42:09 +04:00
2014-03-06 08:32:11 +04:00
it " uncomments when the line has leading whitespace " , ->
editor . setCursorBufferPosition ( [ 10 , 0 ] )
editor . toggleLineCommentsInSelection ( )
2013-01-04 23:42:09 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 10 ) ) . toBe " // "
2014-08-29 02:25:12 +04:00
editor . moveToBeginningOfLine ( )
2014-03-06 08:32:11 +04:00
editor . insertText ( " " )
editor . setSelectedBufferRange ( [ [ 10 , 0 ] , [ 10 , 0 ] ] )
editor . toggleLineCommentsInSelection ( )
expect ( buffer . lineForRow ( 10 ) ) . toBe " "
2013-01-04 23:42:09 +04:00
2014-03-06 08:32:11 +04:00
describe " .undo() and .redo() " , ->
it " undoes/redoes the last change " , ->
editor . insertText ( " foo " )
editor . undo ( )
expect ( buffer . lineForRow ( 0 ) ) . not . toContain " foo "
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . redo ( )
expect ( buffer . lineForRow ( 0 ) ) . toContain " foo "
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
it " batches the undo / redo of changes caused by multiple cursors " , ->
editor . setCursorScreenPosition ( [ 0 , 0 ] )
editor . addCursorAtScreenPosition ( [ 1 , 0 ] )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . insertText ( " foo " )
editor . backspace ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 0 ) ) . toContain " fovar "
expect ( buffer . lineForRow ( 1 ) ) . toContain " fo "
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . undo ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 0 ) ) . toContain " foo "
expect ( buffer . lineForRow ( 1 ) ) . toContain " foo "
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . redo ( )
2012-09-20 20:00:37 +04:00
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 0 ) ) . not . toContain " foo "
expect ( buffer . lineForRow ( 0 ) ) . toContain " fovar "
2013-09-13 21:49:01 +04:00
2015-08-25 20:51:45 +03:00
it " restores cursors and selections to their states before and after undone and redone changes " , ->
editor . setSelectedBufferRanges ( [
[ [ 0 , 0 ] , [ 0 , 0 ] ] ,
[ [ 1 , 0 ] , [ 1 , 3 ] ] ,
] )
editor . insertText ( " abc " )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 0 , 3 ] , [ 0 , 3 ] ] ,
[ [ 1 , 3 ] , [ 1 , 3 ] ]
]
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . setSelectedBufferRanges ( [
[ [ 2 , 0 ] , [ 2 , 0 ] ] ,
[ [ 3 , 0 ] , [ 3 , 0 ] ] ,
[ [ 4 , 0 ] , [ 4 , 3 ] ] ,
] )
editor . insertText ( " def " )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 2 , 3 ] , [ 2 , 3 ] ] ,
[ [ 3 , 3 ] , [ 3 , 3 ] ]
[ [ 4 , 3 ] , [ 4 , 3 ] ]
]
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . undo ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 2 , 0 ] , [ 2 , 0 ] ] ,
[ [ 3 , 0 ] , [ 3 , 0 ] ] ,
[ [ 4 , 0 ] , [ 4 , 3 ] ] ,
]
editor . undo ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 0 , 0 ] , [ 0 , 0 ] ] ,
[ [ 1 , 0 ] , [ 1 , 3 ] ]
]
editor . redo ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 0 , 3 ] , [ 0 , 3 ] ] ,
[ [ 1 , 3 ] , [ 1 , 3 ] ]
]
editor . redo ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [
[ [ 2 , 3 ] , [ 2 , 3 ] ] ,
[ [ 3 , 3 ] , [ 3 , 3 ] ]
[ [ 4 , 3 ] , [ 4 , 3 ] ]
]
2014-03-06 08:32:11 +04:00
it " restores the selected ranges after undo and redo " , ->
editor . setSelectedBufferRanges ( [ [ [ 1 , 6 ] , [ 1 , 10 ] ] , [ [ 1 , 22 ] , [ 1 , 27 ] ] ] )
editor . delete ( )
editor . delete ( )
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
selections = editor . getSelections ( )
expect ( buffer . lineForRow ( 1 ) ) . toBe ' var = function( { '
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 1 , 6 ] , [ 1 , 6 ] ] , [ [ 1 , 17 ] , [ 1 , 17 ] ] ]
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . undo ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 1 , 6 ] , [ 1 , 6 ] ] , [ [ 1 , 18 ] , [ 1 , 18 ] ] ]
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . undo ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 1 , 6 ] , [ 1 , 10 ] ] , [ [ 1 , 22 ] , [ 1 , 27 ] ] ]
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
editor . redo ( )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 1 , 6 ] , [ 1 , 6 ] ] , [ [ 1 , 18 ] , [ 1 , 18 ] ] ]
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
xit " restores folds after undo and redo " , ->
editor . foldBufferRow ( 1 )
editor . setSelectedBufferRange ( [ [ 1 , 0 ] , [ 10 , Infinity ] ] , preserveFolds: true )
expect ( editor . isFoldedAtBufferRow ( 1 ) ) . toBeTruthy ( )
editor . insertText """
\ / / testing
function foo ( ) {
return 1 + 2 ;
}
"""
expect ( editor . isFoldedAtBufferRow ( 1 ) ) . toBeFalsy ( )
editor . foldBufferRow ( 2 )
editor . undo ( )
expect ( editor . isFoldedAtBufferRow ( 1 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 9 ) ) . toBeTruthy ( )
expect ( editor . isFoldedAtBufferRow ( 10 ) ) . toBeFalsy ( )
editor . redo ( )
expect ( editor . isFoldedAtBufferRow ( 1 ) ) . toBeFalsy ( )
expect ( editor . isFoldedAtBufferRow ( 2 ) ) . toBeTruthy ( )
2014-11-27 21:58:38 +03:00
describe " ::transact " , ->
2014-03-06 08:32:11 +04:00
it " restores the selection when the transaction is undone/redone " , ->
buffer . setText ( ' 1234 ' )
editor . setSelectedBufferRange ( [ [ 0 , 1 ] , [ 0 , 3 ] ] )
2013-09-13 21:49:01 +04:00
2014-11-27 21:58:38 +03:00
editor . transact ->
editor . delete ( )
editor . moveToEndOfLine ( )
editor . insertText ( ' 5 ' )
expect ( buffer . getText ( ) ) . toBe ' 145 '
2014-03-06 08:32:11 +04:00
editor . undo ( )
expect ( buffer . getText ( ) ) . toBe ' 1234 '
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 1 ] , [ 0 , 3 ] ]
editor . redo ( )
expect ( buffer . getText ( ) ) . toBe ' 145 '
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 3 ] , [ 0 , 3 ] ]
describe " when the buffer is changed (via its direct api, rather than via than edit session) " , ->
it " moves the cursor so it is in the same relative position of the buffer " , ->
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 0 , 0 ]
editor . addCursorAtScreenPosition ( [ 0 , 5 ] )
editor . addCursorAtScreenPosition ( [ 1 , 0 ] )
[ cursor1 , cursor2 , cursor3 ] = editor . getCursors ( )
buffer . insert ( [ 0 , 1 ] , ' abc ' )
expect ( cursor1 . getScreenPosition ( ) ) . toEqual [ 0 , 0 ]
expect ( cursor2 . getScreenPosition ( ) ) . toEqual [ 0 , 8 ]
expect ( cursor3 . getScreenPosition ( ) ) . toEqual [ 1 , 0 ]
it " does not destroy cursors or selections when a change encompasses them " , ->
2014-08-29 05:10:18 +04:00
cursor = editor . getLastCursor ( )
2014-03-06 08:32:11 +04:00
cursor . setBufferPosition [ 3 , 3 ]
editor . buffer . delete ( [ [ 3 , 1 ] , [ 3 , 5 ] ] )
expect ( cursor . getBufferPosition ( ) ) . toEqual [ 3 , 1 ]
expect ( editor . getCursors ( ) . indexOf ( cursor ) ) . not . toBe - 1
selection = editor . getLastSelection ( )
selection . setBufferRange [ [ 3 , 5 ] , [ 3 , 10 ] ]
editor . buffer . delete [ [ 3 , 3 ] , [ 3 , 8 ] ]
expect ( selection . getBufferRange ( ) ) . toEqual [ [ 3 , 3 ] , [ 3 , 5 ] ]
expect ( editor . getSelections ( ) . indexOf ( selection ) ) . not . toBe - 1
it " merges cursors when the change causes them to overlap " , ->
editor . setCursorScreenPosition ( [ 0 , 0 ] )
editor . addCursorAtScreenPosition ( [ 0 , 2 ] )
editor . addCursorAtScreenPosition ( [ 1 , 2 ] )
[ cursor1 , cursor2 , cursor3 ] = editor . getCursors ( )
expect ( editor . getCursors ( ) . length ) . toBe 3
buffer . delete ( [ [ 0 , 0 ] , [ 0 , 2 ] ] )
expect ( editor . getCursors ( ) . length ) . toBe 2
expect ( editor . getCursors ( ) ) . toEqual [ cursor1 , cursor3 ]
2015-05-23 02:50:04 +03:00
expect ( cursor1 . getBufferPosition ( ) ) . toEqual [ 0 , 0 ]
expect ( cursor3 . getBufferPosition ( ) ) . toEqual [ 1 , 2 ]
2014-03-06 08:32:11 +04:00
2015-05-04 05:55:55 +03:00
describe " .moveSelectionLeft() " , ->
it " moves one active selection on one line one column to the left " , ->
editor . setSelectedBufferRange [ [ 0 , 4 ] , [ 0 , 13 ] ]
expect ( editor . getSelectedText ( ) ) . toBe ' quicksort '
2016-03-29 09:26:28 +03:00
2015-05-04 05:55:55 +03:00
editor . moveSelectionLeft ( )
2016-03-29 09:26:28 +03:00
2015-05-04 05:55:55 +03:00
expect ( editor . getSelectedText ( ) ) . toBe ' quicksort '
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 3 ] , [ 0 , 12 ] ]
it " moves multiple active selections on one line one column to the left " , ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 0 , 16 ] , [ 0 , 24 ] ] ] )
selections = editor . getSelections ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' quicksort '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' function '
2016-03-29 09:26:28 +03:00
2015-05-04 05:55:55 +03:00
editor . moveSelectionLeft ( )
2016-03-29 09:26:28 +03:00
2015-05-04 05:55:55 +03:00
expect ( selections [ 0 ] . getText ( ) ) . toBe ' quicksort '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' function '
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 3 ] , [ 0 , 12 ] ] , [ [ 0 , 15 ] , [ 0 , 23 ] ] ]
it " moves multiple active selections on multiple lines one column to the left " , ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 1 , 6 ] , [ 1 , 10 ] ] ] )
selections = editor . getSelections ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' quicksort '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' sort '
2016-03-29 09:26:28 +03:00
2015-05-04 05:55:55 +03:00
editor . moveSelectionLeft ( )
2016-03-29 09:26:28 +03:00
2015-05-04 05:55:55 +03:00
expect ( selections [ 0 ] . getText ( ) ) . toBe ' quicksort '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' sort '
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 3 ] , [ 0 , 12 ] ] , [ [ 1 , 5 ] , [ 1 , 9 ] ] ]
2015-05-04 07:11:42 +03:00
describe " when a selection is at the first column of a line " , ->
it " does not change the selection " , ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 0 ] , [ 0 , 3 ] ] , [ [ 1 , 0 ] , [ 1 , 3 ] ] ] )
selections = editor . getSelections ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' var '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' v '
2016-03-29 09:26:28 +03:00
2015-05-04 07:11:42 +03:00
editor . moveSelectionLeft ( )
editor . moveSelectionLeft ( )
2016-03-29 09:26:28 +03:00
2015-05-04 07:11:42 +03:00
expect ( selections [ 0 ] . getText ( ) ) . toBe ' var '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' v '
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 0 ] , [ 0 , 3 ] ] , [ [ 1 , 0 ] , [ 1 , 3 ] ] ]
2016-03-29 09:26:28 +03:00
describe " when multiple selections are active on one line " , ->
it " does not change the selection " , ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 0 ] , [ 0 , 3 ] ] , [ [ 0 , 4 ] , [ 0 , 13 ] ] ] )
selections = editor . getSelections ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' var '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' quicksort '
editor . moveSelectionLeft ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' var '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' quicksort '
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 0 ] , [ 0 , 3 ] ] , [ [ 0 , 4 ] , [ 0 , 13 ] ] ]
2015-05-04 05:59:17 +03:00
describe " .moveSelectionRight() " , ->
it " moves one active selection on one line one column to the right " , ->
editor . setSelectedBufferRange [ [ 0 , 4 ] , [ 0 , 13 ] ]
expect ( editor . getSelectedText ( ) ) . toBe ' quicksort '
2016-03-29 09:26:28 +03:00
2015-05-04 05:59:17 +03:00
editor . moveSelectionRight ( )
2016-03-29 09:26:28 +03:00
2015-05-04 05:59:17 +03:00
expect ( editor . getSelectedText ( ) ) . toBe ' quicksort '
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 5 ] , [ 0 , 14 ] ]
it " moves multiple active selections on one line one column to the right " , ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 0 , 16 ] , [ 0 , 24 ] ] ] )
selections = editor . getSelections ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' quicksort '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' function '
2016-03-29 09:26:28 +03:00
2015-05-04 05:59:17 +03:00
editor . moveSelectionRight ( )
2016-03-29 09:26:28 +03:00
2015-05-04 05:59:17 +03:00
expect ( selections [ 0 ] . getText ( ) ) . toBe ' quicksort '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' function '
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 5 ] , [ 0 , 14 ] ] , [ [ 0 , 17 ] , [ 0 , 25 ] ] ]
it " moves multiple active selections on multiple lines one column to the right " , ->
editor . setSelectedBufferRanges ( [ [ [ 0 , 4 ] , [ 0 , 13 ] ] , [ [ 1 , 6 ] , [ 1 , 10 ] ] ] )
selections = editor . getSelections ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' quicksort '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' sort '
2016-03-29 09:26:28 +03:00
2015-05-04 05:59:17 +03:00
editor . moveSelectionRight ( )
2016-03-29 09:26:28 +03:00
2015-05-04 05:59:17 +03:00
expect ( selections [ 0 ] . getText ( ) ) . toBe ' quicksort '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' sort '
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 5 ] , [ 0 , 14 ] ] , [ [ 1 , 7 ] , [ 1 , 11 ] ] ]
2015-05-04 07:11:42 +03:00
describe " when a selection is at the last column of a line " , ->
it " does not change the selection " , ->
editor . setSelectedBufferRanges ( [ [ [ 2 , 34 ] , [ 2 , 40 ] ] , [ [ 5 , 22 ] , [ 5 , 30 ] ] ] )
selections = editor . getSelections ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' items; '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' shift(); '
2016-03-29 09:26:28 +03:00
2015-05-04 07:11:42 +03:00
editor . moveSelectionRight ( )
editor . moveSelectionRight ( )
2016-03-29 09:26:28 +03:00
2015-05-04 07:11:42 +03:00
expect ( selections [ 0 ] . getText ( ) ) . toBe ' items; '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' shift(); '
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 2 , 34 ] , [ 2 , 40 ] ] , [ [ 5 , 22 ] , [ 5 , 30 ] ] ]
2016-03-29 09:26:28 +03:00
describe " when multiple selections are active on one line " , ->
it " does not change the selection " , ->
editor . setSelectedBufferRanges ( [ [ [ 2 , 27 ] , [ 2 , 33 ] ] , [ [ 2 , 34 ] , [ 2 , 40 ] ] ] )
selections = editor . getSelections ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' return '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' items; '
editor . moveSelectionRight ( )
expect ( selections [ 0 ] . getText ( ) ) . toBe ' return '
expect ( selections [ 1 ] . getText ( ) ) . toBe ' items; '
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 2 , 27 ] , [ 2 , 33 ] ] , [ [ 2 , 34 ] , [ 2 , 40 ] ] ]
2014-09-04 01:08:43 +04:00
describe ' reading text ' , ->
it ' .lineTextForScreenRow(row) ' , ->
editor . foldBufferRow ( 4 )
expect ( editor . lineTextForScreenRow ( 5 ) ) . toEqual ' return sort(left).concat(pivot).concat(sort(right)); '
2016-03-24 17:57:24 +03:00
expect ( editor . lineTextForScreenRow ( 9 ) ) . toEqual ' }; '
expect ( editor . lineTextForScreenRow ( 10 ) ) . toBeUndefined ( )
2014-09-04 01:08:43 +04:00
2014-03-06 08:32:11 +04:00
describe " .deleteLine() " , ->
it " deletes the first line when the cursor is there " , ->
2014-08-29 05:10:18 +04:00
editor . getLastCursor ( ) . moveToTop ( )
2014-03-06 08:32:11 +04:00
line1 = buffer . lineForRow ( 1 )
count = buffer . getLineCount ( )
expect ( buffer . lineForRow ( 0 ) ) . not . toBe ( line1 )
editor . deleteLine ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe ( line1 )
expect ( buffer . getLineCount ( ) ) . toBe ( count - 1 )
it " deletes the last line when the cursor is there " , ->
count = buffer . getLineCount ( )
secondToLastLine = buffer . lineForRow ( count - 2 )
expect ( buffer . lineForRow ( count - 1 ) ) . not . toBe ( secondToLastLine )
2014-08-29 05:10:18 +04:00
editor . getLastCursor ( ) . moveToBottom ( )
2014-03-06 08:32:11 +04:00
editor . deleteLine ( )
newCount = buffer . getLineCount ( )
expect ( buffer . lineForRow ( newCount - 1 ) ) . toBe ( secondToLastLine )
expect ( newCount ) . toBe ( count - 1 )
it " deletes whole lines when partial lines are selected " , ->
editor . setSelectedBufferRange ( [ [ 0 , 2 ] , [ 1 , 2 ] ] )
line2 = buffer . lineForRow ( 2 )
count = buffer . getLineCount ( )
expect ( buffer . lineForRow ( 0 ) ) . not . toBe ( line2 )
expect ( buffer . lineForRow ( 1 ) ) . not . toBe ( line2 )
editor . deleteLine ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe ( line2 )
expect ( buffer . getLineCount ( ) ) . toBe ( count - 2 )
2015-04-03 19:10:43 +03:00
it " deletes a line only once when multiple selections are on the same line " , ->
2015-04-03 19:06:28 +03:00
line1 = buffer . lineForRow ( 1 )
count = buffer . getLineCount ( )
editor . setSelectedBufferRanges ( [
[ [ 0 , 1 ] , [ 0 , 2 ] ] ,
[ [ 0 , 4 ] , [ 0 , 5 ] ]
] )
expect ( buffer . lineForRow ( 0 ) ) . not . toBe ( line1 )
editor . deleteLine ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe ( line1 )
expect ( buffer . getLineCount ( ) ) . toBe ( count - 1 )
2014-03-06 08:32:11 +04:00
it " only deletes first line if only newline is selected on second line " , ->
editor . setSelectedBufferRange ( [ [ 0 , 2 ] , [ 1 , 0 ] ] )
line1 = buffer . lineForRow ( 1 )
count = buffer . getLineCount ( )
expect ( buffer . lineForRow ( 0 ) ) . not . toBe ( line1 )
editor . deleteLine ( )
expect ( buffer . lineForRow ( 0 ) ) . toBe ( line1 )
expect ( buffer . getLineCount ( ) ) . toBe ( count - 1 )
it " deletes the entire region when invoke on a folded region " , ->
editor . foldBufferRow ( 1 )
2014-08-29 05:10:18 +04:00
editor . getLastCursor ( ) . moveToTop ( )
editor . getLastCursor ( ) . moveDown ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . getLineCount ( ) ) . toBe ( 13 )
editor . deleteLine ( )
expect ( buffer . getLineCount ( ) ) . toBe ( 4 )
it " deletes the entire file from the bottom up " , ->
count = buffer . getLineCount ( )
expect ( count ) . toBeGreaterThan ( 0 )
2016-09-26 20:52:13 +03:00
for [ 0 . . . count ]
2014-08-29 05:10:18 +04:00
editor . getLastCursor ( ) . moveToBottom ( )
2013-11-20 03:22:47 +04:00
editor . deleteLine ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . getLineCount ( ) ) . toBe ( 1 )
expect ( buffer . getText ( ) ) . toBe ( ' ' )
2012-10-09 07:08:07 +04:00
2014-03-06 08:32:11 +04:00
it " deletes the entire file from the top down " , ->
count = buffer . getLineCount ( )
expect ( count ) . toBeGreaterThan ( 0 )
2016-09-26 20:52:13 +03:00
for [ 0 . . . count ]
2014-08-29 05:10:18 +04:00
editor . getLastCursor ( ) . moveToTop ( )
2013-11-20 03:22:47 +04:00
editor . deleteLine ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . getLineCount ( ) ) . toBe ( 1 )
expect ( buffer . getText ( ) ) . toBe ( ' ' )
2013-03-22 04:07:36 +04:00
2014-03-06 08:32:11 +04:00
describe " when soft wrap is enabled " , ->
it " deletes the entire line that the cursor is on " , ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2014-03-06 08:32:11 +04:00
editor . setEditorWidthInChars ( 10 )
editor . setCursorBufferPosition ( [ 6 ] )
line7 = buffer . lineForRow ( 7 )
2013-03-22 04:07:36 +04:00
count = buffer . getLineCount ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 6 ) ) . not . toBe ( line7 )
2013-11-20 03:22:47 +04:00
editor . deleteLine ( )
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 6 ) ) . toBe ( line7 )
2013-03-22 04:07:36 +04:00
expect ( buffer . getLineCount ( ) ) . toBe ( count - 1 )
2014-03-06 08:32:11 +04:00
describe " when the line being deleted preceeds a fold, and the command is undone " , ->
2017-05-11 12:05:58 +03:00
it " restores the line and preserves the fold " , ->
2014-03-06 08:32:11 +04:00
editor . setCursorBufferPosition ( [ 4 ] )
editor . foldCurrentRow ( )
expect ( editor . isFoldedAtScreenRow ( 4 ) ) . toBeTruthy ( )
editor . setCursorBufferPosition ( [ 3 ] )
2013-11-20 03:22:47 +04:00
editor . deleteLine ( )
2014-03-06 08:32:11 +04:00
expect ( editor . isFoldedAtScreenRow ( 3 ) ) . toBeTruthy ( )
expect ( buffer . lineForRow ( 3 ) ) . toBe ' while(items.length > 0) { '
editor . undo ( )
expect ( editor . isFoldedAtScreenRow ( 4 ) ) . toBeTruthy ( )
expect ( buffer . lineForRow ( 3 ) ) . toBe ' var pivot = items.shift(), current, left = [], right = []; '
describe " .replaceSelectedText(options, fn) " , ->
describe " when no text is selected " , ->
it " inserts the text returned from the function at the cursor position " , ->
editor . replaceSelectedText { } , -> ' 123 '
expect ( buffer . lineForRow ( 0 ) ) . toBe ' 123var quicksort = function () { '
editor . setCursorBufferPosition ( [ 0 ] )
2016-05-21 01:52:14 +03:00
editor . replaceSelectedText { selectWordIfEmpty: true } , -> ' var '
2014-03-06 08:32:11 +04:00
expect ( buffer . lineForRow ( 0 ) ) . toBe ' var quicksort = function () { '
editor . setCursorBufferPosition ( [ 10 ] )
editor . replaceSelectedText null , -> ' '
expect ( buffer . lineForRow ( 10 ) ) . toBe ' '
describe " when text is selected " , ->
it " replaces the selected text with the text returned from the function " , ->
editor . setSelectedBufferRange ( [ [ 0 , 1 ] , [ 0 , 3 ] ] )
editor . replaceSelectedText { } , -> ' ia '
expect ( buffer . lineForRow ( 0 ) ) . toBe ' via quicksort = function () { '
2016-05-21 01:52:14 +03:00
it " replaces the selected text and selects the replacement text " , ->
editor . setSelectedBufferRange ( [ [ 0 , 4 ] , [ 0 , 9 ] ] )
editor . replaceSelectedText { } , -> ' whatnot '
expect ( buffer . lineForRow ( 0 ) ) . toBe ' var whatnotsort = function () { '
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 4 ] , [ 0 , 11 ] ]
2014-03-06 08:32:11 +04:00
describe " .transpose() " , ->
it " swaps two characters " , ->
editor . buffer . setText ( " abc " )
editor . setCursorScreenPosition ( [ 0 , 1 ] )
editor . transpose ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' bac '
2014-03-06 08:32:11 +04:00
it " reverses a selection " , ->
editor . buffer . setText ( " xabcz " )
editor . setSelectedBufferRange ( [ [ 0 , 1 ] , [ 0 , 4 ] ] )
editor . transpose ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' xcbaz '
2014-03-06 08:32:11 +04:00
describe " .upperCase() " , ->
describe " when there is no selection " , ->
it " upper cases the current word " , ->
editor . buffer . setText ( " aBc " )
editor . setCursorScreenPosition ( [ 0 , 1 ] )
editor . upperCase ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' ABC '
2016-05-21 01:52:14 +03:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 0 , 3 ] ]
2013-09-13 21:49:01 +04:00
2014-03-06 08:32:11 +04:00
describe " when there is a selection " , ->
it " upper cases the current selection " , ->
2013-11-20 03:22:47 +04:00
editor . buffer . setText ( " abc " )
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 0 , 2 ] ] )
2014-03-06 08:32:11 +04:00
editor . upperCase ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' ABc '
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 0 , 2 ] ]
describe " .lowerCase() " , ->
describe " when there is no selection " , ->
it " lower cases the current word " , ->
editor . buffer . setText ( " aBC " )
2013-11-20 03:22:47 +04:00
editor . setCursorScreenPosition ( [ 0 , 1 ] )
2014-03-06 08:32:11 +04:00
editor . lowerCase ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' abc '
2016-05-21 01:52:14 +03:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 0 , 3 ] ]
2014-03-06 08:32:11 +04:00
describe " when there is a selection " , ->
it " lower cases the current selection " , ->
editor . buffer . setText ( " ABC " )
2015-05-23 02:50:04 +03:00
editor . setSelectedBufferRange ( [ [ 0 , 0 ] , [ 0 , 2 ] ] )
2014-03-06 08:32:11 +04:00
editor . lowerCase ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' abC '
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 0 ] , [ 0 , 2 ] ]
2016-07-12 03:02:48 +03:00
describe ' .setTabLength(tabLength) ' , ->
2016-12-13 10:09:09 +03:00
it ' clips atomic soft tabs to the given tab length ' , ->
2016-07-12 03:02:48 +03:00
expect ( editor . getTabLength ( ) ) . toBe 2
2016-12-13 10:09:09 +03:00
expect ( editor . clipScreenPosition ( [ 5 , 1 ] , clipDirection: ' forward ' ) ) . toEqual ( [ 5 , 2 ] )
2016-07-12 03:02:48 +03:00
editor . setTabLength ( 6 )
expect ( editor . getTabLength ( ) ) . toBe 6
2016-12-13 10:09:09 +03:00
expect ( editor . clipScreenPosition ( [ 5 , 1 ] , clipDirection: ' forward ' ) ) . toEqual ( [ 5 , 6 ] )
2016-07-12 03:02:48 +03:00
changeHandler = jasmine . createSpy ( ' changeHandler ' )
editor . onDidChange ( changeHandler )
editor . setTabLength ( 6 )
expect ( changeHandler ) . not . toHaveBeenCalled ( )
2014-10-04 03:22:16 +04:00
2016-09-29 22:01:39 +03:00
it ' does not change its tab length when the given tab length is null ' , ->
editor . setTabLength ( 4 )
editor . setTabLength ( null )
expect ( editor . getTabLength ( ) ) . toBe ( 4 )
2014-03-06 08:32:11 +04:00
describe " .indentLevelForLine(line) " , ->
it " returns the indent level when the line has only leading whitespace " , ->
expect ( editor . indentLevelForLine ( " hello " ) ) . toBe ( 2 )
expect ( editor . indentLevelForLine ( " hello " ) ) . toBe ( 1.5 )
it " returns the indent level when the line has only leading tabs " , ->
expect ( editor . indentLevelForLine ( " \t \t hello " ) ) . toBe ( 2 )
2015-06-30 01:05:28 +03:00
it " returns the indent level based on the character starting the line when the leading whitespace contains both spaces and tabs " , ->
2014-03-06 08:32:11 +04:00
expect ( editor . indentLevelForLine ( " \t hello " ) ) . toBe ( 2 )
expect ( editor . indentLevelForLine ( " \t hello " ) ) . toBe ( 2 )
expect ( editor . indentLevelForLine ( " \t hello " ) ) . toBe ( 2.5 )
2015-06-30 20:32:10 +03:00
expect ( editor . indentLevelForLine ( " \t \t hello " ) ) . toBe ( 4 )
expect ( editor . indentLevelForLine ( " \t \t hello " ) ) . toBe ( 4 )
expect ( editor . indentLevelForLine ( " \t \t hello " ) ) . toBe ( 4.5 )
2014-03-06 08:32:11 +04:00
describe " when a better-matched grammar is added to syntax " , ->
it " switches to the better-matched grammar and re-tokenizes the buffer " , ->
2014-04-23 04:52:28 +04:00
editor . destroy ( )
2014-11-20 21:42:49 +03:00
jsGrammar = atom . grammars . selectGrammar ( ' a.js ' )
atom . grammars . removeGrammar ( jsGrammar )
2014-03-06 08:32:11 +04:00
2014-04-23 04:52:28 +04:00
waitsForPromise ->
atom . workspace . open ( ' sample.js ' , autoIndent: false ) . then (o) -> editor = o
runs ->
2014-11-20 21:42:49 +03:00
expect ( editor . getGrammar ( ) ) . toBe atom . grammars . nullGrammar
2016-03-25 12:49:32 +03:00
expect ( editor . tokensForScreenRow ( 0 ) . length ) . toBe ( 1 )
2014-03-06 08:32:11 +04:00
2014-11-20 21:42:49 +03:00
atom . grammars . addGrammar ( jsGrammar )
2014-04-23 04:52:28 +04:00
expect ( editor . getGrammar ( ) ) . toBe jsGrammar
2016-03-25 12:49:32 +03:00
expect ( editor . tokensForScreenRow ( 0 ) . length ) . toBeGreaterThan 1
2014-03-06 08:32:11 +04:00
2014-11-18 03:53:11 +03:00
describe " editor.autoIndent " , ->
describe " when editor.autoIndent is false (default) " , ->
describe " when `indent` is triggered " , ->
it " does not auto-indent the line " , ->
editor . setCursorBufferPosition ( [ 1 , 30 ] )
editor . insertText ( " \n " )
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " "
2014-03-06 08:32:11 +04:00
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: false } )
2014-11-18 03:53:11 +03:00
editor . indent ( )
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " "
2013-05-07 22:55:57 +04:00
2014-11-18 03:53:11 +03:00
describe " when editor.autoIndent is true " , ->
beforeEach ->
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2013-05-10 00:12:29 +04:00
2014-11-18 03:53:11 +03:00
describe " when `indent` is triggered " , ->
it " auto-indents the line " , ->
editor . setCursorBufferPosition ( [ 1 , 30 ] )
editor . insertText ( " \n " )
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " "
2013-05-13 23:18:24 +04:00
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2014-11-18 03:53:11 +03:00
editor . indent ( )
expect ( editor . lineTextForBufferRow ( 2 ) ) . toBe " "
2013-05-13 23:18:24 +04:00
2014-11-18 03:53:11 +03:00
describe " when a newline is added " , ->
describe " when the line preceding the newline adds a new level of indentation " , ->
it " indents the newline to one additional level of indentation beyond the preceding line " , ->
editor . setCursorBufferPosition ( [ 1 , Infinity ] )
2014-03-06 08:32:11 +04:00
editor . insertText ( ' \n ' )
expect ( editor . indentationForBufferRow ( 2 ) ) . toBe editor . indentationForBufferRow ( 1 ) + 1
2013-01-18 04:15:20 +04:00
2014-11-18 03:53:11 +03:00
describe " when the line preceding the newline does ' t add a level of indentation " , ->
2016-03-31 05:56:34 +03:00
it " indents the new line to the same level as the preceding line " , ->
2014-11-18 03:53:11 +03:00
editor . setCursorBufferPosition ( [ 5 , 14 ] )
editor . insertText ( ' \n ' )
expect ( editor . indentationForBufferRow ( 6 ) ) . toBe editor . indentationForBufferRow ( 5 )
2014-10-07 05:19:07 +04:00
2014-11-18 03:53:11 +03:00
describe " when the line preceding the newline is a comment " , ->
it " maintains the indent of the commented line " , ->
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . insertText ( ' // ' )
editor . setCursorBufferPosition ( [ 0 , Infinity ] )
editor . insertText ( ' \n ' )
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 2
2014-10-07 05:19:07 +04:00
2014-11-19 04:27:43 +03:00
describe " when the line preceding the newline contains only whitespace " , ->
it " bases the new line ' s indentation on only the preceding line " , ->
editor . setCursorBufferPosition ( [ 6 , Infinity ] )
editor . insertText ( " \n " )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual ( [ 7 , 2 ] )
editor . insertNewline ( )
expect ( editor . lineTextForBufferRow ( 8 ) ) . toBe ( " " )
2014-11-18 03:53:11 +03:00
it " does not indent the line preceding the newline " , ->
editor . setCursorBufferPosition ( [ 2 , 0 ] )
editor . insertText ( ' var this-line-should-be-indented-more \n ' )
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 1
2014-10-07 05:19:07 +04:00
2016-08-12 01:34:54 +03:00
editor . update ( { autoIndent: true } )
2014-11-18 03:53:11 +03:00
editor . setCursorBufferPosition ( [ 2 , Infinity ] )
editor . insertText ( ' \n ' )
expect ( editor . indentationForBufferRow ( 1 ) ) . toBe 1
expect ( editor . indentationForBufferRow ( 2 ) ) . toBe 1
describe " when the cursor is before whitespace " , ->
it " retains the whitespace following the cursor on the new line " , ->
editor . setText ( " var sort = function() {} " )
2014-12-12 03:27:23 +03:00
editor . setCursorScreenPosition ( [ 0 , 12 ] )
2014-11-18 03:53:11 +03:00
editor . insertNewline ( )
2014-12-12 03:27:23 +03:00
expect ( buffer . lineForRow ( 0 ) ) . toBe ' var sort = '
expect ( buffer . lineForRow ( 1 ) ) . toBe ' function() {} '
2014-11-18 03:53:11 +03:00
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 1 , 2 ]
describe " when inserted text matches a decrease indent pattern " , ->
describe " when the preceding line matches an increase indent pattern " , ->
it " decreases the indentation to match that of the preceding line " , ->
editor . setCursorBufferPosition ( [ 1 , Infinity ] )
editor . insertText ( ' \n ' )
expect ( editor . indentationForBufferRow ( 2 ) ) . toBe editor . indentationForBufferRow ( 1 ) + 1
editor . insertText ( ' } ' )
expect ( editor . indentationForBufferRow ( 2 ) ) . toBe editor . indentationForBufferRow ( 1 )
describe " when the preceding line doesn ' t match an increase indent pattern " , ->
it " decreases the indentation to be one level below that of the preceding line " , ->
editor . setCursorBufferPosition ( [ 3 , Infinity ] )
editor . insertText ( ' \n ' )
expect ( editor . indentationForBufferRow ( 4 ) ) . toBe editor . indentationForBufferRow ( 3 )
editor . insertText ( ' } ' )
expect ( editor . indentationForBufferRow ( 4 ) ) . toBe editor . indentationForBufferRow ( 3 ) - 1
it " doesn ' t break when decreasing the indentation on a row that has no indentation " , ->
editor . setCursorBufferPosition ( [ 12 , Infinity ] )
editor . insertText ( " \n }; # too many closing brackets! " )
expect ( editor . lineTextForBufferRow ( 13 ) ) . toBe " }; # too many closing brackets! "
describe " when inserted text does not match a decrease indent pattern " , ->
it " does not decrease the indentation " , ->
editor . setCursorBufferPosition ( [ 12 , 0 ] )
editor . insertText ( ' ' )
expect ( editor . lineTextForBufferRow ( 12 ) ) . toBe ' }; '
editor . insertText ( ' \t \t ' )
expect ( editor . lineTextForBufferRow ( 12 ) ) . toBe ' \t \t }; '
2014-10-07 05:19:07 +04:00
2014-11-18 03:53:11 +03:00
describe " when the current line does not match a decrease indent pattern " , ->
it " leaves the line unchanged " , ->
editor . setCursorBufferPosition ( [ 2 , 4 ] )
expect ( editor . indentationForBufferRow ( 2 ) ) . toBe editor . indentationForBufferRow ( 1 ) + 1
editor . insertText ( ' foo ' )
expect ( editor . indentationForBufferRow ( 2 ) ) . toBe editor . indentationForBufferRow ( 1 ) + 1
2016-07-12 03:02:48 +03:00
describe " atomic soft tabs " , ->
2016-05-05 10:10:36 +03:00
it " skips tab-length runs of leading whitespace when moving the cursor " , ->
2016-08-16 02:45:05 +03:00
editor . update ( { tabLength: 4 , atomicSoftTabs: true } )
2016-05-05 10:10:36 +03:00
editor . setCursorScreenPosition ( [ 2 , 3 ] )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 2 , 4 ]
2016-08-16 02:45:05 +03:00
editor . update ( { atomicSoftTabs: false } )
2016-05-05 10:10:36 +03:00
editor . setCursorScreenPosition ( [ 2 , 3 ] )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 2 , 3 ]
2016-08-16 02:45:05 +03:00
editor . update ( { atomicSoftTabs: true } )
2016-05-05 10:10:36 +03:00
editor . setCursorScreenPosition ( [ 2 , 3 ] )
expect ( editor . getCursorScreenPosition ( ) ) . toEqual [ 2 , 4 ]
2014-03-06 08:32:11 +04:00
describe " .destroy() " , ->
2015-11-04 02:49:11 +03:00
it " destroys marker layers associated with the text editor " , ->
2017-01-02 22:31:43 +03:00
buffer . retain ( )
2015-11-04 02:49:11 +03:00
selectionsMarkerLayerId = editor . selectionsMarkerLayer . id
2016-03-25 12:53:02 +03:00
foldsMarkerLayerId = editor . displayLayer . foldsMarkerLayer . id
2014-03-06 08:32:11 +04:00
editor . destroy ( )
2015-11-04 02:49:11 +03:00
expect ( buffer . getMarkerLayer ( selectionsMarkerLayerId ) ) . toBeUndefined ( )
expect ( buffer . getMarkerLayer ( foldsMarkerLayerId ) ) . toBeUndefined ( )
2017-01-02 22:31:43 +03:00
buffer . release ( )
2014-03-06 08:32:11 +04:00
2014-09-18 04:36:06 +04:00
it " notifies ::onDidDestroy observers when the editor is destroyed " , ->
destroyObserverCalled = false
editor . onDidDestroy -> destroyObserverCalled = true
editor . destroy ( )
expect ( destroyObserverCalled ) . toBe true
2017-01-04 01:00:50 +03:00
it " does not blow up when query methods are called afterward " , ->
editor . destroy ( )
editor . getGrammar ( )
editor . getLastCursor ( )
editor . lineTextForBufferRow ( 0 )
2017-01-04 02:18:01 +03:00
it " emits the destroy event after destroying the editor ' s buffer " , ->
events = [ ]
editor . getBuffer ( ) . onDidDestroy ->
expect ( editor . isDestroyed ( ) ) . toBe ( true )
events . push ( ' buffer-destroyed ' )
editor . onDidDestroy ->
expect ( buffer . isDestroyed ( ) ) . toBe ( true )
events . push ( ' editor-destroyed ' )
editor . destroy ( )
expect ( events ) . toEqual ( [ ' buffer-destroyed ' , ' editor-destroyed ' ] )
2014-03-06 08:32:11 +04:00
describe " .joinLines() " , ->
describe " when no text is selected " , ->
describe " when the line below isn ' t empty " , ->
it " joins the line below with the current line separated by a space and moves the cursor to the start of line that was moved up " , ->
2014-10-16 21:58:02 +04:00
editor . setCursorBufferPosition ( [ 0 , Infinity ] )
editor . insertText ( ' ' )
editor . setCursorBufferPosition ( [ 0 ] )
2014-03-06 08:32:11 +04:00
editor . joinLines ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' var quicksort = function () { var sort = function(items) { '
2014-10-16 21:50:21 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 29 ]
2014-03-06 08:32:11 +04:00
describe " when the line below is empty " , ->
it " deletes the line below and moves the cursor to the end of the line " , ->
editor . setCursorBufferPosition ( [ 9 ] )
editor . joinLines ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe ' }; '
expect ( editor . lineTextForBufferRow ( 10 ) ) . toBe ' return sort(Array.apply(this, arguments)); '
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 9 , 4 ]
describe " when the cursor is on the last row " , ->
it " does nothing " , ->
editor . setCursorBufferPosition ( [ Infinity , Infinity ] )
editor . joinLines ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 12 ) ) . toBe ' }; '
2014-03-06 08:32:11 +04:00
2014-10-16 21:54:29 +04:00
describe " when the line is empty " , ->
it " joins the line below with the current line with no added space " , ->
editor . setCursorBufferPosition ( [ 10 ] )
editor . joinLines ( )
expect ( editor . lineTextForBufferRow ( 10 ) ) . toBe ' return sort(Array.apply(this, arguments)); '
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 10 , 0 ]
2014-03-06 08:32:11 +04:00
describe " when text is selected " , ->
describe " when the selection does not span multiple lines " , ->
it " joins the line below with the current line separated by a space and retains the selected text " , ->
editor . setSelectedBufferRange ( [ [ 0 , 1 ] , [ 0 , 3 ] ] )
editor . joinLines ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 0 ) ) . toBe ' var quicksort = function () { var sort = function(items) { '
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 0 , 1 ] , [ 0 , 3 ] ]
2013-06-19 22:19:53 +04:00
2014-03-06 08:32:11 +04:00
describe " when the selection spans multiple lines " , ->
it " joins all selected lines separated by a space and retains the selected text " , ->
editor . setSelectedBufferRange ( [ [ 9 , 3 ] , [ 12 , 1 ] ] )
editor . joinLines ( )
2014-09-04 00:51:57 +04:00
expect ( editor . lineTextForBufferRow ( 9 ) ) . toBe ' }; return sort(Array.apply(this, arguments)); }; '
2014-03-06 08:32:11 +04:00
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 9 , 3 ] , [ 9 , 49 ] ]
2014-03-06 10:29:28 +04:00
describe " .duplicateLines() " , ->
it " for each selection, duplicates all buffer lines intersected by the selection " , ->
editor . foldBufferRow ( 4 )
editor . setCursorBufferPosition ( [ 2 , 5 ] )
2014-03-06 11:29:35 +04:00
editor . addSelectionForBufferRange ( [ [ 3 , 0 ] , [ 8 , 0 ] ] , preserveFolds: true )
2014-03-06 10:29:28 +04:00
2014-03-07 00:20:20 +04:00
editor . duplicateLines ( )
2014-03-06 10:29:28 +04:00
expect ( editor . getTextInBufferRange ( [ [ 2 , 0 ] , [ 13 , 5 ] ] ) ) . toBe """
\ if ( items . length <= 1 ) return items ;
if ( items . length <= 1 ) return items ;
var pivot = items . shift ( ) , current , left = [ ] , right = [ ] ;
while ( items . length > 0 ) {
current = items . shift ( ) ;
current < pivot ? left . push ( current ) : right . push ( current ) ;
}
var pivot = items . shift ( ) , current , left = [ ] , right = [ ] ;
while ( items . length > 0 ) {
current = items . shift ( ) ;
current < pivot ? left . push ( current ) : right . push ( current ) ;
}
"""
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 3 , 5 ] , [ 3 , 5 ] ] , [ [ 9 , 0 ] , [ 14 , 0 ] ] ]
2014-03-06 11:29:35 +04:00
# folds are also duplicated
2016-03-25 12:49:32 +03:00
expect ( editor . isFoldedAtScreenRow ( 5 ) ) . toBe ( true )
expect ( editor . isFoldedAtScreenRow ( 7 ) ) . toBe ( true )
2016-04-05 12:28:16 +03:00
expect ( editor . lineTextForScreenRow ( 7 ) ) . toBe " while(items.length > 0) { " + editor . displayLayer . foldCharacter
2016-03-25 12:49:32 +03:00
expect ( editor . lineTextForScreenRow ( 8 ) ) . toBe " return sort(left).concat(pivot).concat(sort(right)); "
2014-03-06 11:29:35 +04:00
2017-01-12 23:35:42 +03:00
it " duplicates all folded lines for empty selections on lines containing folds " , ->
2014-03-06 11:03:22 +04:00
editor . foldBufferRow ( 4 )
editor . setCursorBufferPosition ( [ 4 , 0 ] )
2014-03-07 00:20:20 +04:00
editor . duplicateLines ( )
2014-03-06 11:03:22 +04:00
expect ( editor . getTextInBufferRange ( [ [ 2 , 0 ] , [ 11 , 5 ] ] ) ) . toBe """
\ if ( items . length <= 1 ) return items ;
var pivot = items . shift ( ) , current , left = [ ] , right = [ ] ;
while ( items . length > 0 ) {
current = items . shift ( ) ;
current < pivot ? left . push ( current ) : right . push ( current ) ;
}
while ( items . length > 0 ) {
current = items . shift ( ) ;
current < pivot ? left . push ( current ) : right . push ( current ) ;
}
"""
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 8 , 0 ] , [ 8 , 0 ] ]
2014-03-07 01:48:36 +04:00
it " can duplicate the last line of the buffer " , ->
editor . setSelectedBufferRange ( [ [ 11 , 0 ] , [ 12 , 2 ] ] )
editor . duplicateLines ( )
expect ( editor . getTextInBufferRange ( [ [ 11 , 0 ] , [ 14 , 2 ] ] ) ) . toBe """
\ return sort ( Array . apply ( this , arguments ) ) ;
} ;
return sort ( Array . apply ( this , arguments ) ) ;
} ;
"""
expect ( editor . getSelectedBufferRange ( ) ) . toEqual [ [ 13 , 0 ] , [ 14 , 2 ] ]
2017-01-12 23:35:42 +03:00
it " only duplicates lines containing multiple selections once " , ->
editor . setText ( """
aaaaaa
bbbbbb
cccccc
dddddd
""" )
editor . setSelectedBufferRanges ( [
[ [ 0 , 1 ] , [ 0 , 2 ] ] ,
[ [ 0 , 3 ] , [ 0 , 4 ] ] ,
[ [ 2 , 1 ] , [ 2 , 2 ] ] ,
[ [ 2 , 3 ] , [ 3 , 1 ] ] ,
[ [ 3 , 3 ] , [ 3 , 4 ] ] ,
] )
editor . duplicateLines ( )
expect ( editor . getText ( ) ) . toBe ( """
aaaaaa
aaaaaa
bbbbbb
cccccc
dddddd
cccccc
dddddd
""" )
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual ( [
[ [ 1 , 1 ] , [ 1 , 2 ] ] ,
[ [ 1 , 3 ] , [ 1 , 4 ] ] ,
[ [ 5 , 1 ] , [ 5 , 2 ] ] ,
[ [ 5 , 3 ] , [ 6 , 1 ] ] ,
[ [ 6 , 3 ] , [ 6 , 4 ] ] ,
] )
2014-03-06 08:32:11 +04:00
describe " .shouldPromptToSave() " , ->
2016-10-10 01:20:22 +03:00
it " returns true when buffer changed " , ->
2014-03-06 08:32:11 +04:00
jasmine . unspy ( editor , ' shouldPromptToSave ' )
expect ( editor . shouldPromptToSave ( ) ) . toBeFalsy ( )
buffer . setText ( ' changed ' )
expect ( editor . shouldPromptToSave ( ) ) . toBeTruthy ( )
2014-04-23 04:52:28 +04:00
2016-10-10 01:20:22 +03:00
it " returns false when an edit session ' s buffer is in use by more than one session " , ->
jasmine . unspy ( editor , ' shouldPromptToSave ' )
buffer . setText ( ' changed ' )
2014-04-23 04:52:28 +04:00
editor2 = null
waitsForPromise ->
2015-10-03 06:13:42 +03:00
atom . workspace . getActivePane ( ) . splitRight ( )
atom . workspace . open ( ' sample.js ' , autoIndent: false ) . then (o) -> editor2 = o
2014-04-23 04:52:28 +04:00
runs ->
expect ( editor . shouldPromptToSave ( ) ) . toBeFalsy ( )
editor2 . destroy ( )
expect ( editor . shouldPromptToSave ( ) ) . toBeTruthy ( )
2014-03-06 08:32:11 +04:00
2016-10-10 01:20:22 +03:00
it " returns false when close of a window requested and edit session opened inside project " , ->
jasmine . unspy ( editor , ' shouldPromptToSave ' )
buffer . setText ( ' changed ' )
expect ( editor . shouldPromptToSave ( windowCloseRequested: true , projectHasPaths: true ) ) . toBeFalsy ( )
it " returns true when close of a window requested and edit session opened without project " , ->
jasmine . unspy ( editor , ' shouldPromptToSave ' )
buffer . setText ( ' changed ' )
expect ( editor . shouldPromptToSave ( windowCloseRequested: true , projectHasPaths: false ) ) . toBeTruthy ( )
2014-09-17 20:32:18 +04:00
describe " when the editor contains surrogate pair characters " , ->
2014-03-06 08:32:11 +04:00
it " correctly backspaces over them " , ->
editor . setText ( ' \u D835 \u DF97 \u D835 \u DF97 \u D835 \u DF97 ' )
2014-08-29 02:25:12 +04:00
editor . moveToBottom ( )
2014-03-06 08:32:11 +04:00
editor . backspace ( )
expect ( editor . getText ( ) ) . toBe ' \u D835 \u DF97 \u D835 \u DF97 '
editor . backspace ( )
expect ( editor . getText ( ) ) . toBe ' \u D835 \u DF97 '
editor . backspace ( )
expect ( editor . getText ( ) ) . toBe ' '
it " correctly deletes over them " , ->
editor . setText ( ' \u D835 \u DF97 \u D835 \u DF97 \u D835 \u DF97 ' )
2014-08-29 02:25:12 +04:00
editor . moveToTop ( )
2014-03-06 08:32:11 +04:00
editor . delete ( )
expect ( editor . getText ( ) ) . toBe ' \u D835 \u DF97 \u D835 \u DF97 '
editor . delete ( )
expect ( editor . getText ( ) ) . toBe ' \u D835 \u DF97 '
editor . delete ( )
expect ( editor . getText ( ) ) . toBe ' '
it " correctly moves over them " , ->
editor . setText ( ' \u D835 \u DF97 \u D835 \u DF97 \u D835 \u DF97 \n ' )
2014-08-29 02:25:12 +04:00
editor . moveToTop ( )
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 2 ]
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 4 ]
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2014-09-17 20:30:26 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 6 ]
editor . moveRight ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 0 ]
editor . moveLeft ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 6 ]
editor . moveLeft ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 4 ]
editor . moveLeft ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 2 ]
editor . moveLeft ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
describe " when the editor contains variation sequence character pairs " , ->
it " correctly backspaces over them " , ->
editor . setText ( ' \u 2714 \u FE0E \u 2714 \u FE0E \u 2714 \u FE0E ' )
editor . moveToBottom ( )
editor . backspace ( )
expect ( editor . getText ( ) ) . toBe ' \u 2714 \u FE0E \u 2714 \u FE0E '
editor . backspace ( )
expect ( editor . getText ( ) ) . toBe ' \u 2714 \u FE0E '
editor . backspace ( )
expect ( editor . getText ( ) ) . toBe ' '
it " correctly deletes over them " , ->
editor . setText ( ' \u 2714 \u FE0E \u 2714 \u FE0E \u 2714 \u FE0E ' )
editor . moveToTop ( )
editor . delete ( )
expect ( editor . getText ( ) ) . toBe ' \u 2714 \u FE0E \u 2714 \u FE0E '
editor . delete ( )
expect ( editor . getText ( ) ) . toBe ' \u 2714 \u FE0E '
editor . delete ( )
expect ( editor . getText ( ) ) . toBe ' '
it " correctly moves over them " , ->
editor . setText ( ' \u 2714 \u FE0E \u 2714 \u FE0E \u 2714 \u FE0E \n ' )
editor . moveToTop ( )
editor . moveRight ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 2 ]
editor . moveRight ( )
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 4 ]
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 6 ]
2014-08-29 02:25:12 +04:00
editor . moveRight ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 1 , 0 ]
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 6 ]
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 4 ]
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 2 ]
2014-08-29 02:25:12 +04:00
editor . moveLeft ( )
2014-03-06 08:32:11 +04:00
expect ( editor . getCursorBufferPosition ( ) ) . toEqual [ 0 , 0 ]
describe " .setIndentationForBufferRow " , ->
describe " when the editor uses soft tabs but the row has hard tabs " , ->
2014-08-29 20:35:19 +04:00
it " only replaces whitespace characters " , ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2014-03-11 05:45:01 +04:00
editor . setText ( " \t 1 \n \t 2 " )
2014-03-06 08:32:11 +04:00
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . setIndentationForBufferRow ( 0 , 2 )
2014-03-11 05:45:01 +04:00
expect ( editor . getText ( ) ) . toBe ( " 1 \n \t 2 " )
describe " when the indentation level is a non-integer " , ->
it " does not throw an exception " , ->
2014-09-04 18:42:32 +04:00
editor . setSoftWrapped ( true )
2014-03-11 05:45:01 +04:00
editor . setText ( " \t 1 \n \t 2 " )
editor . setCursorBufferPosition ( [ 0 , 0 ] )
editor . setIndentationForBufferRow ( 0 , 2.1 )
expect ( editor . getText ( ) ) . toBe ( " 1 \n \t 2 " )
2013-06-19 22:19:53 +04:00
2014-03-06 08:34:31 +04:00
describe " when the editor ' s grammar has an injection selector " , ->
beforeEach ->
waitsForPromise ->
atom . packages . activatePackage ( ' language-text ' )
2014-03-06 08:32:11 +04:00
2014-03-06 08:34:31 +04:00
waitsForPromise ->
atom . packages . activatePackage ( ' language-javascript ' )
2013-12-31 21:43:05 +04:00
2014-03-06 08:34:31 +04:00
it " includes the grammar ' s patterns when the selector matches the current scope in other grammars " , ->
2014-02-11 03:22:00 +04:00
waitsForPromise ->
atom . packages . activatePackage ( ' language-hyperlink ' )
runs ->
2014-11-20 21:42:49 +03:00
grammar = atom . grammars . selectGrammar ( " text.js " )
2015-05-21 17:33:17 +03:00
{ line , tags } = grammar . tokenizeLine ( " var i; // http://github.com " )
2014-03-06 08:34:31 +04:00
2015-05-21 17:33:17 +03:00
tokens = atom . grammars . decodeTokens ( line , tags )
2014-03-06 08:34:31 +04:00
expect ( tokens [ 0 ] . value ) . toBe " var "
2015-12-03 05:39:12 +03:00
expect ( tokens [ 0 ] . scopes ) . toEqual [ " source.js " , " storage.type.var.js " ]
2013-12-31 21:43:05 +04:00
2014-03-06 08:34:31 +04:00
expect ( tokens [ 6 ] . value ) . toBe " http://github.com "
2014-10-21 22:38:43 +04:00
expect ( tokens [ 6 ] . scopes ) . toEqual [ " source.js " , " comment.line.double-slash.js " , " markup.underline.link.http.hyperlink " ]
2014-03-06 08:34:31 +04:00
describe " when the grammar is added " , ->
2013-12-31 21:43:05 +04:00
it " retokenizes existing buffers that contain tokens that match the injection selector " , ->
2014-04-23 04:52:28 +04:00
waitsForPromise ->
atom . workspace . open ( ' sample.js ' ) . then (o) -> editor = o
2013-12-31 21:43:05 +04:00
2014-04-23 04:52:28 +04:00
runs ->
editor . setText ( " // http://github.com " )
2016-03-25 12:49:32 +03:00
tokens = editor . tokensForScreenRow ( 0 )
2016-07-26 22:39:41 +03:00
expect ( tokens ) . toEqual [
2017-05-05 10:04:34 +03:00
{ text: ' // ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' , ' syntax--punctuation syntax--definition syntax--comment syntax--js ' ] } ,
{ text: ' http://github.com ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' ] }
2016-07-26 22:39:41 +03:00
]
2013-12-31 21:43:05 +04:00
2014-02-18 02:58:55 +04:00
waitsForPromise ->
2014-03-06 08:34:31 +04:00
atom . packages . activatePackage ( ' language-hyperlink ' )
2014-02-11 03:22:00 +04:00
2014-02-18 02:58:55 +04:00
runs ->
2016-03-25 12:49:32 +03:00
tokens = editor . tokensForScreenRow ( 0 )
2016-07-26 22:39:41 +03:00
expect ( tokens ) . toEqual [
2017-05-05 10:04:34 +03:00
{ text: ' // ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' , ' syntax--punctuation syntax--definition syntax--comment syntax--js ' ] } ,
{ text: ' ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' ] }
{ text: ' http://github.com ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' , ' syntax--markup syntax--underline syntax--link syntax--http syntax--hyperlink ' ] }
2016-07-26 22:39:41 +03:00
]
2014-03-06 08:34:31 +04:00
describe " when the grammar is updated " , ->
it " retokenizes existing buffers that contain tokens that match the injection selector " , ->
2014-04-23 04:52:28 +04:00
waitsForPromise ->
atom . workspace . open ( ' sample.js ' ) . then (o) -> editor = o
2014-03-06 08:34:31 +04:00
2014-04-23 04:52:28 +04:00
runs ->
editor . setText ( " // SELECT * FROM OCTOCATS " )
2016-03-25 12:49:32 +03:00
tokens = editor . tokensForScreenRow ( 0 )
2016-07-26 22:39:41 +03:00
expect ( tokens ) . toEqual [
2017-05-05 10:04:34 +03:00
{ text: ' // ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' , ' syntax--punctuation syntax--definition syntax--comment syntax--js ' ] } ,
{ text: ' SELECT * FROM OCTOCATS ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' ] }
2016-07-26 22:39:41 +03:00
]
2013-12-31 21:43:05 +04:00
2014-03-06 08:34:31 +04:00
waitsForPromise ->
atom . packages . activatePackage ( ' package-with-injection-selector ' )
2013-12-31 21:43:05 +04:00
2014-03-06 08:34:31 +04:00
runs ->
2016-03-25 12:49:32 +03:00
tokens = editor . tokensForScreenRow ( 0 )
2016-07-26 22:39:41 +03:00
expect ( tokens ) . toEqual [
2017-05-05 10:04:34 +03:00
{ text: ' // ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' , ' syntax--punctuation syntax--definition syntax--comment syntax--js ' ] } ,
{ text: ' SELECT * FROM OCTOCATS ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' ] }
2016-07-26 22:39:41 +03:00
]
2014-03-06 08:34:31 +04:00
waitsForPromise ->
atom . packages . activatePackage ( ' language-sql ' )
runs ->
2016-03-25 12:49:32 +03:00
tokens = editor . tokensForScreenRow ( 0 )
2016-07-26 22:39:41 +03:00
expect ( tokens ) . toEqual [
2017-05-05 10:04:34 +03:00
{ text: ' // ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' , ' syntax--punctuation syntax--definition syntax--comment syntax--js ' ] } ,
{ text: ' ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' ] } ,
{ text: ' SELECT ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' , ' syntax--keyword syntax--other syntax--DML syntax--sql ' ] } ,
{ text: ' ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' ] } ,
{ text: ' * ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' , ' syntax--keyword syntax--operator syntax--star syntax--sql ' ] } ,
{ text: ' ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' ] } ,
{ text: ' FROM ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' , ' syntax--keyword syntax--other syntax--DML syntax--sql ' ] } ,
{ text: ' OCTOCATS ' , scopes: [ ' syntax--source syntax--js ' , ' syntax--comment syntax--line syntax--double-slash syntax--js ' ] }
2016-07-26 22:39:41 +03:00
]
2014-03-11 04:54:34 +04:00
describe " .normalizeTabsInBufferRange() " , ->
2014-03-11 05:43:38 +04:00
it " normalizes tabs depending on the editor ' s soft tab/tab length settings " , ->
2014-03-11 04:54:34 +04:00
editor . setTabLength ( 1 )
editor . setSoftTabs ( true )
editor . setText ( ' \t \t \t ' )
editor . normalizeTabsInBufferRange ( [ [ 0 , 0 ] , [ 0 , 1 ] ] )
expect ( editor . getText ( ) ) . toBe ' \t \t '
editor . setTabLength ( 2 )
editor . normalizeTabsInBufferRange ( [ [ 0 , 0 ] , [ Infinity , Infinity ] ] )
expect ( editor . getText ( ) ) . toBe ' '
editor . setSoftTabs ( false )
editor . normalizeTabsInBufferRange ( [ [ 0 , 0 ] , [ Infinity , Infinity ] ] )
expect ( editor . getText ( ) ) . toBe ' '
2014-04-23 02:43:32 +04:00
2014-04-23 02:56:52 +04:00
describe " .pageUp/Down() " , ->
2015-08-28 22:39:14 +03:00
it " moves the cursor down one page length " , ->
2017-04-20 00:52:03 +03:00
editor . update ( autoHeight: false )
element = editor . getElement ( )
jasmine . attachToDOM ( element )
element.style.height = element . component . getLineHeight ( ) * 5 + ' px '
element . measureDimensions ( )
2015-09-29 09:24:28 +03:00
2014-06-12 04:19:59 +04:00
expect ( editor . getCursorBufferPosition ( ) . row ) . toBe 0
2014-04-23 02:56:52 +04:00
editor . pageDown ( )
2014-06-12 04:19:59 +04:00
expect ( editor . getCursorBufferPosition ( ) . row ) . toBe 5
2014-04-23 02:56:52 +04:00
editor . pageDown ( )
2014-06-12 04:19:59 +04:00
expect ( editor . getCursorBufferPosition ( ) . row ) . toBe 10
2014-04-23 02:56:52 +04:00
editor . pageUp ( )
2014-06-12 04:19:59 +04:00
expect ( editor . getCursorBufferPosition ( ) . row ) . toBe 5
2014-04-23 02:56:52 +04:00
editor . pageUp ( )
2014-06-12 04:19:59 +04:00
expect ( editor . getCursorBufferPosition ( ) . row ) . toBe 0
2014-06-20 22:42:35 +04:00
describe " .selectPageUp/Down() " , ->
2014-06-20 22:50:48 +04:00
it " selects one screen height of text up or down " , ->
2017-04-20 00:52:03 +03:00
editor . update ( autoHeight: false )
element = editor . getElement ( )
jasmine . attachToDOM ( element )
element.style.height = element . component . getLineHeight ( ) * 5 + ' px '
element . measureDimensions ( )
2015-09-29 09:24:28 +03:00
2014-06-20 22:42:35 +04:00
expect ( editor . getCursorBufferPosition ( ) . row ) . toBe 0
editor . selectPageDown ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 0 ] , [ 5 , 0 ] ] ]
2014-06-20 22:42:35 +04:00
editor . selectPageDown ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 0 ] , [ 10 , 0 ] ] ]
2014-06-20 22:42:35 +04:00
editor . selectPageDown ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 0 ] , [ 12 , 2 ] ] ]
2014-06-20 22:42:35 +04:00
2014-08-29 02:25:12 +04:00
editor . moveToBottom ( )
2014-06-20 22:42:35 +04:00
editor . selectPageUp ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 7 , 0 ] , [ 12 , 2 ] ] ]
2014-06-20 22:42:35 +04:00
editor . selectPageUp ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 2 , 0 ] , [ 12 , 2 ] ] ]
2014-06-20 22:42:35 +04:00
editor . selectPageUp ( )
2015-05-23 02:50:04 +03:00
expect ( editor . getSelectedBufferRanges ( ) ) . toEqual [ [ [ 0 , 0 ] , [ 12 , 2 ] ] ]
2014-09-23 04:21:42 +04:00
2016-04-05 18:40:24 +03:00
describe " ::scrollToScreenPosition(position, [options]) " , ->
it " triggers ::onDidRequestAutoscroll with the logical coordinates along with the options " , ->
scrollSpy = jasmine . createSpy ( " ::onDidRequestAutoscroll " )
editor . onDidRequestAutoscroll ( scrollSpy )
editor . scrollToScreenPosition ( [ 8 , 20 ] )
editor . scrollToScreenPosition ( [ 8 , 20 ] , center: true )
editor . scrollToScreenPosition ( [ 8 , 20 ] , center: false , reversed: true )
expect ( scrollSpy ) . toHaveBeenCalledWith ( screenRange: [ [ 8 , 20 ] , [ 8 , 20 ] ] , options: { } )
expect ( scrollSpy ) . toHaveBeenCalledWith ( screenRange: [ [ 8 , 20 ] , [ 8 , 20 ] ] , options: { center: true } )
expect ( scrollSpy ) . toHaveBeenCalledWith ( screenRange: [ [ 8 , 20 ] , [ 8 , 20 ] ] , options: { center: false , reversed: true } )
2016-06-30 16:08:51 +03:00
describe " scroll past end " , ->
2016-08-11 21:10:54 +03:00
it " returns false by default but can be customized " , ->
2016-06-30 16:08:51 +03:00
expect ( editor . getScrollPastEnd ( ) ) . toBe ( false )
2016-08-12 01:34:54 +03:00
editor . update ( { scrollPastEnd: true } )
2016-06-30 16:08:51 +03:00
expect ( editor . getScrollPastEnd ( ) ) . toBe ( true )
2016-08-12 01:34:54 +03:00
editor . update ( { scrollPastEnd: false } )
2016-08-11 21:10:54 +03:00
expect ( editor . getScrollPastEnd ( ) ) . toBe ( false )
2016-06-30 16:08:51 +03:00
2017-05-04 15:36:42 +03:00
it " always returns false when autoHeight is on " , ->
editor . update ( { autoHeight: true , scrollPastEnd: true } )
expect ( editor . getScrollPastEnd ( ) ) . toBe ( false )
editor . update ( { autoHeight: false } )
expect ( editor . getScrollPastEnd ( ) ) . toBe ( true )
2016-06-30 16:27:47 +03:00
describe " auto height " , ->
2016-08-17 20:57:35 +03:00
it " returns true by default but can be customized " , ->
2016-10-10 10:28:36 +03:00
editor = new TextEditor
2016-08-17 20:57:35 +03:00
expect ( editor . getAutoHeight ( ) ) . toBe ( true )
2016-08-16 02:45:05 +03:00
editor . update ( { autoHeight: false } )
2016-06-30 16:27:47 +03:00
expect ( editor . getAutoHeight ( ) ) . toBe ( false )
2016-08-16 02:45:05 +03:00
editor . update ( { autoHeight: true } )
2016-06-30 16:27:47 +03:00
expect ( editor . getAutoHeight ( ) ) . toBe ( true )
2016-08-18 23:01:08 +03:00
editor . destroy ( )
2016-06-30 16:27:47 +03:00
2016-08-17 15:10:11 +03:00
describe " auto width " , ->
it " returns false by default but can be customized " , ->
expect ( editor . getAutoWidth ( ) ) . toBe ( false )
editor . update ( { autoWidth: true } )
expect ( editor . getAutoWidth ( ) ) . toBe ( true )
editor . update ( { autoWidth: false } )
expect ( editor . getAutoWidth ( ) ) . toBe ( false )
2014-09-23 04:21:42 +04:00
describe ' .get/setPlaceholderText() ' , ->
it ' can be created with placeholderText ' , ->
2016-10-10 10:28:36 +03:00
newEditor = new TextEditor ( {
2014-09-23 04:21:42 +04:00
mini: true
placeholderText: ' yep '
2016-10-10 10:28:36 +03:00
} )
2014-09-23 04:21:42 +04:00
expect ( newEditor . getPlaceholderText ( ) ) . toBe ' yep '
it ' models placeholderText and emits an event when changed ' , ->
editor . onDidChangePlaceholderText handler = jasmine . createSpy ( )
2014-09-23 21:38:38 +04:00
expect ( editor . getPlaceholderText ( ) ) . toBeUndefined ( )
2014-09-23 04:21:42 +04:00
editor . setPlaceholderText ( ' OK ' )
expect ( handler ) . toHaveBeenCalledWith ' OK '
expect ( editor . getPlaceholderText ( ) ) . toBe ' OK '
2015-02-25 02:30:04 +03:00
2015-02-02 04:58:54 +03:00
describe ' gutters ' , ->
2015-02-03 19:50:10 +03:00
describe ' the TextEditor constructor ' , ->
it ' creates a line-number gutter ' , ->
expect ( editor . getGutters ( ) . length ) . toBe 1
lineNumberGutter = editor . gutterWithName ( ' line-number ' )
expect ( lineNumberGutter . name ) . toBe ' line-number '
expect ( lineNumberGutter . priority ) . toBe 0
2015-02-02 04:58:54 +03:00
describe ' ::addGutter ' , ->
it ' can add a gutter ' , ->
2015-02-03 19:50:10 +03:00
expect ( editor . getGutters ( ) . length ) . toBe 1 # line-number gutter
2015-02-02 04:58:54 +03:00
options =
name: ' test-gutter '
priority: 1
gutter = editor . addGutter options
2015-02-03 19:50:10 +03:00
expect ( editor . getGutters ( ) . length ) . toBe 2
expect ( editor . getGutters ( ) [ 1 ] ) . toBe gutter
it " does not allow a custom gutter with the ' line-number ' name. " , ->
expect ( editor . addGutter . bind ( editor , { name: ' line-number ' } ) ) . toThrow ( )
2015-02-04 05:34:51 +03:00
2015-10-27 04:02:11 +03:00
describe ' ::decorateMarker ' , ->
[ marker ] = [ ]
2015-02-04 05:34:51 +03:00
2015-10-27 04:02:11 +03:00
beforeEach ->
marker = editor . markBufferRange ( [ [ 1 , 0 ] , [ 1 , 0 ] ] )
it ' reflects an added decoration when one of its custom gutters is decorated. ' , ->
gutter = editor . addGutter { ' name ' : ' custom-gutter ' }
decoration = gutter . decorateMarker marker , { class : ' custom-class ' }
gutterDecorations = editor . getDecorations
type: ' gutter '
gutterName: ' custom-gutter '
class : ' custom-class '
expect ( gutterDecorations . length ) . toBe 1
expect ( gutterDecorations [ 0 ] ) . toBe decoration
it ' reflects an added decoration when its line-number gutter is decorated. ' , ->
decoration = editor . gutterWithName ( ' line-number ' ) . decorateMarker marker , { class : ' test-class ' }
gutterDecorations = editor . getDecorations
type: ' line-number '
gutterName: ' line-number '
class : ' test-class '
expect ( gutterDecorations . length ) . toBe 1
expect ( gutterDecorations [ 0 ] ) . toBe decoration
describe ' ::observeGutters ' , ->
[ payloads , callback ] = [ ]
2015-03-13 01:48:25 +03:00
2015-10-27 04:02:11 +03:00
beforeEach ->
payloads = [ ]
callback = (payload) ->
payloads . push ( payload )
2015-03-13 01:48:25 +03:00
2015-10-27 04:02:11 +03:00
it ' calls the callback immediately with each existing gutter, and with each added gutter after that. ' , ->
lineNumberGutter = editor . gutterWithName ( ' line-number ' )
editor . observeGutters ( callback )
expect ( payloads ) . toEqual [ lineNumberGutter ]
gutter1 = editor . addGutter ( { name: ' test-gutter-1 ' } )
expect ( payloads ) . toEqual [ lineNumberGutter , gutter1 ]
gutter2 = editor . addGutter ( { name: ' test-gutter-2 ' } )
expect ( payloads ) . toEqual [ lineNumberGutter , gutter1 , gutter2 ]
it ' does not call the callback when a gutter is removed. ' , ->
gutter = editor . addGutter ( { name: ' test-gutter ' } )
editor . observeGutters ( callback )
payloads = [ ]
gutter . destroy ( )
expect ( payloads ) . toEqual [ ]
it ' does not call the callback after the subscription has been disposed. ' , ->
subscription = editor . observeGutters ( callback )
payloads = [ ]
subscription . dispose ( )
editor . addGutter ( { name: ' test-gutter ' } )
expect ( payloads ) . toEqual [ ]
describe ' ::onDidAddGutter ' , ->
[ payloads , callback ] = [ ]
2015-03-13 01:48:25 +03:00
2015-10-27 04:02:11 +03:00
beforeEach ->
payloads = [ ]
callback = (payload) ->
payloads . push ( payload )
it ' calls the callback with each newly-added gutter, but not with existing gutters. ' , ->
editor . onDidAddGutter ( callback )
expect ( payloads ) . toEqual [ ]
gutter = editor . addGutter ( { name: ' test-gutter ' } )
expect ( payloads ) . toEqual [ gutter ]
it ' does not call the callback after the subscription has been disposed. ' , ->
subscription = editor . onDidAddGutter ( callback )
payloads = [ ]
subscription . dispose ( )
editor . addGutter ( { name: ' test-gutter ' } )
expect ( payloads ) . toEqual [ ]
describe ' ::onDidRemoveGutter ' , ->
[ payloads , callback ] = [ ]
2015-03-13 01:48:25 +03:00
2015-10-27 04:02:11 +03:00
beforeEach ->
payloads = [ ]
callback = (payload) ->
payloads . push ( payload )
it ' calls the callback when a gutter is removed. ' , ->
gutter = editor . addGutter ( { name: ' test-gutter ' } )
editor . onDidRemoveGutter ( callback )
expect ( payloads ) . toEqual [ ]
gutter . destroy ( )
expect ( payloads ) . toEqual [ ' test-gutter ' ]
it ' does not call the callback after the subscription has been disposed. ' , ->
gutter = editor . addGutter ( { name: ' test-gutter ' } )
subscription = editor . onDidRemoveGutter ( callback )
subscription . dispose ( )
gutter . destroy ( )
expect ( payloads ) . toEqual [ ]
2015-03-13 01:48:25 +03:00
2015-10-27 04:03:19 +03:00
describe " decorations " , ->
describe " ::decorateMarker " , ->
2015-10-29 00:08:50 +03:00
it " includes the decoration in the object returned from ::decorationsStateForScreenRowRange " , ->
2015-10-27 04:03:19 +03:00
marker = editor . markBufferRange ( [ [ 2 , 4 ] , [ 6 , 8 ] ] )
decoration = editor . decorateMarker ( marker , type: ' highlight ' , class : ' foo ' )
2015-10-29 00:08:50 +03:00
expect ( editor . decorationsStateForScreenRowRange ( 0 , 5 ) [ decoration . id ] ) . toEqual {
2015-10-27 04:08:02 +03:00
properties: { type: ' highlight ' , class : ' foo ' }
2015-10-27 04:03:19 +03:00
screenRange: marker . getScreenRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker . getBufferRange ( ) ,
2015-10-27 23:05:22 +03:00
rangeIsReversed: false
}
2016-08-04 22:37:51 +03:00
it " does not throw errors after the marker ' s containing layer is destroyed " , ->
layer = editor . addMarkerLayer ( )
marker = layer . markBufferRange ( [ [ 2 , 4 ] , [ 6 , 8 ] ] )
decoration = editor . decorateMarker ( marker , type: ' highlight ' , class : ' foo ' )
layer . destroy ( )
editor . decorationsStateForScreenRowRange ( 0 , 5 )
2015-10-27 23:05:22 +03:00
describe " ::decorateMarkerLayer " , ->
2015-10-29 00:08:50 +03:00
it " based on the markers in the layer, includes multiple decoration objects with the same properties and different ranges in the object returned from ::decorationsStateForScreenRowRange " , ->
2015-10-27 23:05:22 +03:00
layer1 = editor . getBuffer ( ) . addMarkerLayer ( )
marker1 = layer1 . markRange ( [ [ 2 , 4 ] , [ 6 , 8 ] ] )
marker2 = layer1 . markRange ( [ [ 11 , 0 ] , [ 11 , 12 ] ] )
layer2 = editor . getBuffer ( ) . addMarkerLayer ( )
marker3 = layer2 . markRange ( [ [ 8 , 0 ] , [ 9 , 0 ] ] )
layer1Decoration1 = editor . decorateMarkerLayer ( layer1 , type: ' highlight ' , class : ' foo ' )
layer1Decoration2 = editor . decorateMarkerLayer ( layer1 , type: ' highlight ' , class : ' bar ' )
layer2Decoration = editor . decorateMarkerLayer ( layer2 , type: ' highlight ' , class : ' baz ' )
2015-10-29 00:08:50 +03:00
decorationState = editor . decorationsStateForScreenRowRange ( 0 , 13 )
2015-10-27 23:05:22 +03:00
expect ( decorationState [ " #{ layer1Decoration1 . id } - #{ marker1 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' foo ' } ,
screenRange: marker1 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker1 . getRange ( ) ,
2015-10-27 23:05:22 +03:00
rangeIsReversed: false
}
expect ( decorationState [ " #{ layer1Decoration1 . id } - #{ marker2 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' foo ' } ,
screenRange: marker2 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker2 . getRange ( ) ,
2015-10-27 23:05:22 +03:00
rangeIsReversed: false
}
expect ( decorationState [ " #{ layer1Decoration2 . id } - #{ marker1 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' bar ' } ,
screenRange: marker1 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker1 . getRange ( ) ,
2015-10-27 23:05:22 +03:00
rangeIsReversed: false
}
expect ( decorationState [ " #{ layer1Decoration2 . id } - #{ marker2 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' bar ' } ,
screenRange: marker2 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker2 . getRange ( ) ,
2015-10-27 23:05:22 +03:00
rangeIsReversed: false
}
expect ( decorationState [ " #{ layer2Decoration . id } - #{ marker3 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' baz ' } ,
screenRange: marker3 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker3 . getRange ( ) ,
2015-10-27 23:05:22 +03:00
rangeIsReversed: false
}
layer1Decoration1 . destroy ( )
2015-10-29 00:08:50 +03:00
decorationState = editor . decorationsStateForScreenRowRange ( 0 , 12 )
2015-10-27 23:05:22 +03:00
expect ( decorationState [ " #{ layer1Decoration1 . id } - #{ marker1 . id } " ] ) . toBeUndefined ( )
expect ( decorationState [ " #{ layer1Decoration1 . id } - #{ marker2 . id } " ] ) . toBeUndefined ( )
expect ( decorationState [ " #{ layer1Decoration2 . id } - #{ marker1 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' bar ' } ,
screenRange: marker1 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker1 . getRange ( ) ,
2015-10-27 23:05:22 +03:00
rangeIsReversed: false
}
expect ( decorationState [ " #{ layer1Decoration2 . id } - #{ marker2 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' bar ' } ,
screenRange: marker2 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker2 . getRange ( ) ,
2015-10-27 23:05:22 +03:00
rangeIsReversed: false
}
expect ( decorationState [ " #{ layer2Decoration . id } - #{ marker3 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' baz ' } ,
screenRange: marker3 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker3 . getRange ( ) ,
2015-10-27 23:05:22 +03:00
rangeIsReversed: false
2015-10-27 04:03:19 +03:00
}
2015-10-29 00:07:21 +03:00
layer1Decoration2 . setPropertiesForMarker ( marker1 , { type: ' highlight ' , class : ' quux ' } )
2015-10-29 00:08:50 +03:00
decorationState = editor . decorationsStateForScreenRowRange ( 0 , 12 )
2015-10-29 00:07:21 +03:00
expect ( decorationState [ " #{ layer1Decoration2 . id } - #{ marker1 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' quux ' } ,
screenRange: marker1 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker1 . getRange ( ) ,
2015-10-29 00:07:21 +03:00
rangeIsReversed: false
}
layer1Decoration2 . setPropertiesForMarker ( marker1 , null )
2015-10-29 00:08:50 +03:00
decorationState = editor . decorationsStateForScreenRowRange ( 0 , 12 )
2015-10-29 00:07:21 +03:00
expect ( decorationState [ " #{ layer1Decoration2 . id } - #{ marker1 . id } " ] ) . toEqual {
properties: { type: ' highlight ' , class : ' bar ' } ,
screenRange: marker1 . getRange ( ) ,
2016-04-26 13:09:38 +03:00
bufferRange: marker1 . getRange ( ) ,
2015-10-29 00:07:21 +03:00
rangeIsReversed: false
}
2016-03-01 19:07:55 +03:00
2016-07-12 03:02:48 +03:00
describe " invisibles " , ->
2016-07-26 22:39:41 +03:00
beforeEach ->
2016-08-16 02:45:05 +03:00
editor . update ( { showInvisibles: true } )
2016-07-26 22:39:41 +03:00
2016-07-12 03:02:48 +03:00
it " substitutes invisible characters according to the given rules " , ->
2016-07-11 23:52:05 +03:00
previousLineText = editor . lineTextForScreenRow ( 0 )
2016-08-16 02:45:05 +03:00
editor . update ( { invisibles: { eol: ' ? ' } } )
2016-07-11 23:52:05 +03:00
expect ( editor . lineTextForScreenRow ( 0 ) ) . not . toBe ( previousLineText )
expect ( editor . lineTextForScreenRow ( 0 ) . endsWith ( ' ? ' ) ) . toBe ( true )
expect ( editor . getInvisibles ( ) ) . toEqual ( eol: ' ? ' )
2016-07-12 03:02:48 +03:00
it " does not use invisibles if showInvisibles is set to false " , ->
2016-08-16 02:45:05 +03:00
editor . update ( { invisibles: { eol: ' ? ' } } )
2016-07-12 03:02:48 +03:00
expect ( editor . lineTextForScreenRow ( 0 ) . endsWith ( ' ? ' ) ) . toBe ( true )
2016-08-16 02:45:05 +03:00
editor . update ( { showInvisibles: false } )
2016-07-12 03:02:48 +03:00
expect ( editor . lineTextForScreenRow ( 0 ) . endsWith ( ' ? ' ) ) . toBe ( false )
2016-05-01 12:42:28 +03:00
describe " indent guides " , ->
it " shows indent guides when `editor.showIndentGuide` is set to true and the editor is not mini " , ->
editor . setText ( " foo " )
2016-07-12 03:02:48 +03:00
editor . setTabLength ( 2 )
2016-05-01 12:42:28 +03:00
2016-08-12 23:21:41 +03:00
editor . update ( { showIndentGuide: false } )
2016-07-26 22:39:41 +03:00
expect ( editor . tokensForScreenRow ( 0 ) ) . toEqual [
2017-05-05 10:04:34 +03:00
{ text: ' ' , scopes: [ ' syntax--source syntax--js ' , ' leading-whitespace ' ] } ,
{ text: ' foo ' , scopes: [ ' syntax--source syntax--js ' ] }
2016-07-26 22:39:41 +03:00
]
2016-05-01 12:42:28 +03:00
2016-08-12 23:21:41 +03:00
editor . update ( { showIndentGuide: true } )
2016-07-26 22:39:41 +03:00
expect ( editor . tokensForScreenRow ( 0 ) ) . toEqual [
2017-05-05 10:04:34 +03:00
{ text: ' ' , scopes: [ ' syntax--source syntax--js ' , ' leading-whitespace indent-guide ' ] } ,
{ text: ' foo ' , scopes: [ ' syntax--source syntax--js ' ] }
2016-07-26 22:39:41 +03:00
]
2016-05-01 12:42:28 +03:00
editor . setMini ( true )
2016-07-26 22:39:41 +03:00
expect ( editor . tokensForScreenRow ( 0 ) ) . toEqual [
2017-05-05 10:04:34 +03:00
{ text: ' ' , scopes: [ ' syntax--source syntax--js ' , ' leading-whitespace ' ] } ,
{ text: ' foo ' , scopes: [ ' syntax--source syntax--js ' ] }
2016-07-26 22:39:41 +03:00
]
2015-03-13 01:48:25 +03:00
2016-03-03 18:09:18 +03:00
describe " when the editor is constructed with the grammar option set " , ->
2015-03-13 01:48:25 +03:00
beforeEach ->
2016-03-01 19:43:38 +03:00
waitsForPromise ->
atom . packages . activatePackage ( ' language-coffee-script ' )
it " sets the grammar " , ->
2016-10-07 19:21:09 +03:00
editor = new TextEditor ( { grammar: atom . grammars . grammarForScopeName ( ' source.coffee ' ) } )
2016-03-01 19:43:38 +03:00
expect ( editor . getGrammar ( ) . name ) . toBe ' CoffeeScript '
2016-08-16 02:45:05 +03:00
describe " softWrapAtPreferredLineLength " , ->
2017-02-07 06:59:47 +03:00
it " soft wraps the editor at the preferred line length unless the editor is narrower or the editor is mini " , ->
2016-08-16 02:45:05 +03:00
editor . update ( {
editorWidthInChars: 30
softWrapped: true
softWrapAtPreferredLineLength: true
preferredLineLength: 20
} )
2016-06-16 17:42:30 +03:00
expect ( editor . lineTextForScreenRow ( 0 ) ) . toBe ' var quicksort = '
2016-08-16 02:45:05 +03:00
editor . update ( { editorWidthInChars: 10 } )
2016-06-16 17:42:30 +03:00
expect ( editor . lineTextForScreenRow ( 0 ) ) . toBe ' var '
2017-02-07 06:59:47 +03:00
editor . update ( { mini: true } )
expect ( editor . lineTextForScreenRow ( 0 ) ) . toBe ' var quicksort = function () { '
2016-08-12 02:38:31 +03:00
describe " softWrapHangingIndentLength " , ->
2016-08-03 02:20:23 +03:00
it " controls how much extra indentation is applied to soft-wrapped lines " , ->
editor . setText ( ' 123456789 ' )
2016-08-16 02:45:05 +03:00
editor . update ( {
editorWidthInChars: 8
softWrapped: true
softWrapHangingIndentLength: 2
} )
2016-08-03 02:20:23 +03:00
expect ( editor . lineTextForScreenRow ( 1 ) ) . toEqual ' 9 '
2016-08-12 02:38:31 +03:00
editor . update ( { softWrapHangingIndentLength: 4 } )
2016-08-03 02:20:23 +03:00
expect ( editor . lineTextForScreenRow ( 1 ) ) . toEqual ' 9 '
2016-03-01 19:07:55 +03:00
describe " ::getElement " , ->
it " returns an element " , ->
expect ( editor . getElement ( ) instanceof HTMLElement ) . toBe ( true )