Selection/line running in cells plugin
@@ -51,18 +51,7 @@ def update_editor_cells(event):
break
-def _patch_perform_return():
- original_perform_return = CodeViewText.perform_return
-
- def _patched_perform_return(self, event):
- text = event.widget
- ranges = text.tag_ranges("CURRENT_CELL")
-
- if (len(ranges) == 2
- and (ui_utils.shift_is_pressed(event.state)
- or ui_utils.control_is_pressed(event.state))):
-
- code = text.get(ranges[0], ranges[1]).strip()
+def _submit_code(code):
lines = code.splitlines()
# remove starting comments
@@ -82,6 +71,21 @@ def _patch_perform_return():
shell = get_workbench().show_view("ShellView", False)
shell.submit_python_code(code)
+
+def _patch_perform_return():
+ original_perform_return = CodeViewText.perform_return
+
+ def _patched_perform_return(self, event):
+ text = event.widget
+ ranges = text.tag_ranges("CURRENT_CELL")
+
+ if (len(ranges) == 2
+ and (ui_utils.shift_is_pressed(event.state)
+ or ui_utils.control_is_pressed(event.state))):
+
+ code = text.get(ranges[0], ranges[1]).strip()
+ _submit_code(code)
+
if ui_utils.shift_is_pressed(event.state):
# advance to next cell
text.mark_set("insert", ranges[1])
@@ -123,7 +127,16 @@ def dummy(event=None):
def run_selection(event=None):
- print("run_selection")
+ widget = get_workbench().focus_get()
+ if isinstance(widget, CodeViewText):
+ text = widget
+
+ if text.has_selection():
+ code = text.get("sel.first", "sel.last")
+ else:
+ code = text.get("insert linestart", "insert lineend")
+
+ _submit_code(code)
def run_enabled():
return True
