diff --git a/docs/changelog.md b/docs/changelog.md index 567609a7..9f08072c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/docs/index.md b/docs/index.md index 43753a63..b68c0215 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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". diff --git a/rsrc/screenshots/line-wrap-demo-2.gif b/rsrc/screenshots/line-wrap-demo-2.gif new file mode 100644 index 00000000..5aacd21a Binary files /dev/null and b/rsrc/screenshots/line-wrap-demo-2.gif differ diff --git a/src/conf/Settings.cpp b/src/conf/Settings.cpp index 184703c3..f3a6ff44 100644 --- a/src/conf/Settings.cpp +++ b/src/conf/Settings.cpp @@ -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(); } diff --git a/src/conf/Settings.h b/src/conf/Settings.h index 5ba059f9..41b1be1b 100644 --- a/src/conf/Settings.h +++ b/src/conf/Settings.h @@ -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); diff --git a/src/dialogs/DiffPanel.cpp b/src/dialogs/DiffPanel.cpp index ddf55827..40ad124c 100644 --- a/src/dialogs/DiffPanel.cpp +++ b/src/dialogs/DiffPanel.cpp @@ -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. diff --git a/src/editor/TextEditor.cpp b/src/editor/TextEditor.cpp index 1a4b8773..28f348dc 100644 --- a/src/editor/TextEditor.cpp +++ b/src/editor/TextEditor.cpp @@ -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;