From 0bb5dd9f635cc7a70eafdd8c79f7e528ef07966b Mon Sep 17 00:00:00 2001 From: Jarkko Linnanvirta Date: Tue, 22 Feb 2022 19:50:46 +0200 Subject: [PATCH] #143: OutputChannelDriver_Modal: Disable redirection to channels that do not accept the stream. E.g. OutputChannelDriver_OpenFiles does not accept "stderr". --- .../OutputChannelDriver_Modal.ts | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/output_channels/OutputChannelDriver_Modal.ts b/src/output_channels/OutputChannelDriver_Modal.ts index 4d86b5f4..6cb7c193 100644 --- a/src/output_channels/OutputChannelDriver_Modal.ts +++ b/src/output_channels/OutputChannelDriver_Modal.ts @@ -115,21 +115,24 @@ class OutputModal extends Modal { // Ensure this channel is not excluded if (!excluded_output_channels.contains(output_channel_name)) { const output_channel_driver = output_channel_drivers[output_channel_name]; - redirect_setting.addButton(button => button - .setButtonText(output_channel_driver.getTitle(output_stream)) - .onClick(() => { - // Redirect output to the selected driver - const output_streams: OutputStreams = {}; - const textarea_element = textarea_setting.settingEl.find("textarea") as HTMLTextAreaElement; - output_streams[output_stream] = - getSelectionFromTextarea(textarea_element, true) // Use the selection, or... - ?? output_textarea.getValue() // ...use the whole text, if nothing is selected. - ; - output_channel_driver.initialize(this.plugin, this.t_shell_command, this.shell_command_parsing_result); - output_channel_driver.handle(output_streams, this.exit_code); - textarea_element.focus(); // Bring the focus back to the textarea in order to show a possible highlight (=selection) again. - }), - ); + // Ensure the output channel accepts this output stream. E.g. OutputChannelDriver_OpenFiles does not accept "stderr". + if (output_channel_driver.acceptsOutputStream(output_stream)) { + redirect_setting.addButton(button => button + .setButtonText(output_channel_driver.getTitle(output_stream)) + .onClick(() => { + // Redirect output to the selected driver + const output_streams: OutputStreams = {}; + const textarea_element = textarea_setting.settingEl.find("textarea") as HTMLTextAreaElement; + output_streams[output_stream] = + getSelectionFromTextarea(textarea_element, true) // Use the selection, or... + ?? output_textarea.getValue() // ...use the whole text, if nothing is selected. + ; + output_channel_driver.initialize(this.plugin, this.t_shell_command, this.shell_command_parsing_result); + output_channel_driver.handle(output_streams, this.exit_code); + textarea_element.focus(); // Bring the focus back to the textarea in order to show a possible highlight (=selection) again. + }), + ); + } } });