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

TextTransformation creates 30+ instances of TextWatcher #6020

Closed
Reinmar opened this issue Dec 20, 2019 · 3 comments · Fixed by ckeditor/ckeditor5-typing#223
Closed

TextTransformation creates 30+ instances of TextWatcher #6020

Reinmar opened this issue Dec 20, 2019 · 3 comments · Fixed by ckeditor/ckeditor5-typing#223
Assignees
Labels
type:bug This issue reports a buggy (incorrect) behavior.

Comments

@Reinmar
Copy link
Member

Reinmar commented Dec 20, 2019

TextTransformation creates a new TextWatcher instance for every configured transformation. This is completely non-optimal. We should have one TextWatcher and check all transformations in it. And then react to matchetd:data and check whcih transformation we matched.


If you'd like to see this fixed sooner, add a 👍 reaction to this post.

@Reinmar Reinmar added type:bug This issue reports a buggy (incorrect) behavior. status:confirmed labels Dec 20, 2019
@Reinmar
Copy link
Member Author

Reinmar commented Dec 20, 2019

cc @jodator

@Reinmar
Copy link
Member Author

Reinmar commented Dec 20, 2019

I'm thinking about something like this:

		const watcher = new TextWatcher( editor.model, text => {
			for ( const transformation of configuredTransformations ) {
				const from = normalizeFrom( transformation.from );
				const to = normalizeTo( transformation.to );
			
				const match = from.test( text );

				if ( match ) {
					// Return match meta data so we can access that in the `matched:data` event.
					return { match, transformation };
				}
			}
		} );

		watcher.on( 'matched:data', ( evt, data ) => {
			const transformation = data.transformation;

			// Apply the transformation...
		} );

Which means that the return value of TextWatcher callback must allow returning some metadata (in this case – the transformation object that we need later on in matched:data listener.

@Reinmar Reinmar added this to the iteration 29 milestone Dec 20, 2019
@jodator
Copy link
Contributor

jodator commented Dec 20, 2019

Yeah, I was worried about that and probably left for next step which supposed to be opening the API.

The problem with that might be different and might be deeper. Nah we can fix that as you proposed. I would only advise to not take this example as-is. Ie, the from/to might be stored somewhere to not create them every time user type. The for loop should be AFAP® (as-fast-as-possible) IMO.

The other things is that we could rethink this watcher API and how the test callbacks are registered but passing stuff in the data is OK.

@Reinmar Reinmar modified the milestones: iteration 29, nice-to-have Jan 30, 2020
Reinmar added a commit to ckeditor/ckeditor5-typing that referenced this issue Mar 10, 2020
Other: Run only one instance of the `TextWatcher` for all text transformations. Closes ckeditor/ckeditor5#6020.
@Reinmar Reinmar modified the milestones: nice-to-have, iteration 30 Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
3 participants