From 4d3fa1eb30530344d7e7f42028c254b0aa65ce34 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Fri, 5 Apr 2024 12:04:33 +0200 Subject: [PATCH] fix blank screen under certain circumstances due to incorrect handling of capture groups --- src/fingers/hinter.cr | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/fingers/hinter.cr b/src/fingers/hinter.cr index 9d37ce6..9c35e4b 100644 --- a/src/fingers/hinter.cr +++ b/src/fingers/hinter.cr @@ -106,7 +106,7 @@ module Fingers def replace(match, line_index) text = match[0] - captured_text = match["match"]? || text + captured_text = captured_text_for_match(match) relative_capture_offset = relative_capture_offset_for_match(match, captured_text) absolute_offset = { @@ -114,7 +114,7 @@ module Fingers match.begin(0) + (relative_capture_offset ? relative_capture_offset[0] : 0) } - hint = hint_for_text(text) + hint = hint_for_text(captured_text) build_target(captured_text, hint, absolute_offset) if !state.input.empty? && !hint.starts_with?(state.input) @@ -129,6 +129,10 @@ module Fingers ) end + def captured_text_for_match(match) + match["match"]? || match[0] + end + def hint_for_text(text) return pop_hint! unless reuse_hints @@ -195,7 +199,7 @@ module Fingers lines.each do |line| line.scan(pattern) do |match| - match_set.add(match[0]?.not_nil!) + match_set.add(captured_text_for_match(match)) end end