Yes we can

This commit is contained in:
jazzpi 2015-03-22 14:17:43 +01:00
parent d1295587ee
commit 433b1dd6ac
2 changed files with 28 additions and 27 deletions

View file

@ -1,26 +1,27 @@
module.exports = {
findLines: (lines, pattern) ->
# TODO: There's gotta be a better way to do this. Can we use vim-mode's
# search or find-and-replace maybe?
return (i for line, i in lines when line.match(pattern))
findInBuffer : (buffer, pattern) ->
found = []
buffer.scan(new RegExp(pattern, 'g'), (obj) -> found.push obj.range)
return found
findNext: (lines, pattern, curLine) ->
lines = @findLines(lines, pattern)
if lines.length == 0
return null
more = (i for i in lines when i > curLine)
findNextInBuffer : (buffer, curPos, pattern) ->
found = @findInBuffer(buffer, pattern)
more = (i for i in found when i.compare([curPos, curPos]) is 1)
if more.length > 0
return more[0]
return more[0].start.row
else if found.length > 0
return found[0].start.row
else
return lines[0]
findPrevious: (lines, pattern, curLine) ->
lines = @findLines(lines, pattern)
if lines.length == 0
return null
less = (i for i in lines when i < curLine)
findPreviousInBuffer : (buffer, curPos, pattern) ->
found = @findInBuffer(buffer, pattern)
console.log found, curPos
less = (i for i in found when i.compare([curPos, curPos]) is -1)
if less.length > 0
return less[0]
return less[less.length - 1].start.row
else if found.length > 0
return found[found.length - 1].start.row
else
return lines[lines.length - 1]
return null
}