Skip to content

Commit

Permalink
Feat: Added word counter
Browse files Browse the repository at this point in the history
  • Loading branch information
4rnv committed Nov 27, 2024
1 parent 8d7bf33 commit 540ff1c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/app.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"version": "1.0.0-3"
}
{}
5 changes: 4 additions & 1 deletion src/lib/components/Editor/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
let caretLineNo = 1;
let caretColumnNo = 1;
let characterCount = 0;
let wordCount = 0;
async function setupQuill() {
quill = new Quill(editorContainer!, {
Expand Down Expand Up @@ -64,6 +65,7 @@
caretLineNo = lines.length;
caretColumnNo = lines[lines.length - 1].length + 1;
characterCount = quill.getLength() - 1; // quill.getLength() includes a trailing newline character
wordCount = quill.getText().trim().split(/\s+/).filter(word => word).length; // \s+ is RegEx for whitespace characters.
}
}
Expand Down Expand Up @@ -104,6 +106,7 @@
caretLineNo ||
caretColumnNo ||
characterCount ||
wordCount ||
$settings
) {
updateCaretPosition();
Expand Down Expand Up @@ -163,7 +166,7 @@
/>
</div>

<StatusBar {caretLineNo} {caretColumnNo} {characterCount} />
<StatusBar {caretLineNo} {caretColumnNo} {characterCount} {wordCount} />

<!-- {#if updateScheduled}
<style>
Expand Down
10 changes: 10 additions & 0 deletions src/lib/components/StatusBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export let caretLineNo = 1;
export let caretColumnNo = 1;
export let characterCount = 0;
export let wordCount = 0;
const inAnimation = {
duration: 80
Expand Down Expand Up @@ -49,6 +50,15 @@
{characterCount <= 1 ? 'Character' : 'Characters'}
</span>

<span class="flex items-center justify-center">
{#key wordCount}
<span in:slide={inAnimation} class="mr-1 inline-block">
{wordCount}
</span>
{/key}
{wordCount <= 1 ? 'Word' : 'Words'}
</span>

<span class="ml-auto">
{$settings.zoom * 100}%
</span>
Expand Down

0 comments on commit 540ff1c

Please sign in to comment.