Method: Textbringer::Commands#isearch_search

Defined in:
lib/textbringer/commands/isearch.rb

#isearch_searchObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/textbringer/commands/isearch.rb', line 132

def isearch_search
  forward = ISEARCH_STATUS[:forward]
  options = if /\A[A-Z]/.match?(ISEARCH_STATUS[:string])
              nil
            else
              Regexp::IGNORECASE
            end
  re = Regexp.new(Regexp.quote(ISEARCH_STATUS[:string]), options)
  last_pos = ISEARCH_STATUS[:last_pos]
  offset = forward ? last_pos : last_pos - ISEARCH_STATUS[:string].bytesize
  if offset >= 0 && Buffer.current.byteindex(forward, re, offset)
    if Buffer.current != Buffer.minibuffer
      message(isearch_prompt + ISEARCH_STATUS[:string], log: false)
    end
    Buffer.current.set_visible_mark(forward ? match_beginning(0) :
                                    match_end(0))
    goto_char(forward ? match_end(0) : match_beginning(0))
  else
    if Buffer.current != Buffer.minibuffer
      message("Failing " + isearch_prompt + ISEARCH_STATUS[:string],
              log: false)
    end
  end
end