Skip to content

Commit 31673b7

Browse files
committed
Word count bug fix + changelog updates.
1 parent fe28881 commit 31673b7

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [2.1.0] - 2021-11-20
9+
10+
#### Added
911

1012
* Untitled documents are now autosaved to a draft folder when autosave is enabled.
1113
* Added preferences button to open the draft folder location where untitled documents are autosaved.
12-
* Added check box option to load last opened file on startup. If left unchecked, a new file will be opened on startup.
14+
* Added check box option to load last opened file on startup. If left unchecked, a new file will be opened on startup
15+
* Added ability to word count indicator in status bar to display a different statistic. (The indicator is now a combo box.)
1316
* Updated Brazilian Portuguese translation.
1417

1518
## [2.0.2] - 2021-06-27

src/documentmanager.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***********************************************************************
1+
/***********************************************************************
22
*
33
* Copyright (C) 2014-2021 wereturtle
44
*
@@ -549,10 +549,9 @@ bool DocumentManager::close()
549549
cursor.setPosition(0);
550550
d->editor->setTextCursor(cursor);
551551

552-
d->document->blockSignals(true);
553-
d->document->setPlainText("");
554-
d->document->blockSignals(false);
552+
d->document->clear();
555553
d->document->clearUndoRedoStacks();
554+
556555
d->editor->setReadOnly(false);
557556
d->document->setReadOnly(false);
558557
d->setFilePath(QString());
@@ -729,9 +728,7 @@ bool DocumentManagerPrivate::loadFile(const QString &filePath)
729728

730729
document->clearUndoRedoStacks();
731730
document->setUndoRedoEnabled(false);
732-
document->blockSignals(true);
733-
document->setPlainText("");
734-
document->blockSignals(false);
731+
document->clear();
735732

736733
QApplication::setOverrideCursor(Qt::WaitCursor);
737734
emit q->operationStarted(QObject::tr("opening %1").arg(filePath));

src/documentstatistics.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/***********************************************************************
22
*
3-
* Copyright (C) 2016-2020 wereturtle
3+
* Copyright (C) 2016-2021 wereturtle
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -87,14 +87,28 @@ DocumentStatistics::DocumentStatistics(MarkdownDocument *document, QObject *pare
8787

8888
d->document = document;
8989
d->wordCount = 0;
90+
d->totalWordCount = 0;
9091
d->wordCharacterCount = 0;
9192
d->sentenceCount = 0;
9293
d->paragraphCount = 0;
9394
d->pageCount = 0;
9495
d->lixLongWordCount = 0;
96+
d->readTimeMinutes = 0;
9597

9698
connect(d->document, SIGNAL(contentsChange(int, int, int)), this, SLOT(onTextChanged(int, int, int)));
9799
connect(d->document, SIGNAL(textBlockRemoved(const QTextBlock &)), this, SLOT(onTextBlockRemoved(const QTextBlock &)));
100+
connect(d->document,
101+
&MarkdownDocument::cleared,
102+
[d]() {
103+
d->wordCount = 0;
104+
d->wordCharacterCount = 0;
105+
d->sentenceCount = 0;
106+
d->paragraphCount = 0;
107+
d->pageCount = 0;
108+
d->lixLongWordCount = 0;
109+
d->readTimeMinutes = 0;
110+
d->updateStatistics();
111+
});
98112
}
99113

100114
DocumentStatistics::~DocumentStatistics()

src/markdowndocument.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***********************************************************************
1+
/***********************************************************************
22
*
33
* Copyright (C) 2014-2021 wereturtle
44
*
@@ -167,6 +167,12 @@ void MarkdownDocument::notifyTextBlockRemoved(const QTextBlock &block)
167167
emit textBlockRemoved(block);
168168
}
169169

170+
void MarkdownDocument::clear()
171+
{
172+
QTextDocument::clear();
173+
emit cleared();
174+
}
175+
170176
void MarkdownDocumentPrivate::initializeUntitledDocument()
171177
{
172178
Q_Q(MarkdownDocument);

src/markdowndocument.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***********************************************************************
1+
/***********************************************************************
22
*
33
* Copyright (C) 2014-2021 wereturtle
44
*
@@ -109,6 +109,11 @@ class MarkdownDocument : public QTextDocument
109109
*/
110110
void notifyTextBlockRemoved(const QTextBlock &block);
111111

112+
/**
113+
* Overrides base class clear() method to send cleared() signal.
114+
*/
115+
void clear();
116+
112117
signals:
113118
/**
114119
* Emitted when the file path changes.
@@ -127,6 +132,11 @@ class MarkdownDocument : public QTextDocument
127132
*/
128133
void textBlockRemoved(const QTextBlock &block);
129134

135+
/**
136+
* Emitted when the contents of the document is cleared.
137+
*/
138+
void cleared();
139+
130140
private:
131141
QScopedPointer<MarkdownDocumentPrivate> d_ptr;
132142
};

0 commit comments

Comments
 (0)