Skip to content

Commit c160002

Browse files
committed
Wrap lines that are longer than 106 characters
1 parent 3eafc8d commit c160002

File tree

10 files changed

+272
-77
lines changed

10 files changed

+272
-77
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ jobs:
8383
- name: Install ruff
8484
run: python -m pip install ruff
8585
- name: Run ruff check
86-
run: ruff check --select F,E,W,I,UP --ignore E501 .
86+
run: ruff check --select F,E,W,I,UP --line-length=106 .

ReText/converterprocess.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def recvall(sock, remaining):
3232
while remaining > 0:
3333
data = sock.recv(remaining)
3434
if len(data) == 0:
35-
raise EOFError('Received 0 bytes from socket while more bytes were expected. Did the sender process exit unexpectedly?')
35+
raise EOFError(
36+
'Received 0 bytes from socket while more bytes were expected.'
37+
' Did the sender process exit unexpectedly?'
38+
)
3639
alldata.extend(data)
3740
remaining -= len(data)
3841

ReText/dialogs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def __init__(self, parent, defaultText=None):
5858
self.checkBox = QCheckBox(self.tr('Set as default'), self)
5959
verticalLayout.addWidget(self.checkBox)
6060
buttonBox = QDialogButtonBox(self)
61-
buttonBox.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok)
61+
buttonBox.setStandardButtons(
62+
QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok
63+
)
6264
verticalLayout.addWidget(buttonBox)
6365
buttonBox.accepted.connect(self.accept)
6466
buttonBox.rejected.connect(self.reject)

ReText/editor.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ def contextMenuEvent(self, event):
260260
curchar = self.document().characterAt(cursor.position())
261261
isalpha = curchar.isalpha()
262262
word = None
263-
if isalpha and not (oldcursor.hasSelection() and oldcursor.selectedText() != cursor.selectedText()):
263+
if isalpha and not (
264+
oldcursor.hasSelection()
265+
and oldcursor.selectedText() != cursor.selectedText()
266+
):
264267
cursor.select(QTextCursor.SelectionType.WordUnderCursor)
265268
word = cursor.selectedText()
266269

@@ -276,7 +279,10 @@ def contextMenuEvent(self, event):
276279
for action in actions[::-1]:
277280
menu.insertAction(menu.actions()[0], action)
278281
menu.insertSeparator(menu.actions()[0])
279-
menu.insertAction(menu.actions()[0], self.parent.act(self.tr('Add to dictionary'), trig=self.learnWord(word)))
282+
menu.insertAction(
283+
menu.actions()[0],
284+
self.parent.act(self.tr('Add to dictionary'), trig=self.learnWord(word)),
285+
)
280286

281287
menu.addSeparator()
282288
menu.addAction(self.parent.actionMoveUp)
@@ -384,7 +390,11 @@ def handleReturn(self, cursor):
384390
if matchOL is not None:
385391
matchedPrefix = matchOL.group(1)
386392
matchedNumber = int(matchOL.group(2))
387-
nextNumber = matchedNumber if self.settings.orderedListMode == 'repeat' else matchedNumber + 1
393+
nextNumber = (
394+
matchedNumber
395+
if self.settings.orderedListMode == 'repeat'
396+
else matchedNumber + 1
397+
)
388398
matchedText = matchedPrefix + str(nextNumber) + ". "
389399
else:
390400
matchedText = ''
@@ -455,15 +465,21 @@ def highlightCurrentLine(self):
455465
if globalSettings.highlightCurrentLine == 'wrapped-line':
456466
selections.append(QTextEdit.ExtraSelection())
457467
selections[0].cursor.movePosition(QTextCursor.MoveOperation.StartOfBlock)
458-
selections[0].cursor.movePosition(QTextCursor.MoveOperation.EndOfBlock, QTextCursor.MoveMode.KeepAnchor)
468+
selections[0].cursor.movePosition(
469+
QTextCursor.MoveOperation.EndOfBlock,
470+
QTextCursor.MoveMode.KeepAnchor,
471+
)
459472
selections[1].format.setBackground(getColor('currentLineHighlight'))
460473
selections[1].format.setProperty(QTextFormat.Property.FullWidthSelection, True)
461474
selections[1].cursor = self.textCursor()
462475
selections[1].cursor.movePosition(QTextCursor.MoveOperation.EndOfBlock)
463476
elif selection.cursor.block().textDirection() == Qt.LayoutDirection.RightToLeft:
464477
# FullWidthSelection does not work correctly for RTL direction
465478
selection.cursor.movePosition(QTextCursor.MoveOperation.StartOfLine)
466-
selection.cursor.movePosition(QTextCursor.MoveOperation.EndOfLine, QTextCursor.MoveMode.KeepAnchor)
479+
selection.cursor.movePosition(
480+
QTextCursor.MoveOperation.EndOfLine,
481+
QTextCursor.MoveMode.KeepAnchor,
482+
)
467483
self.setExtraSelections(selections)
468484

469485
def enableTableMode(self, enable):

ReText/tab.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,16 @@ def find(self, text, flags, replaceText=None, wrap=False):
416416
if not newCursor.isNull():
417417
if replaceText is not None:
418418
newCursor.insertText(replaceText)
419-
newCursor.movePosition(QTextCursor.MoveOperation.Left, QTextCursor.MoveMode.MoveAnchor, len(replaceText))
420-
newCursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, len(replaceText))
419+
newCursor.movePosition(
420+
QTextCursor.MoveOperation.Left,
421+
QTextCursor.MoveMode.MoveAnchor,
422+
len(replaceText),
423+
)
424+
newCursor.movePosition(
425+
QTextCursor.MoveOperation.Right,
426+
QTextCursor.MoveMode.KeepAnchor,
427+
len(replaceText),
428+
)
421429
self.editBox.setTextCursor(newCursor)
422430
if self.editBox.cursorRect().bottom() >= self.editBox.height() - 3:
423431
scrollValue = self.editBox.verticalScrollBar().value()
@@ -439,8 +447,16 @@ def replaceAll(self, text, replaceText):
439447
lastCursor = cursor
440448
cursor = self.editBox.document().find(text, cursor, flags)
441449
if not lastCursor.isNull():
442-
lastCursor.movePosition(QTextCursor.MoveOperation.Left, QTextCursor.MoveMode.MoveAnchor, len(replaceText))
443-
lastCursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, len(replaceText))
450+
lastCursor.movePosition(
451+
QTextCursor.MoveOperation.Left,
452+
QTextCursor.MoveMode.MoveAnchor,
453+
len(replaceText),
454+
)
455+
lastCursor.movePosition(
456+
QTextCursor.MoveOperation.Right,
457+
QTextCursor.MoveMode.KeepAnchor,
458+
len(replaceText),
459+
)
444460
self.editBox.setTextCursor(lastCursor)
445461
self.editBox.textCursor().endEditBlock()
446462
return not lastCursor.isNull()
@@ -468,10 +484,13 @@ def promptFileCreation(self, fileToCreate):
468484
Prompt user if a file should be created for the clicked link,
469485
and try to create it. Return True on success.
470486
"""
471-
buttonReply = QMessageBox.question(self, self.tr('Create missing file?'),
472-
self.tr("The file '%s' does not exist.\n\nDo you want to create it?") % fileToCreate,
473-
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
474-
QMessageBox.StandardButton.No)
487+
buttonReply = QMessageBox.question(
488+
self,
489+
self.tr('Create missing file?'),
490+
self.tr("The file '%s' does not exist.\n\nDo you want to create it?") % fileToCreate,
491+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
492+
QMessageBox.StandardButton.No,
493+
)
475494
if buttonReply == QMessageBox.StandardButton.Yes:
476495
return self.createFile(fileToCreate)
477496
elif buttonReply == QMessageBox.StandardButton.No:

ReText/tablemode.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,33 @@ def _determineEditLists(rows, editedlineindex, offset, editsize, alignWithAnyEdg
180180
if editsize < 0:
181181
# How much an edge shifts to the left depends on how much room
182182
# there is in the cells on any row that shares this edge.
183-
leastLeftShift = min((-rowShift + _determineRoomInCell(row, currentedge, currentedgeindex, True)
184-
for row, rowShift in zip(rows, rowShifts)))
183+
leastLeftShift = min(
184+
-rowShift + _determineRoomInCell(row, currentedge, currentedgeindex, True)
185+
for row, rowShift in zip(rows, rowShifts)
186+
)
185187

186188
shift = max(editsize, -leastLeftShift)
187189
else:
188190
# When shifting right, determine how much only once based on how
189191
# much the edited cell needs to expand
190192
if firstEdge:
191-
room = _determineRoomInCell(rows[editedlineindex], currentedge, currentedgeindex, False, offset)
193+
room = _determineRoomInCell(
194+
rows[editedlineindex],
195+
currentedge,
196+
currentedgeindex,
197+
False,
198+
offset,
199+
)
192200
shift = max(0, editsize - room)
193201

194202
for i, row in enumerate(rows):
195-
editList, newRowShift = _performShift(row, rowShifts[i], currentedge, currentedgeindex, shift)
203+
editList, newRowShift = _performShift(
204+
row,
205+
rowShifts[i],
206+
currentedge,
207+
currentedgeindex,
208+
shift,
209+
)
196210
rowShifts[i] = newRowShift
197211
editLists[i].extend(editList)
198212

ReText/window.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ def __init__(self, parent=None):
237237
self.actionPdf = self.act('PDF', 'application-pdf', self.savePdf)
238238
self.actionOdf = self.act('ODT', 'x-office-document', self.saveOdf)
239239
self.getExportExtensionsList()
240-
self.actionQuit = self.act(self.tr('Quit'), 'application-exit', shct=QKeySequence.StandardKey.Quit)
240+
self.actionQuit = self.act(
241+
self.tr('Quit'),
242+
'application-exit',
243+
shct=QKeySequence.StandardKey.Quit,
244+
)
241245
self.actionQuit.setMenuRole(QAction.MenuRole.QuitRole)
242246
self.actionQuit.triggered.connect(self.close)
243247
self.actionUndo = self.act(self.tr('Undo'), 'edit-undo',
@@ -250,8 +254,12 @@ def __init__(self, parent=None):
250254
lambda: self.currentTab.editBox.cut(), shct=QKeySequence.StandardKey.Cut)
251255
self.actionPaste = self.act(self.tr('Paste'), 'edit-paste',
252256
lambda: self.currentTab.editBox.paste(), shct=QKeySequence.StandardKey.Paste)
253-
self.actionPasteImage = self.act(self.tr('Paste image'), 'edit-paste',
254-
lambda: self.currentTab.editBox.pasteImage(), shct=Qt.Modifier.CTRL | Qt.Modifier.SHIFT | Qt.Key.Key_V)
257+
self.actionPasteImage = self.act(
258+
self.tr('Paste image'),
259+
'edit-paste',
260+
lambda: self.currentTab.editBox.pasteImage(),
261+
shct=Qt.Modifier.CTRL | Qt.Modifier.SHIFT | Qt.Key.Key_V,
262+
)
255263
self.actionMoveUp = self.act(self.tr('Move line up'), 'go-up',
256264
lambda: self.currentTab.editBox.moveLineUp(), shct=Qt.Modifier.ALT | Qt.Key.Key_Up)
257265
self.actionMoveDown = self.act(self.tr('Move line down'), 'go-down',
@@ -615,7 +623,9 @@ def createTab(self, fileName):
615623
previewState = PreviewDisabled # Opening empty document in preview mode makes no sense
616624
self.currentTab = ReTextTab(self, fileName, previewState)
617625
self.currentTab.fileNameChanged.connect(lambda: self.tabFileNameChanged(self.currentTab))
618-
self.currentTab.modificationStateChanged.connect(lambda: self.tabModificationStateChanged(self.currentTab))
626+
self.currentTab.modificationStateChanged.connect(
627+
lambda: self.tabModificationStateChanged(self.currentTab)
628+
)
619629
self.currentTab.activeMarkupChanged.connect(lambda: self.tabActiveMarkupChanged(self.currentTab))
620630
self.tabWidget.addTab(self.currentTab, self.tr("New document"))
621631
self.currentTab.updateBoxesVisibility()
@@ -1096,7 +1106,12 @@ def savePdf(self):
10961106
if pageSize is None:
10971107
pageSize = QPageSize(QPageSize.PageSizeId.A4)
10981108
margins = QMarginsF(20, 20, 13, 20) # left, top, right, bottom (in millimeters)
1099-
layout = QPageLayout(pageSize, QPageLayout.Orientation.Portrait, margins, QPageLayout.Unit.Millimeter)
1109+
layout = QPageLayout(
1110+
pageSize,
1111+
QPageLayout.Orientation.Portrait,
1112+
margins,
1113+
QPageLayout.Unit.Millimeter,
1114+
)
11001115
preview.page().printToPdf(fileName, layout)
11011116
return
11021117
printer = self.standardPrinter(title)
@@ -1267,9 +1282,14 @@ def maybeSave(self, ind):
12671282
if not tab.editBox.document().isModified():
12681283
return True
12691284
self.tabWidget.setCurrentIndex(ind)
1270-
ret = QMessageBox.warning(self, '',
1285+
ret = QMessageBox.warning(
1286+
self,
1287+
'',
12711288
self.tr("The document has been modified.\nDo you want to save your changes?"),
1272-
QMessageBox.StandardButton.Save | QMessageBox.StandardButton.Discard | QMessageBox.StandardButton.Cancel)
1289+
QMessageBox.StandardButton.Save
1290+
| QMessageBox.StandardButton.Discard
1291+
| QMessageBox.StandardButton.Cancel,
1292+
)
12731293
if ret == QMessageBox.StandardButton.Save:
12741294
return self.saveFile(False)
12751295
elif ret == QMessageBox.StandardButton.Cancel:

tests/test_editor.py

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ def getText(self, key):
161161
return '\''
162162

163163
def getEvent(self, key):
164-
return QKeyEvent(QEvent.Type.KeyPress, key, Qt.KeyboardModifier.NoModifier, text=self.getText(key))
164+
return QKeyEvent(
165+
QEvent.Type.KeyPress,
166+
key,
167+
Qt.KeyboardModifier.NoModifier,
168+
text=self.getText(key),
169+
)
165170

166171
def test_isSurroundKey(self):
167172
# close keys should not start a surrounding
@@ -176,12 +181,30 @@ def test_isSurroundKey(self):
176181
self.assertTrue(self.editor.isSurroundKey(Qt.Key.Key_Apostrophe))
177182

178183
def test_getCloseKey(self):
179-
self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Underscore), Qt.Key.Key_Underscore), '_')
180-
self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Asterisk), Qt.Key.Key_Asterisk), '*')
181-
self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_QuoteDbl), Qt.Key.Key_QuoteDbl), '"')
182-
self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Apostrophe), Qt.Key.Key_Apostrophe), '\'')
183-
self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_ParenLeft), Qt.Key.Key_ParenLeft), ')')
184-
self.assertEqual(self.editor.getCloseKey(self.getEvent(Qt.Key.Key_BracketLeft), Qt.Key.Key_BracketLeft), ']')
184+
self.assertEqual(
185+
self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Underscore), Qt.Key.Key_Underscore),
186+
'_',
187+
)
188+
self.assertEqual(
189+
self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Asterisk), Qt.Key.Key_Asterisk),
190+
'*',
191+
)
192+
self.assertEqual(
193+
self.editor.getCloseKey(self.getEvent(Qt.Key.Key_QuoteDbl), Qt.Key.Key_QuoteDbl),
194+
'"',
195+
)
196+
self.assertEqual(
197+
self.editor.getCloseKey(self.getEvent(Qt.Key.Key_Apostrophe), Qt.Key.Key_Apostrophe),
198+
'\'',
199+
)
200+
self.assertEqual(
201+
self.editor.getCloseKey(self.getEvent(Qt.Key.Key_ParenLeft), Qt.Key.Key_ParenLeft),
202+
')',
203+
)
204+
self.assertEqual(
205+
self.editor.getCloseKey(self.getEvent(Qt.Key.Key_BracketLeft), Qt.Key.Key_BracketLeft),
206+
']',
207+
)
185208

186209
def changeCursor(self, posI, posF):
187210
self.cursor.setPosition(posI)
@@ -190,27 +213,51 @@ def changeCursor(self, posI, posF):
190213
def test_surroundText(self):
191214

192215
self.changeCursor(0, 3)
193-
self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_Underscore), Qt.Key.Key_Underscore)
216+
self.editor.surroundText(
217+
self.cursor,
218+
self.getEvent(Qt.Key.Key_Underscore),
219+
Qt.Key.Key_Underscore,
220+
)
194221
self.assertEqual(self.document.toPlainText(), '_foo_ bar baz qux corge grault')
195222

196223
self.changeCursor(6, 9)
197-
self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_Asterisk), Qt.Key.Key_Asterisk)
224+
self.editor.surroundText(
225+
self.cursor,
226+
self.getEvent(Qt.Key.Key_Asterisk),
227+
Qt.Key.Key_Asterisk,
228+
)
198229
self.assertEqual(self.document.toPlainText(), '_foo_ *bar* baz qux corge grault')
199230

200231
self.changeCursor(12, 15)
201-
self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_QuoteDbl), Qt.Key.Key_QuoteDbl)
232+
self.editor.surroundText(
233+
self.cursor,
234+
self.getEvent(Qt.Key.Key_QuoteDbl),
235+
Qt.Key.Key_QuoteDbl,
236+
)
202237
self.assertEqual(self.document.toPlainText(), '_foo_ *bar* "baz" qux corge grault')
203238

204239
self.changeCursor(18, 21)
205-
self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_Apostrophe), Qt.Key.Key_Apostrophe)
240+
self.editor.surroundText(
241+
self.cursor,
242+
self.getEvent(Qt.Key.Key_Apostrophe),
243+
Qt.Key.Key_Apostrophe,
244+
)
206245
self.assertEqual(self.document.toPlainText(), '_foo_ *bar* "baz" \'qux\' corge grault')
207246

208247
self.changeCursor(24, 29)
209-
self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_ParenLeft), Qt.Key.Key_ParenLeft)
248+
self.editor.surroundText(
249+
self.cursor,
250+
self.getEvent(Qt.Key.Key_ParenLeft),
251+
Qt.Key.Key_ParenLeft,
252+
)
210253
self.assertEqual(self.document.toPlainText(), '_foo_ *bar* "baz" \'qux\' (corge) grault')
211254

212255
self.changeCursor(32, 38)
213-
self.editor.surroundText(self.cursor, self.getEvent(Qt.Key.Key_BracketLeft), Qt.Key.Key_BracketLeft)
256+
self.editor.surroundText(
257+
self.cursor,
258+
self.getEvent(Qt.Key.Key_BracketLeft),
259+
Qt.Key.Key_BracketLeft,
260+
)
214261
self.assertEqual(self.document.toPlainText(), '_foo_ *bar* "baz" \'qux\' (corge) [grault]')
215262

216263
class TestOrderedListMode(unittest.TestCase):

0 commit comments

Comments
 (0)