Require single click for toggling a breakpoint,
@@ -4,6 +4,7 @@ import io
import os
import re
import sys
+import time
import tkinter as tk
from logging import getLogger
from tkinter import messagebox
@@ -168,7 +169,10 @@ class CodeView(tktextext.EnhancedTextFrame):
get_workbench().bind("SyntaxThemeChanged", self._reload_theme_options, True)
self._original_newlines = os.linesep
self._reload_theme_options()
- self._gutter.bind("<Double-Button-1>", self._toggle_breakpoint, True)
+ self._start_toggle_breakpoint_index = None
+ self._last_toggle_breakpoint_time = 0
+ self._gutter.bind("<Button-1>", self._start_toggle_breakpoint, True)
+ self._gutter.bind("<ButtonRelease-1>", self._consider_toggle_breakpoint, True)
# self.text.tag_configure("breakpoint_line", background="pink")
self._gutter.tag_configure("breakpoint", foreground="crimson")
@@ -274,8 +278,19 @@ class CodeView(tktextext.EnhancedTextFrame):
if not keep_undo:
self.text.edit_reset()
- def _toggle_breakpoint(self, event):
+ def _start_toggle_breakpoint(self, event):
+ self._start_toggle_breakpoint_index = "@%d,%d" % (event.x, event.y)
+
+ def _consider_toggle_breakpoint(self, event):
+ if time.time() - self._last_toggle_breakpoint_time < 0.3:
+ # it was probably a double-click. Don't want to double-toggle in this case.
+ return
+
index = "@%d,%d" % (event.x, event.y)
+ if index != self._start_toggle_breakpoint_index:
+ # it was probably a drag
+ return
+
start_index = index + " linestart"
end_index = index + " lineend"
@@ -287,6 +302,7 @@ class CodeView(tktextext.EnhancedTextFrame):
self.text.tag_add("breakpoint_line", start_index, end_index)
self.update_gutter(clean=True)
+ self._last_toggle_breakpoint_time = time.time()
def _clean_selection(self):
self.text.tag_remove("sel", "1.0", "end")
