Class: Yatte::FindReplace
- Inherits:
-
Object
- Object
- Yatte::FindReplace
- Defined in:
- lib/yatte/find_replace.rb
Overview
Interactive Ctrl+H find-and-replace. Prompts for query and replacement, then walks matches asking y/n/a/ESC for each.
Instance Method Summary collapse
-
#initialize(buffer:, cursor:, undo_stack:, input:, prompt:, status:) ⇒ FindReplace
constructor
A new instance of FindReplace.
- #run ⇒ Object
Constructor Details
#initialize(buffer:, cursor:, undo_stack:, input:, prompt:, status:) ⇒ FindReplace
Returns a new instance of FindReplace.
7 8 9 10 11 12 13 14 |
# File 'lib/yatte/find_replace.rb', line 7 def initialize(buffer:, cursor:, undo_stack:, input:, prompt:, status:) @buffer = buffer @cursor = cursor @undo_stack = undo_stack @input = input @prompt = prompt @status = status end |
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/yatte/find_replace.rb', line 16 def run query = @prompt.call("Find: ") return unless query replacement = @prompt.call("Replace with: ") return unless replacement match = @buffer.find(query, 0, 0) unless match @status.call("No matches found.") return end @cursor.set(match[0], match[1]) walk_matches(query, replacement) end |