[PATCH 1 of 2] fileview: set a font after clearing the lexer too (fixes #6003)

4 views
Skip to first unread message

Matt Harbison

unread,
Jan 15, 2025, 11:45:35 AMJan 15
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1736886461 18000
# Tue Jan 14 15:27:41 2025 -0500
# Branch stable
# Node ID 2b06d75337948f524590ec3b43ea3acdea553612
# Parent dd839fdd09fa13f0745a8954c44b4e08241e7ed8
# EXP-Topic issue-6003
fileview: set a font after clearing the lexer too (fixes #6003)

This is further work on 95ab09489701. I still have no idea what's going on here,
but a simple reproduction of the problem that this fixes is:

1) launch thg with the Revision Details widget, and type "macos" in the file
filter area
2) Press the button to show all revision controlled files in the tree and
expand out `contrib/packaging/macos`
3) Select "print_platform_files.py" (file content displays correctly)
4) Select "requirements-py3.txt" (file contents has an unexpected font)
5) Select "requirements-pyqt6.txt" (file contents has correct monspaced font)

After that, selecting another *.py file shows the correct contents. Selecting a
text file will show with a bad font, the second text file will show with the
correct monospace font, etc.

My thinking is that somehow, changing to a None lexer is mangling the font on
the QSci component. Selecting the second text file will call `display()` again,
which sets the font on it again. It sets the lexer to None again of course, but
it's already None, so does nothing/skips a block of code/whatever.

Note that prior to 95ab09489701, this set the font after setting the lexer to
None. But we still have to set the font before setting a real lexer to fix the
original problem, so now we handle both.

diff --git a/tortoisehg/hgqt/fileview.py b/tortoisehg/hgqt/fileview.py
--- a/tortoisehg/hgqt/fileview.py
+++ b/tortoisehg/hgqt/fileview.py
@@ -841,8 +841,12 @@
if fd.contents:
filename = fd.filePath()
lexer = lexers.getlexer(self._ui, filename, fd.contents, self)
- self._sci.setFont(qtlib.getfont('fontlog').font())
+ newFont = qtlib.getfont('fontlog').font()
+
+ self._sci.setFont(newFont)
self._sci.setLexer(lexer)
+ self._sci.setFont(newFont)
+
self._sci.setText(fd.fileText())

self._sci.setMarginsFont(self._sci.font())

Matt Harbison

unread,
Jan 15, 2025, 11:45:40 AMJan 15
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1736890686 18000
# Tue Jan 14 16:38:06 2025 -0500
# Branch stable
# Node ID 92fd6dc326551c4757df18c699324bf2d1011f82
# Parent 2b06d75337948f524590ec3b43ea3acdea553612
# EXP-Topic issue-6003
qt5: apply the recent lexer fix to all other users

With the lexer font issue seemingly fixed with a known reproducible problem in
the previous commit, apply that same change (set font before setting a lexer,
but after clearing a lexer) to all of the other places with a similar pattern.
This is basically a backout of 95ab09489701, and reapplying it more carefully.
There were a few other changes in that commit that are unaffected, because they
were near an unconditional setting of a lexer.

diff --git a/tortoisehg/hgqt/filedialogs.py b/tortoisehg/hgqt/filedialogs.py
--- a/tortoisehg/hgqt/filedialogs.py
+++ b/tortoisehg/hgqt/filedialogs.py
@@ -523,8 +523,10 @@
sci.setMarginLineNumbers(1, True)
sci.SendScintilla(sci.SCI_SETSELEOLFILLED, True)

- sci.setFont(qtlib.getfont('fontdiff').font())
+ font = qtlib.getfont('fontdiff').font()
+ sci.setFont(font)
sci.setLexer(lexer)
+ sci.setFont(font)

sci.setReadOnly(True)
sci.setUtf8(True)
diff --git a/tortoisehg/hgqt/messageentry.py b/tortoisehg/hgqt/messageentry.py
--- a/tortoisehg/hgqt/messageentry.py
+++ b/tortoisehg/hgqt/messageentry.py
@@ -76,13 +76,14 @@
def applylexer(self):
font = qtlib.getfont('fontcomment').font()
self.fontHeight = QFontMetrics(font).height()
- self.setFont(font)
if qtlib.readBool(QSettings(), 'msgentry/lexer', True):
+ self.setFont(font)
self.setLexer(QsciLexerMakefile(self))
self.lexer().setColor(QColor(Qt.GlobalColor.red), QsciLexerMakefile.Error)
self.lexer().setFont(font)
else:
self.setLexer(None)
+ self.setFont(font)

@pyqtSlot(QPoint)
def menuRequested(self, point):
diff --git a/tortoisehg/hgqt/rejects.py b/tortoisehg/hgqt/rejects.py
--- a/tortoisehg/hgqt/rejects.py
+++ b/tortoisehg/hgqt/rejects.py
@@ -126,8 +126,12 @@
return
earlybytes = hglib.fromunicode(editor.text(), 'replace')[:4096]
lexer = lexers.getlexer(ui, hglib.tounicode(path), earlybytes, self)
- editor.setFont(qtlib.getfont('fontlog').font())
+
+ font = qtlib.getfont('fontlog').font()
+ editor.setFont(font)
editor.setLexer(lexer)
+ editor.setFont(font)
+
editor.setMarginLineNumbers(1, True)
editor.setMarginWidth(1, str(editor.lines())+'X')


Yuya Nishihara

unread,
Jan 16, 2025, 8:14:59 AMJan 16
to Matt Harbison, thg...@googlegroups.com
On Wed, 15 Jan 2025 11:45:22 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_h...@yahoo.com>
> # Date 1736886461 18000
> # Tue Jan 14 15:27:41 2025 -0500
> # Branch stable
> # Node ID 2b06d75337948f524590ec3b43ea3acdea553612
> # Parent dd839fdd09fa13f0745a8954c44b4e08241e7ed8
> # EXP-Topic issue-6003
> fileview: set a font after clearing the lexer too (fixes #6003)

Queued, thanks.
Reply all
Reply to author
Forward
0 new messages