1313)
1414
1515from core .folding import FoldingManager
16+ from core .multi_cursor import MultiCursorManager
1617
1718
1819class LineNumberArea (QWidget ):
@@ -259,6 +260,8 @@ def __init__(self, parent=None):
259260
260261 self .FOLD_AREA_WIDTH = 14
261262 self .folding_manager = FoldingManager (self )
263+ self .multi_cursor_manager = MultiCursorManager (self )
264+ self ._column_drag_start = None
262265 self ._fold_timer = QTimer (self )
263266 self ._fold_timer .setSingleShot (True )
264267 self ._fold_timer .setInterval (100 )
@@ -564,6 +567,45 @@ def move_line_down(self):
564567 new_cursor .setPosition (nxt .position () + min (col , len (curr_text )))
565568 self .setTextCursor (new_cursor )
566569
570+ def paintEvent (self , event ):
571+ super ().paintEvent (event )
572+ if hasattr (self , 'multi_cursor_manager' ) and self .multi_cursor_manager .has_extra_cursors ():
573+ self .multi_cursor_manager .paint_extra_carets (self )
574+
575+ def mousePressEvent (self , event ):
576+ if event .button () == Qt .MouseButton .LeftButton :
577+ modifiers = event .modifiers ()
578+ if modifiers & Qt .KeyboardModifier .AltModifier :
579+ if modifiers & Qt .KeyboardModifier .ShiftModifier :
580+ # Spaltenauswahl via Alt+Shift+Mausklick / Drag starten
581+ self ._column_drag_start = self .cursorForPosition (event .position ().toPoint ())
582+ event .accept ()
583+ return
584+ else :
585+ # Weiteren Cursor an Klickposition setzen oder entfernen
586+ clicked_c = self .cursorForPosition (event .position ().toPoint ())
587+ self .multi_cursor_manager .toggle_cursor_at (clicked_c .position ())
588+ event .accept ()
589+ return
590+ elif hasattr (self , 'multi_cursor_manager' ) and self .multi_cursor_manager .has_extra_cursors ():
591+ self .multi_cursor_manager .clear ()
592+ super ().mousePressEvent (event )
593+
594+ def mouseMoveEvent (self , event ):
595+ if getattr (self , '_column_drag_start' , None ) is not None :
596+ end_cursor = self .cursorForPosition (event .position ().toPoint ())
597+ self .multi_cursor_manager .column_select_between_cursors (self ._column_drag_start , end_cursor )
598+ event .accept ()
599+ return
600+ super ().mouseMoveEvent (event )
601+
602+ def mouseReleaseEvent (self , event ):
603+ if getattr (self , '_column_drag_start' , None ) is not None :
604+ self ._column_drag_start = None
605+ event .accept ()
606+ return
607+ super ().mouseReleaseEvent (event )
608+
567609 def keyPressEvent (self , event ):
568610 # Completer aktiv?
569611 if self .completer and self .completer .popup ().isVisible ():
@@ -572,6 +614,34 @@ def keyPressEvent(self, event):
572614 event .ignore ()
573615 return
574616
617+ # Multi-Cursor Shortcuts
618+ modifiers = event .modifiers ()
619+ if (modifiers & Qt .KeyboardModifier .ControlModifier ) and (modifiers & Qt .KeyboardModifier .AltModifier ):
620+ if event .key () == Qt .Key .Key_Up :
621+ self .multi_cursor_manager .add_cursor_above ()
622+ return
623+ if event .key () == Qt .Key .Key_Down :
624+ self .multi_cursor_manager .add_cursor_below ()
625+ return
626+ if event .key () == Qt .Key .Key_L :
627+ self .multi_cursor_manager .add_next_occurrence ()
628+ return
629+
630+ if (modifiers & Qt .KeyboardModifier .ControlModifier ) and (modifiers & Qt .KeyboardModifier .ShiftModifier ):
631+ if event .key () == Qt .Key .Key_L :
632+ self .multi_cursor_manager .select_all_occurrences ()
633+ return
634+
635+ # Escape hebt Multi-Cursor auf
636+ if event .key () == Qt .Key .Key_Escape and self .multi_cursor_manager .has_extra_cursors ():
637+ self .multi_cursor_manager .clear ()
638+ return
639+
640+ # Multi-Cursor Tasten-Handling bei aktiven Sekundär-Cursorn
641+ if self .multi_cursor_manager .has_extra_cursors ():
642+ if self .multi_cursor_manager .handle_key_press (event ):
643+ return
644+
575645 # Tab & Shift+Tab / Backtab (Einrücken / Ausrücken)
576646 if event .key () == Qt .Key .Key_Backtab or (
577647 event .key () == Qt .Key .Key_Tab and bool (event .modifiers () & Qt .KeyboardModifier .ShiftModifier )
@@ -901,6 +971,8 @@ def highlightCurrentLine(self):
901971 extraSelections = (list (self .search_selections ) +
902972 list (self .bracket_selections ) +
903973 list (self .error_selections ))
974+ if hasattr (self , 'multi_cursor_manager' ):
975+ extraSelections .extend (self .multi_cursor_manager .get_extra_selections ())
904976 if not self .isReadOnly ():
905977 selection = QTextEdit .ExtraSelection ()
906978 selection .format .setBackground (QColor (45 , 45 , 45 ))
0 commit comments