mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-29 00:20:04 +01:00
web: do not ignore line breaks when counting words (#1625)
Signed-off-by: Abdullah Atta <thecodrr@protonmail.com> Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
This commit is contained in:
@@ -276,3 +276,13 @@ test("creating a new note and toggling read-only mode should not empty editor co
|
||||
expect(await notes.editor.getContent("text")).not.toHaveLength(0);
|
||||
expect(await notes.editor.getContent("text")).toBe(NOTE.content);
|
||||
});
|
||||
|
||||
test("count number of words in an opened note", async ({ page }) => {
|
||||
const app = new AppModel(page);
|
||||
await app.goto();
|
||||
const notes = await app.goToNotes();
|
||||
NOTE.content = "1\n2\n3\na\nb\nc\nd\ne\nali\nwaqar"; //10
|
||||
await notes.createNote(NOTE);
|
||||
|
||||
expect((await notes.editor.getWordCount()) === 10).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -248,4 +248,12 @@ export class EditorModel {
|
||||
await this.previewRestoreButton.click();
|
||||
await this.previewNotice.waitFor({ state: "hidden" });
|
||||
}
|
||||
|
||||
async getWordCount() {
|
||||
return parseInt(
|
||||
(await this.wordCountText.allInnerTexts())
|
||||
.toString()
|
||||
.replace(" words", "")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ function save(
|
||||
configureEditor({
|
||||
statistics: {
|
||||
words: {
|
||||
total: countWords(content.textBetween(0, content.size)),
|
||||
total: countWords(content.textBetween(0, content.size, "\n", " ")),
|
||||
selected: 0
|
||||
}
|
||||
}
|
||||
@@ -210,7 +210,7 @@ function TipTap(props: TipTapProps) {
|
||||
words: {
|
||||
total:
|
||||
old.statistics?.words.total ||
|
||||
countWords(content.textBetween(0, content.size)),
|
||||
countWords(content.textBetween(0, content.size, "\n", " ")),
|
||||
selected: getSelectedWords(
|
||||
editor as Editor,
|
||||
transaction.selection
|
||||
@@ -424,5 +424,6 @@ function countWords(str: string) {
|
||||
}
|
||||
|
||||
if (shouldCount) ++count;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user