def highlightBlock(self, text): """Called by Qt when the highlighting of the current line needs updating.""" # find the state of the previous line prev = self.previousBlockState() state = self._fridge.thaw(prev) blank = not state and (not text or text.isspace()) if not state: state = self.initialState() # collect and save the tokens tokens = tuple(state.tokens(text)) cursortools.data(self.currentBlock()).tokens = tokens # if blank thus far, keep the highlighter coming back # because the parsing state is not yet known; else save the state self.setCurrentBlockState(prev - 1 if blank else self._fridge.freeze(state)) # apply highlighting if desired if self._highlighting: setFormat = lambda f: self.setFormat(token.pos, len(token), f) mapping = highlight_mapping() for token in tokens: f = mapping[token] if f: setFormat(f)
def mark(self, block, state=None): if state is None: try: return block.userData().folded except AttributeError: return False elif state: cursortools.data(block).folded = state else: try: del block.userData().folded except AttributeError: pass
def slotItemExpanded(self, item): """Called when the user expands an item.""" block = self.cursorForItem(item).block() cursortools.data(block).collapsed = False
def slotItemCollapsed(self, item): """Called when the user collapses an item.""" block = self.cursorForItem(item).block() cursortools.data(block).collapsed = True