Skip to content

Commit

Permalink
Merge pull request #78 from idris-hackers/issue-72
Browse files Browse the repository at this point in the history
Insert initial clause in the next empty line
  • Loading branch information
archaeron committed Oct 17, 2015
2 parents ec0e39a + 4d01fa3 commit 549b094
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- Added a better description for the path to the idris executable in the settings
- Fixed the highlighting of comments
- Initial clause is inserted in wrong place for functions with multiline type annotation. [#72](https://github.com/idris-hackers/atom-language-idris/issues/72)

## v0.3.3

Expand Down
11 changes: 8 additions & 3 deletions lib/idris-controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Logger = require './Logger'
IdrisModel = require './idris-model'
Ipkg = require './utils/ipkg'
Symbol = require './utils/symbol'
editorHelper = require './utils/editor'

class IdrisController

Expand Down Expand Up @@ -157,11 +158,15 @@ class IdrisController
successHandler = ({ responseType, msg }) ->
[clause] = msg
editor.transact ->
# Insert a newline and the new clause
editor.insertNewlineBelow()
editorHelper.moveToNextEmptyLine editor

# Insert the new clause
editor.insertText clause

# And move the cursor to the beginning of
# the new line
# the new line and add an empty line below it
editor.insertNewlineBelow()
editor.moveUp()
editor.moveToBeginningOfLine()

@model
Expand Down
32 changes: 32 additions & 0 deletions lib/utils/editor.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
isCurrentLineEmpty = (editor) ->
# save the current buffer range, so that we can
# reset the state in the end
bufferRange = editor.getSelectedBufferRange()

editor.moveToBeginningOfLine()
editor.selectToEndOfLine()
selectedText = editor.getSelectedText()

# reset the selection to what it was before calling
# this function
editor.setSelectedBufferRange bufferRange

selectedText.trim() == ''

isCurrentLineLastOfFile = (editor) ->
currentRow = editor.getCursorBufferPosition().row
totalRows = editor.getLineCount()
currentRow == totalRows - 1

moveToNextEmptyLine = (editor) ->
while !isCurrentLineEmpty(editor) && !isCurrentLineLastOfFile(editor)
editor.moveDown()

if !isCurrentLineEmpty(editor)
editor.insertNewlineBelow()

editor.moveToBeginningOfLine()

module.exports =
isCurrentLineEmpty: isCurrentLineEmpty
moveToNextEmptyLine: moveToNextEmptyLine

0 comments on commit 549b094

Please sign in to comment.