W
W
w0lkolak2021-11-11 13:19:45
Qt
w0lkolak, 2021-11-11 13:19:45

How to completely cancel text highlighting before it starts?

There is a syntax selection menu. The user takes a file.ru from the explorer
and applies it, hoping that it is a file with syntax. It may be a different file.
Then you need to return the old syntax.
Now it looks like this:

try:
       self. Highlighter = myHighlighter(doc, new_syntax)
except:
       self. Highlighter = myHighlighter(doc, old_syntax)


class myHighlighter(QSyntaxHighlighter):
    def __init__(self, doc, syntax):
       QSyntaxHighlighter.__init__(self, doc)
       self.rules_from_syntax(syntax)


The problem is that the application of old_syntax does not cancel the application of new_syntax, and after switching to except and finishing all manipulations, highlihtBlock still starts with the new_syntax syntax. And it is empty, for example. collapse.
How to cancel highlight new_syntax in case of an error and immediately deal with old_syntax?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question