select line on triple click
This commit is contained in:
15
bigtext.py
15
bigtext.py
@@ -117,6 +117,8 @@ class InnerBigText(QWidget):
|
||||
self.update_font_metrics(QPainter(self))
|
||||
self.lines = []
|
||||
self.selection_highlight = HighlightSelection()
|
||||
self._last_double_click_time = 0
|
||||
self._last_double_click_line_number = -1
|
||||
|
||||
def keyPressEvent(self, e: QKeyEvent) -> None:
|
||||
|
||||
@@ -184,6 +186,16 @@ class InnerBigText(QWidget):
|
||||
self.update()
|
||||
return
|
||||
|
||||
if e.buttons() == Qt.MouseButton.LeftButton and (time.time() - self._last_double_click_time) < 0.5:
|
||||
# triple click: select line
|
||||
line_number = self.y_pos_to_line(e.pos().y())
|
||||
if line_number == self._last_double_click_line_number and line_number < len(self.lines):
|
||||
line = self.lines[line_number]
|
||||
self.selection_highlight.set_start(line.byte_offset())
|
||||
self.selection_highlight.set_end_byte(line.byte_end())
|
||||
self.update()
|
||||
return
|
||||
|
||||
if e.buttons() == Qt.MouseButton.LeftButton and e.modifiers() == Qt.KeyboardModifier.NoModifier:
|
||||
offset = self.to_byte_offset(e)
|
||||
self.selection_highlight.set_start(offset)
|
||||
@@ -192,6 +204,9 @@ class InnerBigText(QWidget):
|
||||
|
||||
def mouseDoubleClickEvent(self, e: QtGui.QMouseEvent) -> None:
|
||||
if e.buttons() == Qt.MouseButton.LeftButton:
|
||||
self._last_double_click_time = time.time()
|
||||
self._last_double_click_line_number = self.y_pos_to_line(e.pos().y())
|
||||
|
||||
offset = self.to_byte_offset(e)
|
||||
(_word, start_byte, end_byte) = self.model.read_word_at(offset)
|
||||
if start_byte >= 0 and end_byte >= 0:
|
||||
|
||||
Reference in New Issue
Block a user