Advanced Text Editor
fontSizeSelect.addEventListener('change', function() {
var fontSize = fontSizeSelect.value;
document.execCommand('fontSize', false, fontSize);
});
textColorInput.addEventListener('change', function() {
var textColor = textColorInput.value;
document.execCommand('foreColor', false, textColor);
});
bgColorInput.addEventListener('change', function() {
var bgColor = bgColorInput.value;
document.execCommand('backColor', false, bgColor);
});
undoButton.addEventListener('click', function() {
document.execCommand('undo', false, null);
});
redoButton.addEventListener('click', function() {
document.execCommand('redo', false, null);
});
// Update word count
function updateWordCount() {
var content = editor.innerText;
var words = content.trim().split(/\s+/).length;
document.getElementById('wordCount').textContent = 'Word Count: ' + words;
}
// Update cursor position
function updateCursorPosition() {
var selection = window.getSelection();
var caretOffset = selection.focusOffset;
document.getElementById('cursorPosition').textContent = 'Cursor Position: ' + caretOffset;
}
// Add event listeners to update word count and cursor position
editor.addEventListener('input', function() {
updateWordCount();
});
editor.addEventListener('keyup', function() {
updateWordCount();
updateCursorPosition();
});
editor.addEventListener('mouseup', function() {
updateCursorPosition();
});
});
Comments
Post a Comment
have u any doubt pls coment me