diff options
author | aycabta <[email protected]> | 2021-12-20 14:36:37 +0900 |
---|---|---|
committer | git <[email protected]> | 2021-12-20 14:54:42 +0900 |
commit | 145c1e0691d4a6ca8eda40a42e584a1f6899fae2 (patch) | |
tree | df6e3e6184437c4a7d65db2a6672ca78988cbee4 /lib/reline/line_editor.rb | |
parent | c462e07a5c9cf80227926de40c00917445f5b53e (diff) |
[ruby/reline] Add support for overwriting dialog proc with the same name
https://github.com/ruby/reline/commit/16aa20c380
Diffstat (limited to 'lib/reline/line_editor.rb')
-rw-r--r-- | lib/reline/line_editor.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 4fbed471c3..657b3e7018 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -634,8 +634,12 @@ class Reline::LineEditor end def add_dialog_proc(name, p, context = nil) - return if @dialogs.any? { |d| d.name == name } - @dialogs << Dialog.new(name, @config, DialogProcScope.new(self, @config, p, context)) + dialog = Dialog.new(name, @config, DialogProcScope.new(self, @config, p, context)) + if index = @dialogs.find_index { |d| d.name == name } + @dialogs[index] = dialog + else + @dialogs << dialog + end end DIALOG_DEFAULT_HEIGHT = 20 |