Skip to content

Commit

Permalink
Fix #516: Option to fully highlight wrapped-lines (#523)
Browse files Browse the repository at this point in the history
This commit resolves the issue while still maintaining the current behaviour.

Changes:
· ReText/__init__.py
    Change default value of highlightCurrentLine to 'disabled'.
· ReText/config.py
    Add a combobox for the line highlighting setting with options:
        - "Disabled": no line highlighting;
        - "Cursor Line": line highlighting till EOL (current behaviour);
        - "Wrapped Line": line highlighting for whole wrapped line.
· ReText/editor.py
    Modify highlightCurrentLine() to achieve the intended behaviour.
  • Loading branch information
nihillum authored Aug 7, 2020
1 parent 9d955a8 commit 0e065a5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ReText/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def getBundledIcon(iconName):
'font': QFont(),
'handleWebLinks': False,
'hideToolBar': False,
'highlightCurrentLine': False,
'highlightCurrentLine': 'disabled',
'iconTheme': '',
'lastTabIndex': 0,
'lineNumbersEnabled': False,
Expand Down
7 changes: 7 additions & 0 deletions ReText/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ def getPageWidget(self, options):
self.configurators[name].addItem(self.tr('Normal preview'), 'normal-preview')
comboBoxIndex = self.configurators[name].findData(value)
self.configurators[name].setCurrentIndex(comboBoxIndex)
elif name == 'highlightCurrentLine':
self.configurators[name] = QComboBox(self)
self.configurators[name].addItem(self.tr('Disabled'), 'disabled')
self.configurators[name].addItem(self.tr('Cursor Line'), 'cursor-line')
self.configurators[name].addItem(self.tr('Wrapped Line'), 'wrapped-line')
comboBoxIndex = self.configurators[name].findData(value)
self.configurators[name].setCurrentIndex(comboBoxIndex)
elif isinstance(value, bool):
self.configurators[name] = QCheckBox(self)
self.configurators[name].setChecked(value)
Expand Down
15 changes: 12 additions & 3 deletions ReText/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,23 @@ def resizeEvent(self, event):
def highlightCurrentLine(self):
if globalSettings.relativeLineNumbers:
self.lineNumberArea.update()
if not globalSettings.highlightCurrentLine:
if globalSettings.highlightCurrentLine == 'disabled':
return self.setExtraSelections([])
selection = QTextEdit.ExtraSelection();
selection = QTextEdit.ExtraSelection()
selection.format.setBackground(colorValues['currentLineHighlight'])
selection.format.setProperty(QTextFormat.FullWidthSelection, True)
selection.cursor = self.textCursor()
selection.cursor.clearSelection()
self.setExtraSelections([selection])
selections = [selection]
if globalSettings.highlightCurrentLine == 'wrapped-line':
selections.append(QTextEdit.ExtraSelection())
selections[0].cursor.movePosition(QTextCursor.StartOfBlock)
selections[0].cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
selections[1].format.setBackground(colorValues['currentLineHighlight'])
selections[1].format.setProperty(QTextFormat.FullWidthSelection, True)
selections[1].cursor = self.textCursor()
selections[1].cursor.movePosition(QTextCursor.EndOfBlock)
self.setExtraSelections(selections)

def enableTableMode(self, enable):
self.tableModeEnabled = enable
Expand Down

0 comments on commit 0e065a5

Please sign in to comment.