From 4e35bc22e052bd4ef74b8ad2d23f2b1a6e51fc7d Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 4 Mar 2011 01:23:30 +0000 Subject: vim-mode/vim_mode: make :mapped commands use appropriate context when calling irssi commands. --- vim-mode/vim_mode.pl | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'vim-mode') diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 7f4832e..551fbb6 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -2537,13 +2537,7 @@ sub handle_command_cmd { } elsif ($cmd->{type} == C_IRSSI) { print "Processing irssi-command: $map->{char} ($cmd->{char})" if DEBUG; - # TODO: fix me more better (general server/win/none context?) - my $server = Irssi::active_server; - if (defined $server) { - $server->command($cmd->{func}); - } else { - Irssi::command($cmd->{func}); - } + _command_with_context($cmd->{func}); $numeric_prefix = undef; return 1; # call _stop(); @@ -3206,3 +3200,29 @@ sub _warn { print '%_vim_mode: ', $warning, '%_'; } + +sub _command_with_context { + my ($command) = @_; + my $context; + my $window = Irssi::active_win; + if (defined $window) { + my $witem = $window->{active}; + if (defined $witem and ref($witem) eq 'Irssi::Windowitem') { + $context = $witem; + } else { + $context = $window; + } + } else { + my $server = Irssi::active_server; + if (defined $server) { + $context = $server; + } + } + if (defined $context) { + print "Command $command Using context: " . ref($context) if DEBUG; + $context->command($command); + } else { + print "Command $command has no context" if DEBUG; + Irssi::command($command); + } +} -- cgit v1.2.3