From 9e0caba187746acb03449ea5b08334cd6b68ea0a Mon Sep 17 00:00:00 2001 From: aycabta Date: Fri, 3 Sep 2021 03:29:10 +0900 Subject: [PATCH] [ruby/reline] Add Reline::Key#match? https://github.com/ruby/reline/commit/8f6aa3af2e --- lib/reline.rb | 8 +++++++- lib/reline/line_editor.rb | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index f1f82bff72..81619dea77 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -16,7 +16,13 @@ module Reline class ConfigEncodingConversionError < StandardError; end - Key = Struct.new('Key', :char, :combined_char, :with_meta) + Key = Struct.new('Key', :char, :combined_char, :with_meta) do + def match?(key) + (key.char.nil? or char.nil? or char == key.char) and + (key.combined_char.nil? or combined_char.nil? or combined_char == key.combined_char) and + (key.with_meta.nil? or with_meta.nil? or with_meta == key.with_meta) + end + end CursorPos = Struct.new(:x, :y) DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :width, :height, keyword_init: true) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 50aeac996f..d3020087bf 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1480,7 +1480,9 @@ class Reline::LineEditor @last_key = key @dialogs.each do |dialog| # The dialog will intercept the key if trap_key is set. - return if dialog.trap_key and key.combined_char == dialog.trap_key + if dialog.trap_key and dialog.trap_key.match?(key) + return + end end @just_cursor_moving = nil if key.char.nil?