Skip to content

Commit

Permalink
Commited
Browse files Browse the repository at this point in the history
  • Loading branch information
Varshithvhegde committed Oct 25, 2023
1 parent c0c4d9a commit 917d2c1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
10 changes: 6 additions & 4 deletions src/app/home/home.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@
margin-top: 10px;
}

.made-div{
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;

}

.made-div {
text-align: center; /* Optional: To center the text within the div */
}


/* Add a media query if the width less 290 px */
@media screen and (max-width: 290px) {
Expand Down
7 changes: 5 additions & 2 deletions src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
spellcheck="false"
></textarea>
</mat-form-field>
<div class="made-div">
Made with <span class="heart" style="color: red;"></span> by <a href="https://github.com/Varshithvhegde">Varshith</a>
<div class="container">
<div class="made-div">
Made with <span class="heart" style="color: red;"></span> by <a href="https://github.com/Varshithvhegde">Varshith</a>
</div>
</div>

<div class="div-count">
Word Count: {{ words }} | Character Count: {{ characters }}
</div>
Expand Down
46 changes: 22 additions & 24 deletions src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class HomeComponent implements OnInit {
// Update word and character counts
this.updateWordAndCharacterCount();
}

});
} else {
console.error('Route ID is null or undefined');
Expand Down Expand Up @@ -137,36 +136,35 @@ export class HomeComponent implements OnInit {
}

// Tab key functionality
onTextareaKeydown(event: KeyboardEvent) {
// Check if the pressed key is Tab
if (event.key === 'Tab') {
// Prevent the default Tab behavior (e.g., moving focus to the next element)
event.preventDefault();
onTextareaKeydown(event: KeyboardEvent) {
// Check if the pressed key is Tab
if (event.key === 'Tab') {
// Prevent the default Tab behavior (e.g., moving focus to the next element)
event.preventDefault();

// Insert a tab character at the current cursor position
const textarea = event.target as HTMLTextAreaElement;
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
// Insert a tab character at the current cursor position
const textarea = event.target as HTMLTextAreaElement;
const start = textarea.selectionStart;
const end = textarea.selectionEnd;

// Get the text before and after the cursor position
const textBeforeCursor = textarea.value.substring(0, start);
const textAfterCursor = textarea.value.substring(end);
// Get the text before and after the cursor position
const textBeforeCursor = textarea.value.substring(0, start);
const textAfterCursor = textarea.value.substring(end);

// Combine the text with a tab character at the cursor position
const newText = textBeforeCursor + '\t' + textAfterCursor;
// Combine the text with a tab character at the cursor position
const newText = textBeforeCursor + '\t' + textAfterCursor;

// Update the textarea value
textarea.value = newText;
// Update the textarea value
textarea.value = newText;

// Update the cursor position
const newCursorPos = start + 1;
textarea.setSelectionRange(newCursorPos, newCursorPos);
// Update the cursor position
const newCursorPos = start + 1;
textarea.setSelectionRange(newCursorPos, newCursorPos);

// Update word and character counts
this.updateWordAndCharacterCount();
// Update word and character counts
this.updateWordAndCharacterCount();
}
}
}


updateWordAndCharacterCount() {
if (this.text) {
Expand Down

0 comments on commit 917d2c1

Please sign in to comment.