Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The enter should not be counted as a character #2574

Closed
jodator opened this issue Jun 28, 2019 · 4 comments · Fixed by ckeditor/ckeditor5-word-count#10
Closed

The enter should not be counted as a character #2574

jodator opened this issue Jun 28, 2019 · 4 comments · Fixed by ckeditor/ckeditor5-word-count#10
Assignees
Labels
package:word-count type:bug This issue reports a buggy (incorrect) behavior.
Milestone

Comments

@jodator
Copy link
Contributor

jodator commented Jun 28, 2019

Right now the newline is used to denote blocks and inline elements.

As @msamsel noticed it shouldn't count as a character:

Peek 2019-06-28 15-51

@msamsel
Copy link
Contributor

msamsel commented Jun 28, 2019

I think we should define some rules how words and characters are calculated. It should be also considered how word-count integrates with other plugins, like placeholder, tables, images, media embed etc.
Right now there is pretty basic solution, which might be improved in several ways.

@Reinmar
Copy link
Member

Reinmar commented Jun 30, 2019

Related issues:

  • Media embed is treated as a character.
  • An empty table 3x3 is treated ad 9 characters.

@Reinmar
Copy link
Member

Reinmar commented Jul 1, 2019

I think we should define some rules how words and characters are calculated

I think it's best to check how it works in other editors (Word, GDocs). And see if there's some standard.

@jodator jodator changed the title The enter should not be counted as an character The enter should not be counted as a character Jul 16, 2019
jodator referenced this issue in ckeditor/ckeditor5-word-count Jul 29, 2019
Fix: Improve words recognition, remove enter from counted characters. Closes #4. Closes #5.
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-word-count Oct 9, 2019
@mlewand mlewand added this to the iteration 26 milestone Oct 9, 2019
@mlewand mlewand added status:confirmed type:bug This issue reports a buggy (incorrect) behavior. package:word-count labels Oct 9, 2019
@Prince890840
Copy link

My Question is when i integrate ckeditor into our Project then there is a task about to show character count whatever'd content paste into ckeditor then i saw a difference between the Microsoft word and Ckeditor which has too much difference.

Here I posted the difference of both, can anyone give solution how can i overcome this problem ?

  1. image
  2. image
  3. image

In above I pasted same content in ckeditor, Google Docs and Microsoft word , every editor has different result.

below is my code for the reference.

`const ReviewerNotes = ({
notes,
errorMessage,
plainText,
}) => {
const onNotesChange = useCallback((updatedEditorState) => {
setReviewInfo({
reviewNotes: updatedEditorState,
errorMessage: '',
plainText: convertHTMLToPlainText(updatedEditorState),
});
}, []);
const characterLength = plainText.length;
const scrollAndFocusEditor = (editor) => {
const element = document.body;
editor.focus();

if (element) {
  window.scroll({
    top: element.scrollHeight,
    behavior: 'smooth',
  });
}

};

return (
<>



Reviewer notes  
(Minimum 100 characters)


<TextEditor
editorState={notes}
error={!!errorMessage}
characterCount={{
isShown: true,
character: characterLength,
}}
stripPastedStyles
onEditorStateChange={onNotesChange}
onReady={scrollAndFocusEditor}
/>
{errorMessage}


</>
);
};

import { forwardRef, useMemo } from 'react';
import PropTypes from 'prop-types';
import { CKEditor } from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import plainTextToHtml from '@ckeditor/ckeditor5-clipboard/src/utils/plaintexttohtml';

import './editor.scss';

const editorConfig = {
language: 'en', // fa - for persian language ( rtl )
toolbar: {
items: [
'undo',
'redo',
'heading',
'|',
'bold',
'italic',
'link',
'bulletedList',
'numberedList',
'|',
'outdent',
'indent',
],
},
};

const TextEditor = forwardRef((
{
editorState,
onEditorStateChange,
error,
characterCount,
onReady,
placeholder,
stripPastedStyles,
...rest
},
ref,
) => {
const { isShown, character } = characterCount ?? {};

const handleEditorContentChange = (_event, editor) => {
const editorContent = editor.getData();
const editingView = editor.editing.view;

editingView.document.on('enter', (evt, data) => {
  editor.execute(data.isSoft ? 'enter' : 'shiftEnter');

  data.preventDefault();
  evt.stop();
  editor.editing.view.scrollToTheSelection();
}, { priority: 'high' });

onEditorStateChange(editorContent);

};

const appliedConfiguration = useMemo(() => ({
...editorConfig,
...(placeholder && { placeholder }),
}), [placeholder]);

const handleEditor = (editor) => {
if (stripPastedStyles) {
editor.plugins.get('ClipboardPipeline').on('inputTransformation', (_evt, data) => {
const dataTransfer = data.dataTransfer;

    const content = plainTextToHtml(dataTransfer.getData('text/plain'));

    data.content = editor.data.processor.toView(content);
  }, { priority: 'high' });
}

onReady(editor);

};

return (
<div className={text-editor-wrapper ${error ? 'ckEditor-error' : ''}}>
<CKEditor
config={appliedConfiguration}
data={editorState}
editor={ClassicEditor}
ref={ref}
onChange={handleEditorContentChange}
onReady={handleEditor}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
/>
{isShown ? (


{character}


) : null}

);
});`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:word-count type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants