Skip to content

Commit

Permalink
feat: Add character count feature to textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
masabinhok committed Oct 2, 2024
1 parent 10ad5c1 commit 53c826e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/components/ui/textarea/textarea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
let caretPosition = { top: 10, left: 8, height: 24 };
let lineNo = 1;
let column = 1;
let characterCount = 0; // New variable for character count
// Import the textarea-caret module
let getCaretCoordinates: any;
let updateScheduled = false; // Flag to track if update is already scheduled
Expand All @@ -33,6 +35,9 @@
// Calculate column (length of last line before caret)
column = textBeforeCaret.length - textBeforeCaret.lastIndexOf('\n');
// Update character count
characterCount = textarea.value.length; // Update character count
}
}
Expand Down Expand Up @@ -111,7 +116,9 @@
<div class="absolute bottom-0 z-10 h-[24px] w-full bg-primary-foreground px-1">
<Separator />
<p class="flex h-full w-full items-center justify-start text-sm">
Line: {lineNo}, Column: {column}
Line: {lineNo}, Column: {column},
{characterCount <= 1 ? 'Character: ' : 'Characters: '}
{characterCount}
</p>
</div>

Expand Down

0 comments on commit 53c826e

Please sign in to comment.