import sublime, sublime_plugin
import os
from SublimePlumb.Mouse import MouseCommand

class SublimePlumbSend(MouseCommand):
    """ Sends the current selected text to the plumbing """
    def run(self, edit):
        file_name = self.view.file_name()
        message = {
            "data": self.view.substr(self.selection_at_cursor()),
            "cwd": os.path.dirname(file_name) if file_name else None,
            "src": self.view.id(),
        }
        self.view.run_command("sublime_plumb", message)
        self.remove_selection("1")
        self.view.sel().clear()
import sublime, sublime_plugin
import os
from SublimePlumb.Mouse import MouseCommand

class SublimePlumbSend(MouseCommand):
    """ Sends the current selected text to the plumbing """
    def run(self, edit):
        file_name = self.view.file_name()
        message = {
            "data": self.view.substr(self.selection_at_cursor()),
            "cwd": os.path.dirname(file_name) if file_name else None,
            "src": self.view.id(),
        }
        self.remove_selection("1") # in case it was expanded
        self.view.sel().clear()
        self.view.run_command("sublime_plumb", message)

Move selection clearing to before running the action
Move selection clearing to before running the action

This allows actions like "jump" to modify the selection

  import sublime, sublime_plugin
  import os
  from SublimePlumb.Mouse import MouseCommand
  
  class SublimePlumbSend(MouseCommand):
      """ Sends the current selected text to the plumbing """
      def run(self, edit):
          file_name = self.view.file_name()
          message = {
              "data": self.view.substr(self.selection_at_cursor()),
              "cwd": os.path.dirname(file_name) if file_name else None,
              "src": self.view.id(),
          }
+         self.remove_selection("1") # in case it was expanded
+         self.view.sel().clear()
          self.view.run_command("sublime_plumb", message)
+ 
-         self.remove_selection("1")
-         self.view.sel().clear()
Move selection clearing to before running the action
## Code Before:
import sublime, sublime_plugin
import os
from SublimePlumb.Mouse import MouseCommand

class SublimePlumbSend(MouseCommand):
    """ Sends the current selected text to the plumbing """
    def run(self, edit):
        file_name = self.view.file_name()
        message = {
            "data": self.view.substr(self.selection_at_cursor()),
            "cwd": os.path.dirname(file_name) if file_name else None,
            "src": self.view.id(),
        }
        self.view.run_command("sublime_plumb", message)
        self.remove_selection("1")
        self.view.sel().clear()
## Instruction:
Move selection clearing to before running the action
## Code After:
import sublime, sublime_plugin
import os
from SublimePlumb.Mouse import MouseCommand

class SublimePlumbSend(MouseCommand):
    """ Sends the current selected text to the plumbing """
    def run(self, edit):
        file_name = self.view.file_name()
        message = {
            "data": self.view.substr(self.selection_at_cursor()),
            "cwd": os.path.dirname(file_name) if file_name else None,
            "src": self.view.id(),
        }
        self.remove_selection("1") # in case it was expanded
        self.view.sel().clear()
        self.view.run_command("sublime_plumb", message)
