-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement softwrapping at user specified margin line #313
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ def __init__(self, parent): | |
buttonBox.accepted.connect(self.saveSettings) | ||
buttonBox.rejected.connect(self.close) | ||
self.initWidgets() | ||
self.configurators['rightMargin'].valueChanged.connect(self.handleRightMarginSet) | ||
self.layout.addWidget(buttonBox, len(self.options), 0, 1, 2) | ||
|
||
def initConfigOptions(self): | ||
|
@@ -83,6 +84,7 @@ def initConfigOptions(self): | |
(self.tr('Tab key inserts spaces'), 'tabInsertsSpaces'), | ||
(self.tr('Tabulation width'), 'tabWidth'), | ||
(self.tr('Draw vertical line at column'), 'rightMargin'), | ||
(self.tr('Enable soft wrap'), 'rightMarginWrap'), | ||
(self.tr('Show document stats'), 'documentStatsEnabled'), | ||
(self.tr('Interface'), None), | ||
(self.tr('Icon theme name'), 'iconTheme'), | ||
|
@@ -122,6 +124,8 @@ def initWidgets(self): | |
if isinstance(value, bool): | ||
self.configurators[name] = QCheckBox(self) | ||
self.configurators[name].setChecked(value) | ||
if name == 'rightMarginWrap' and getattr(globalSettings, 'rightMargin') == 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just use |
||
self.configurators[name].setEnabled(False) | ||
elif isinstance(value, int): | ||
self.configurators[name] = QSpinBox(self) | ||
if name == 'tabWidth': | ||
|
@@ -137,6 +141,14 @@ def initWidgets(self): | |
self.layout.addWidget(label, index, 0) | ||
self.layout.addWidget(self.configurators[name], index, 1, Qt.AlignRight) | ||
|
||
def handleRightMarginSet(self, value): | ||
if value > 0: | ||
self.configurators['rightMarginWrap'].setEnabled(True) | ||
self.configurators['rightMarginWrap'].setChecked(getattr(globalSettings, 'rightMarginWrap')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, just use |
||
else: | ||
self.configurators['rightMarginWrap'].setChecked(False) | ||
self.configurators['rightMarginWrap'].setEnabled(False) | ||
|
||
def saveSettings(self): | ||
for option in self.options: | ||
name = option[1] | ||
|
@@ -170,5 +182,6 @@ def applySettings(self): | |
print(e, file=sys.stderr) | ||
for tab in self.parent.iterateTabs(): | ||
tab.editBox.updateFont() | ||
tab.editBox.setWrapModeAndWidth() | ||
tab.editBox.viewport().update() | ||
self.parent.updateStyleSheet() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,12 +106,20 @@ def __init__(self, parent): | |
self.statistics = (0, 0, 0) | ||
self.statsArea = TextInfoArea(self) | ||
self.updateFont() | ||
self.setWrapModeAndWidth() | ||
self.document().blockCountChanged.connect(self.updateLineNumberAreaWidth) | ||
self.cursorPositionChanged.connect(self.highlightCurrentLine) | ||
self.document().contentsChange.connect(self.contentsChange) | ||
if globalSettings.useFakeVim: | ||
self.installFakeVimHandler() | ||
|
||
def setWrapModeAndWidth(self): | ||
if globalSettings.rightMarginWrap and (self.rect().topRight().x() > self.marginx): | ||
self.setLineWrapMode(2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not use magic numbers 1 or 2. Use |
||
self.setLineWrapColumnOrWidth(self.marginx) | ||
else: | ||
self.setLineWrapMode(1) | ||
|
||
def updateFont(self): | ||
self.setFont(globalSettings.editorFont) | ||
metrics = self.fontMetrics() | ||
|
@@ -250,6 +258,7 @@ def resizeEvent(self, event): | |
self.lineNumberAreaWidth(), rect.height()) | ||
self.infoArea.updateTextAndGeometry() | ||
self.statsArea.updateTextAndGeometry() | ||
self.setWrapModeAndWidth() | ||
|
||
def highlightCurrentLine(self): | ||
if globalSettings.relativeLineNumbers: | ||
|
@@ -495,4 +504,3 @@ def getText(self): | |
'count of words, alphanumeric characters, all characters') | ||
words, alphaNums, characters = self.editor.statistics | ||
return template % (words, alphaNums, characters) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix indentation :)