def goto_line(self, line, column=0, move=True): """ Moves the text cursor to the specified position.. :param line: Number of the line to go to (0 based) :param column: Optional column number. Default is 0 (start of line). :param move: True to move the cursor. False will return the cursor without setting it on the editor. :return: The new text cursor :rtype: QtGui.QTextCursor """ text_cursor = self._move_cursor_to(line) if column: text_cursor.movePosition(text_cursor.Right, text_cursor.MoveAnchor, column) if move: block = text_cursor.block() # unfold parent fold trigger if the block is collapsed try: folding_panel = self._editor.panels.get('FoldingPanel') except KeyError: pass else: from pyqode.core.api.folding import FoldScope if not block.isVisible(): block = FoldScope.find_parent_scope(block) if TextBlockHelper.is_collapsed(block): folding_panel.toggle_fold_trigger(block) self._editor.setTextCursor(text_cursor) return text_cursor
def goto_line(self, line, column=0, move=True): """ Moves the text cursor to the specified position.. :param line: Number of the line to go to (0 based) :param column: Optional column number. Default is 0 (start of line). :param move: True to move the cursor. False will return the cursor without setting it on the editor. :return: The new text cursor :rtype: QtGui.QTextCursor """ text_cursor = self._editor.textCursor() text_cursor.movePosition(text_cursor.Start, text_cursor.MoveAnchor) text_cursor.movePosition(text_cursor.Down, text_cursor.MoveAnchor, line) if column: text_cursor.movePosition(text_cursor.Right, text_cursor.MoveAnchor, column) if move: block = text_cursor.block() # unfold parent fold trigger if the block is collapsed try: folding_panel = self._editor.panels.get('FoldingPanel') except KeyError: pass else: from pyqode.core.api.folding import FoldScope if not block.isVisible() or TextBlockHelper.is_fold_trigger( block): block = FoldScope.find_parent_scope(block) if TextBlockHelper.is_collapsed(block): folding_panel.toggle_fold_trigger(block) self._editor.setTextCursor(text_cursor) return text_cursor
def _highlight_caret_scope(self): """ Highlight the scope surrounding the current caret position. This get called only if :attr:` pyqode.core.panels.FoldingPanel.highlight_care_scope` is True. """ cursor = self.editor.textCursor() block_nbr = cursor.blockNumber() if self._block_nbr != block_nbr: block = FoldScope.find_parent_scope( self.editor.textCursor().block()) try: s = FoldScope(block) except ValueError: self._clear_scope_decos() else: self._mouse_over_line = block.blockNumber() if TextBlockHelper.is_fold_trigger(block): self._highlight_surrounding_scopes(block) self._block_nbr = block_nbr
def mouseMoveEvent(self, event): """ Detect mouser over indicator and highlight the current scope in the editor (up and down decoration arround the foldable text when the mouse is over an indicator). :param event: event """ super(FoldingPanel, self).mouseMoveEvent(event) th = TextHelper(self.editor) line = th.line_nbr_from_position(event.pos().y()) if line >= 0: block = FoldScope.find_parent_scope( self.editor.document().findBlockByNumber(line)) if TextBlockHelper.is_fold_trigger(block): if self._mouse_over_line is None: # mouse enter fold scope QtWidgets.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) if self._mouse_over_line != block.blockNumber() and \ self._mouse_over_line is not None: # fold scope changed, a previous block was highlighter so # we quickly update our highlighting self._mouse_over_line = block.blockNumber() self._highlight_surrounding_scopes(block) else: # same fold scope, request highlight self._mouse_over_line = block.blockNumber() self._highlight_runner.request_job( self._highlight_surrounding_scopes, block) self._highight_block = block else: # no fold scope to highlight, cancel any pending requests self._highlight_runner.cancel_requests() self._mouse_over_line = None QtWidgets.QApplication.restoreOverrideCursor() self.repaint()
def _on_action_toggle(self): """ Toggle the current fold trigger. """ block = FoldScope.find_parent_scope(self.editor.textCursor().block()) self.toggle_fold_trigger(block)