Skip to content
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

Enable line wrapping #709

Merged
merged 6 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".

Expand Down
Binary file added rsrc/screenshots/line-wrap-demo-2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/conf/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Murmele marked this conversation as resolved.
Show resolved Hide resolved
}

bool Settings::isWhitespaceIgnored() const {
return value(kIgnoreWsKey).toBool();
}
Expand Down
4 changes: 4 additions & 0 deletions src/conf/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class Settings : public QObject {
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);
Expand Down
8 changes: 8 additions & 0 deletions src/dialogs/DiffPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/editor/TextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Loading