Skip to content

Commit 5579e26

Browse files
fix(git): theme file-at-sha; quiet diff chrome
Diff markers already call out changes, so whitespace dots, EOL marks and indent guides only add noise. Skip those View toggles for diff editors and force them off in DiffView. File-at-revision tabs are plain read-only snapshots, not diffs. Stop registering them as diff views so EditorManager themes them, colour by path for syntax, and clear undo/save state so they never look modified. Show the diff toolbar when it was created under an already visible parent (Qt leaves such children hidden).
1 parent 3454a0a commit 5579e26

6 files changed

Lines changed: 33 additions & 24 deletions

File tree

‎src/EditorManager.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,24 @@ EditorManager::EditorManager(ApplicationSettings *settings, QObject *parent)
9393
connect(settings, &ApplicationSettings::showWhitespaceChanged, this, [=](bool b) {
9494
// TODO: could make SCWS_VISIBLEALWAYS configurable via settings. Probably not worth
9595
// taking up menu space e.g. show all, show leading, show trailing
96+
// Diff views never show whitespace dots, EOL marks or guides: the
97+
// diff already marks changes, and the dots make indented code noisy.
9698
for (auto &editor : getEditors()) {
99+
if (isDiffView(editor)) continue;
97100
editor->setViewWS(b ? SCWS_VISIBLEALWAYS : SCWS_INVISIBLE);
98101
}
99102
});
100103

101104
connect(settings, &ApplicationSettings::showEndOfLineChanged, this, [=](bool b) {
102105
for (auto &editor : getEditors()) {
106+
if (isDiffView(editor)) continue;
103107
editor->setViewEOL(b);
104108
}
105109
});
106110

107111
connect(settings, &ApplicationSettings::showIndentGuideChanged, this, [=](bool b) {
108112
for (auto &editor : getEditors()) {
113+
if (isDiffView(editor)) continue;
109114
editor->setIndentationGuides(b ? SC_IV_LOOKBOTH : SC_IV_NONE);
110115
}
111116
});

‎src/git/DiffView.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ void DiffView::configureEditor()
283283
send(SCI_SETSCROLLWIDTHTRACKING, 1);
284284
send(SCI_SETCARETLINEVISIBLE, 0);
285285
send(SCI_RESETELEMENTCOLOUR, SC_ELEMENT_CARET_LINE_BACK);
286+
// The editor-wide View toggles must not leak in (EditorManager skips diff
287+
// views when they change, so these stay off).
288+
send(SCI_SETVIEWWS, SCWS_INVISIBLE);
289+
send(SCI_SETVIEWEOL, 0);
290+
send(SCI_SETINDENTATIONGUIDES, SC_IV_NONE);
286291

287292
// One right-aligned text margin carries both number columns (margin text
288293
// is per line and shared by every text margin). Every margin mask is 0 so
@@ -1571,6 +1576,9 @@ void DiffView::layoutChrome()
15711576
const QRect content = e->contentsRect();
15721577
const QRect vp = e->viewport()->geometry();
15731578
m_toolbar->setGeometry(content.left(), content.top(), vp.right() + 1 - content.left(), toolbarHeight);
1579+
// Built after the editor may already be on screen: a child created under a
1580+
// visible parent stays hidden until shown, leaving only its reserved margin.
1581+
if (m_toolbar->isHidden()) m_toolbar->show();
15741582
m_toolbar->raise();
15751583
if (m_treeHost) {
15761584
m_treeHost->setVisible(tree);

‎src/git/DiffViewApp.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ ApplicationSettings *settings()
3030
return app ? app->getSettings() : nullptr;
3131
}
3232

33+
void applyLanguageForPath(ScintillaNext *editor, const QString &relPath)
34+
{
35+
auto *app = qobject_cast<NotepadNextApplication *>(QCoreApplication::instance());
36+
if (!app || !editor) return;
37+
app->setEditorLanguage(editor, app->detectLanguageFromPath(relPath));
38+
}
39+
3340
} // namespace DiffViewApp

‎src/git/DiffViewApp.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#define DIFF_VIEW_APP_H
2121

2222
class ApplicationSettings;
23+
class QString;
24+
class ScintillaNext;
2325

2426
// The diff view's link to the application, in its own translation unit so
2527
// tests and benches can link DiffView without NotepadNextApplication.
@@ -28,6 +30,10 @@ namespace DiffViewApp {
2830
// The application settings, or null outside the application.
2931
ApplicationSettings *settings();
3032

33+
// Colours `editor` for the language its file extension names (no-op outside
34+
// the application).
35+
void applyLanguageForPath(ScintillaNext *editor, const QString &relPath);
36+
3137
} // namespace DiffViewApp
3238

3339
#endif // DIFF_VIEW_APP_H

‎src/git/GitCommitView.cpp‎

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ QByteArray makeFileAtShaKey(const QByteArray &sha, const QString &relPath)
8080
return k;
8181
}
8282

83-
int bgr(const QColor &c)
84-
{
85-
return c.red() | (c.green() << 8) | (c.blue() << 16);
86-
}
87-
8883
void goToLine(ScintillaNext *editor, int line)
8984
{
9085
if (line <= 1) return;
@@ -138,21 +133,7 @@ void GitCommitView::setDarkPalette(bool dark)
138133
m_dark = dark;
139134
// Restyles the shown document in place; nothing is refetched.
140135
if (m_view) m_view->setDark(dark);
141-
styleFileAtShaEditor();
142-
}
143-
144-
void GitCommitView::styleFileAtShaEditor()
145-
{
146-
ScintillaNext *e = m_fileAtShaEditor.data();
147-
if (!e) return;
148-
// Registered as a diff view, so the editor theme skips it: paint the
149-
// plain text in the diff canvas colours.
150-
const DiffViewColors colors = DiffViewColors::make(m_dark);
151-
e->send(SCI_STYLESETFORE, STYLE_DEFAULT, bgr(colors.text));
152-
e->send(SCI_STYLESETBACK, STYLE_DEFAULT, bgr(colors.canvas));
153-
e->send(SCI_STYLECLEARALL);
154-
e->send(SCI_STYLESETFORE, STYLE_LINENUMBER, bgr(colors.muted));
155-
e->send(SCI_SETCARETFORE, bgr(colors.text));
136+
// The file-at-revision tab is a plain editor: EditorManager themes it.
156137
}
157138

158139
void GitCommitView::setWatcher(GitWatcher *watcher)
@@ -327,10 +308,9 @@ void GitCommitView::openFileAtSha(const QByteArray &sha, const QString &relPath,
327308
ScintillaNext *editor = m_fileAtShaEditor.data();
328309

329310
if (needNewEditor) {
311+
// A normal editor (themed, syntax-coloured), read-only below.
330312
editor = m_editorManager->createEditor(tabTitleForFileAtSha(sha, relPath));
331-
m_editorManager->registerAsDiffView(editor);
332313
m_fileAtShaEditor = editor;
333-
styleFileAtShaEditor();
334314
connect(editor, &QObject::destroyed, this, [this](QObject *) {
335315
m_currentFileAtShaKey.clear();
336316
});
@@ -342,12 +322,13 @@ void GitCommitView::openFileAtSha(const QByteArray &sha, const QString &relPath,
342322
m_currentFileAtShaKey = key;
343323

344324
m_fileFetcher->request(sha, relPath,
345-
[this, key](const QByteArray &bytes, bool truncated, const QString &err) {
325+
[this, key, relPath](const QByteArray &bytes, bool truncated, const QString &err) {
346326
if (key != m_currentFileAtShaKey) return; // stale
347327
ScintillaNext *e = m_fileAtShaEditor.data();
348328
if (!e) return;
349329
e->send(SCI_SETREADONLY, 0, 0);
350330
e->send(SCI_CLEARALL, 0, 0);
331+
if (err.isEmpty()) DiffViewApp::applyLanguageForPath(e, relPath);
351332
if (!err.isEmpty()) {
352333
const QByteArray msg = tr("Could not load file: %1").arg(err).toUtf8();
353334
e->send(SCI_APPENDTEXT, msg.size(),
@@ -362,6 +343,9 @@ void GitCommitView::openFileAtSha(const QByteArray &sha, const QString &relPath,
362343
reinterpret_cast<sptr_t>(foot.constData()));
363344
}
364345
}
346+
// Not a document the user edited: no undo history, never "modified".
347+
e->send(SCI_EMPTYUNDOBUFFER, 0, 0);
348+
e->send(SCI_SETSAVEPOINT, 0, 0);
365349
e->send(SCI_SETREADONLY, 1, 0);
366350
goToLine(e, m_fileAtShaLine);
367351
});

‎src/git/GitCommitView.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public slots:
9797
void load(const QByteArray &sha, bool keepPosition);
9898
void showDetail(quint64 serial, const std::shared_ptr<const GitCommitDetail> &detail, bool keepPosition);
9999
void onOpenFileRequested(const QString &relPath, int line, DiffView::Side side);
100-
void styleFileAtShaEditor();
101100

102101
// Show file content at a SHA in the shared file-at-sha tab, at `line` (1-based).
103102
void openFileAtSha(const QByteArray &sha, const QString &relPath, int line);

0 commit comments

Comments
 (0)