aboutsummaryrefslogtreecommitdiff
path: root/atom/packages/vim-mode/lib/utils.coffee
blob: 5a26310a43689d87ddcc11c3a7f2efae46362727 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{Range} = require 'atom'

module.exports =
  # Public: Determines if a string should be considered linewise or character
  #
  # text - The string to consider
  #
  # Returns 'linewise' if the string ends with a line return and 'character'
  #  otherwise.
  copyType: (text) ->
    if text.lastIndexOf("\n") is text.length - 1
      'linewise'
    else if text.lastIndexOf("\r") is text.length - 1
      'linewise'
    else
      'character'

  # Public: return a union of two ranges, or simply the newRange if the oldRange is empty.
  #
  # Returns a Range
  mergeRanges: (oldRange, newRange) ->
    oldRange = Range.fromObject oldRange
    newRange = Range.fromObject newRange
    if oldRange.isEmpty()
      newRange
    else
      oldRange.union(newRange)