aboutsummaryrefslogtreecommitdiffstats
path: root/vim-mode
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vim-mode/vim_mode.pl34
1 files changed, 27 insertions, 7 deletions
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);
+ }
+}