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

Refactor *AutoformatEditing.js #7366

Closed
tomalec opened this issue Jun 3, 2020 · 5 comments
Closed

Refactor *AutoformatEditing.js #7366

tomalec opened this issue Jun 3, 2020 · 5 comments
Labels
domain:dx This issue reports a developer experience problem or possible improvement. package:autoformat resolution:expired This issue was closed due to lack of feedback. squad:core Issue to be handled by the Core team. status:stale type:refactor This issue requires or describes a code refactoring. type:task This issue reports a chore (non-production change) and other types of "todos".

Comments

@tomalec
Copy link
Contributor

tomalec commented Jun 3, 2020

This is a followup after #1239 and #7290 (comment)

Provide a description of the task

During the implementation of #7346 I found a few things that look like a code smell to me:

  1. inlineAutoformatEditing.js takes testRegexpOrCallback as an argument, while only regExp is used, and the callback is only used in test suite.

    In my opinion, this functionality could be dropped.

  2. blockAutoformatEditing behaves inconsistently when it comes to checking if the command is enabled. Usually, it checks it early on data change, but for headings, it checks it after is performed all the matches. Also, inlineAutoformatEditing checks it late.

    In my opinion, it should be checked early for all cases, to avoid pointless computation.

  3. Both *AutoformatEditings basically do (pseudocode):

    editor.model.document.on( 'change:data', ( evt, batch ) => {
    	if ( !isEverytighEnabled || !isnotTyping ) {
    		 return false;
    	}
    	// Only difference:
    		text = getDataToCheck();
    
    	match = patternMatch( text );
    	match && editor.model.enqueueChange( writer => {
    		formatCallback()
    	} );
    } );
    

    I believe we can make it DRYier, by letting one extend the other, or moving common code to autoformat.js, and let inlineAutoformatEditing.js, blockAutoformatEditing.js deliver functionality that really differs.

📃 Other details

@tomalec tomalec added type:task This issue reports a chore (non-production change) and other types of "todos". type:refactor This issue requires or describes a code refactoring. squad:red labels Jun 3, 2020
@tomalec
Copy link
Contributor Author

tomalec commented Jun 5, 2020

GitHub Writer already have those and other problems addressed, see https://github.com/ckeditor/github-writer/blob/7aacc28ca6978b319ddbf85f8387025d3629e821/src/app/plugins/autoformat.js

We could start by porting its structure back to ckeditor5. The behavior is slightly different but more intuitive in my opinion, for sure it's worth considering. I believe we can also, take the structure keeping the current behavior as well.


I reached out @fredck for his comments on that. (I hope he will not mind posting them here)

The plugin is pretty complete and I’m very happy with the format of the API. Also, it doesn’t depend on any other code in GHW. It cannot be taken as is ofc, but it is a matter of just cleaning it up with things that don’t make sense for a generic plugin, but I believe there are really very little to be done:

I would be happy to remove the plugin from GHW and use the official one, so let me know if there is a GitHub issue to follow about this.

Guys were talking about exactly this feature yesterday in #github-writer. There is a small annoyance with it as it’s not working when auto-formatting inside the parenthesis, like (bold). I was aware of it and wanted to fix it. I think it is just a matter of fixing these two regexes:

Finally, you have also 100% test coverage for it here:
https://github.com/ckeditor/github-writer/blob/7aacc28ca6978b319ddbf85f8387025d3629e821/tests/unit/plugins/autoformat.js
GHW tests are compatible with CKEditor 5 tests, so you can more or less copy the file as is.

@jodator
Copy link
Contributor

jodator commented Jun 10, 2020

Related: #2400 - there was an idea to re-use TextWatcher in those plugins. The TextWatcher might need some polishing though.

@Reinmar
Copy link
Member

Reinmar commented Jun 25, 2020

cc @mlewand

@mlewand mlewand added this to the backlog milestone Jun 29, 2020
@Reinmar Reinmar removed the squad:red label Jul 2, 2020
@Reinmar Reinmar removed the squad:red label Nov 2, 2020
@Reinmar Reinmar added domain:dx This issue reports a developer experience problem or possible improvement. squad:core Issue to be handled by the Core team. and removed squad:dx labels Sep 9, 2021
@pomek pomek removed this from the backlog milestone Feb 21, 2022
@CKEditorBot
Copy link
Collaborator

There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.

@CKEditorBot
Copy link
Collaborator

We've closed your issue due to inactivity over the last year. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).

@CKEditorBot CKEditorBot added the resolution:expired This issue was closed due to lack of feedback. label Nov 13, 2023
@CKEditorBot CKEditorBot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:dx This issue reports a developer experience problem or possible improvement. package:autoformat resolution:expired This issue was closed due to lack of feedback. squad:core Issue to be handled by the Core team. status:stale type:refactor This issue requires or describes a code refactoring. type:task This issue reports a chore (non-production change) and other types of "todos".
Projects
None yet
Development

No branches or pull requests

7 participants