get word under cursor


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # given a line and a cursor position returns the word
  2. # under the cursor. Takes only spaces into account, not punctuation
  3. # characters.
  4. def _get_word_under_cursor line, pos
  5. finish = line.index(" ", pos)
  6. start = line.rindex(" ",pos)
  7. finish = -1 if finish.nil?
  8. start = 0 if start.nil?
  9. return line[start..finish]
  10. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.