Enable line wrapping

Merge pull request #709 from jensenr30/line-wrapping
This commit is contained in:
Murmele 2024-03-16 08:05:07 +01:00 committed by GitHub
commit dac06473c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 35 additions and 0 deletions

View File

@ -6,6 +6,7 @@ Description
* UI(Commit List): Added a right-click menu entry to rename branches.
* UI(Main Menu): Added a menu-entry to rename the current branch.
* UI(Diff View): Added line wrapping option in Tools - Options - Diff
#### Changed

View File

@ -79,6 +79,11 @@ See blame of the current version with an integrated timeline to see who changed
![Blame View](https://raw.githubusercontent.com/Murmele/Gittyup/master/rsrc/screenshots/BlameView.png)
### Dynamic Line Wrapping
Courtesy of Scintilla.
![Line Wrapping](/rsrc/screenshots/line-wrap-demo-2.gif)
### Single line staging
by eighter clicking on the checkboxes next to each line or by selecting the relevant code and pressing "S". For unstaging you can uncheck the checkboxes or press "U". To revert changes, select the text and press "R".

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

View File

@ -25,6 +25,7 @@
namespace {
const QString kWrapLines("diff/lines/wrap");
const QString kIgnoreWsKey("diff/whitespace/ignore");
const QString kLastPathKey("lastpath");
const QString kTranslation("translation");
@ -191,6 +192,14 @@ QString Settings::hotkey(const QString &action) const {
return value("hotkeys/" + action, "").toString();
}
bool Settings::isTextEditorWrapLines() const {
return value(kWrapLines).toBool();
}
void Settings::setTextEditorWrapLines(bool wrap) {
setValue(kWrapLines, wrap, true);
}
bool Settings::isWhitespaceIgnored() const {
return value(kIgnoreWsKey).toBool();
}

View File

@ -36,6 +36,10 @@ public:
void setHotkey(const QString &action, const QString &hotkey);
QString hotkey(const QString &action) const;
// wrap lines in TextEditor in DiffView
bool isTextEditorWrapLines() const;
void setTextEditorWrapLines(bool wrapLines);
// ignore whitespace
bool isWhitespaceIgnored() const;
void setWhitespaceIgnored(bool ignored);

View File

@ -69,8 +69,16 @@ DiffPanel::DiffPanel(const git::Repository &repo, QWidget *parent)
}
});
// Wrap lines
QCheckBox *wrapLines = new QCheckBox(tr("Wrap lines"), this);
wrapLines->setChecked(Settings::instance()->isTextEditorWrapLines());
connect(wrapLines, &QCheckBox::toggled, [](bool wrap) {
Settings::instance()->setTextEditorWrapLines(wrap);
});
QFormLayout *layout = new QFormLayout(this);
layout->addRow(tr("Context lines:"), contextLayout);
layout->addRow(tr("Wrap lines:"), wrapLines);
layout->addRow(tr("Character Encoding:"), encoding);
// Remaining settings are strictly global.

View File

@ -76,6 +76,8 @@ TextEditor::TextEditor(QWidget *parent) : ScintillaIFace(parent) {
setScrollWidthTracking(true);
setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
setWrapMode(SC_WRAP_NONE);
setMarginLeft(4);
setMarginTypeN(Staged, SC_MARGIN_SYMBOL);
setMarginTypeN(LineNumber, SC_MARGIN_NUMBER);
@ -181,6 +183,12 @@ void TextEditor::applySettings() {
setIndent(settings->value(Setting::Id::IndentWidth).toInt());
setTabWidth(settings->value(Setting::Id::TabWidth).toInt());
if (Settings::instance()->isTextEditorWrapLines()) {
setWrapMode(SC_WRAP_WORD);
} else {
setWrapMode(SC_WRAP_NONE);
}
// Initialize markers.
QColor background = palette().color(QPalette::Base);
int fontHeight;