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

Editor#isReadOnly should work like disabling commands (blockable multiple times by different features) #10496

Closed
scofalik opened this issue Sep 8, 2021 · 6 comments · Fixed by #11441
Assignees
Labels
bc:major Resolving this issue will introduce a major breaking change. squad:collaboration Issue to be handled by the Collaboration team. type:improvement This issue reports a possible enhancement of an existing feature.

Comments

@scofalik
Copy link
Contributor

scofalik commented Sep 8, 2021

📝 Provide a description of the improvement

At the moment, Editor#isReadOnly is a simple property that can be set to either true or false. This is limiting and leads to incorrect code.

Consider two mechanisms (features), that may want to set editor to readonly mode. At the beginning, both of them may decide that "there's some kind of error" and switch editor to read-only. But then, one problem is solved, so one of the mechanisms switches back isReadOnly to true. This is incorrect, because the other mechanism still wants to block the editor.

This is the same situation as with commands, where multiple features may want to set a command as disabled.

My proposal is to:

  • change Editor#isReadOnly to ... wait for it ... readonly property.
  • add Editor#setReadOnly( id:String|Symbol ) and Editor#unsetReadOnly( id ) or (unlockReadOnly( id )) -- similarly as in commands,
  • fix all places where we set Editor#isReadOnly.

One note is that Editor#isReadOnly could also be directly linked with document editing permission. Maybe document editing permission should be the only thing that actually changes Editor#isReadOnly and it should be dynamically affected by other mechanisms/features? However, I don't think that this really makes sense. For example, consider losing connection to Cloud Services. In such situation, we switch the editor to read-only. I don't think that it would make sense to switch user permission to "cannot edit" in this situation.

@scofalik scofalik added the type:improvement This issue reports a possible enhancement of an existing feature. label Sep 8, 2021
@mlewand
Copy link
Contributor

mlewand commented Jan 24, 2022

I wonder if we could somehow avoid breaking changes on this one but I don't think that's possible. The only level of backward compatibility would be to clear all registered locks on doing ediotr.isReadOnly = false but this defeats the purpose of this request.

BTW, to be consistent with what we did already we should go with clearReadOnly() name (as there's clearForceDisabled() in command).

@mlewand mlewand added the squad:core Issue to be handled by the Core team. label Jan 24, 2022
@scofalik
Copy link
Contributor Author

Maybe we could provide a mixin that could handle that for other classes as well. This is a common pattern in our code.

@Reinmar Reinmar added squad:collaboration Issue to be handled by the Collaboration team. and removed squad:core Issue to be handled by the Core team. labels Jan 25, 2022
@scofalik
Copy link
Contributor Author

scofalik commented Jan 25, 2022

We can also leave setting .isReadOnly to true / false as something deprecated (+ log warning on console) and it would work as it did (i.e., setting to false would remove all the locks and setting to true would add one lock). It won't work worse than it does now. We would have a proper logic in our features and those users that used .isReadOnly in their 3rd party plugins would not need to fix the code immediately.

Although personally, I am against such things, for multiple reasons: first, it creates hidden problems, second it will have to be done at some point anyway, third it makes our code messy, fourth it discourages users to update their code ("okay, I'll fix it later" -> forgetting that there's something to fix -> looking way back in the changelog what changed after the deprecated code is removed).

@Reinmar Reinmar added the status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. label Feb 11, 2022
@CKEditorBot CKEditorBot added status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. and removed status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. labels Mar 8, 2022
scofalik added a commit that referenced this issue Apr 4, 2022
Feature (core): Introduced locking mechanism for `Editor#isReadOnly`. Read-only mode can now be separately enabled and disabled by multiple features, which allows for a proper control without conflicts between features. Closes #10496.

Other (core): `Editor#isReadOnly` is now a read-only property.

MAJOR BREAKING CHANGE: The `Editor#isReadOnly` property is now read-only. From now, this property is controlled by `Editor#enableReadOnlyMode( lockId )` and `Editor#disableReadOnlyMode( lockId )`, which allow controlling the `Editor#isReadOnly` state by more than one feature without collisions. See the migration guide to learn more.
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Apr 4, 2022
@scofalik scofalik added this to the iteration 52 milestone Apr 4, 2022
@pomek pomek added the bc:major Resolving this issue will introduce a major breaking change. label Apr 7, 2022
@pomek
Copy link
Member

pomek commented Apr 8, 2022

Why does the Editor#enableReadOnlyMode() accept a second parameter that can be set to false? It looks weird: editor.enableReadOnlyMode( 'foo', false ).

We should have only two methods:

  • Editor#enableReadOnlyMode( lockId ) to create a new lock.
  • Editor#disableReadOnlyMode( lockId ) to remove the lock.

Then, if we think that the "toggle" method is needed, it should be implemented as a new thing: editor.setReadOnlyMode( lockId, isEnabled )

@scofalik
Copy link
Contributor Author

scofalik commented Apr 8, 2022

It was to simplify the most common usage:

myFeature.on( 'change:someValue', () => {
    editor.enableReadOnlyMode( 'myId', myFeature.someValue );
} );

I agree that it looked better when the method was called setReadOnly() (or setReadOnlyMode()).

@mlewand
Copy link
Contributor

mlewand commented Apr 8, 2022

We stick to enableReadOnlyMode + disableReadOnlyMode.

But enableReadOnlyMode will not have this second parameter that confused some of us.

pomek added a commit to ckeditor/ckeditor5-inspector that referenced this issue Apr 12, 2022
Other: Aligned the CKEditor 5 Inspector API to use the new lock mechanism when enabling/disabling the read-only mode.

MAJOR BREAKING CHANGE: Due to introducing the lock mechanism for the `Editor#isReadOnly` property, the inspector uses the new way of enabling the read-only mode in the editor. It requires an instance of CKEditor 5 in version 34 or higher. See ckeditor/ckeditor5#10496.
pomek added a commit to ckeditor/ckeditor5-vue2 that referenced this issue Apr 12, 2022
Other: Aligned the `<CKEditor>` component API to use the new lock mechanism when enabling/disabling the read-only mode.

MAJOR BREAKING CHANGE: Due to introducing the lock mechanism for the `Editor#isReadOnly` property, the `<CKEditor>` component uses the new way of enabling the read-only mode in the editor. The component requires an instance of CKEditor 5 in version 34 or higher. See ckeditor/ckeditor5#10496.
pomek added a commit to ckeditor/ckeditor5-vue that referenced this issue Apr 12, 2022
Other: Aligned the `<CKEditor>` component API to use the new lock mechanism when enabling/disabling the read-only mode.

MAJOR BREAKING CHANGE: Due to introducing the lock mechanism for the `Editor#isReadOnly` property, the `<CKEditor>` component uses the new way of enabling the read-only mode in the editor. The component requires an instance of CKEditor 5 in version 34 or higher. See ckeditor/ckeditor5#10496.
pomek added a commit to ckeditor/ckeditor5-angular that referenced this issue Apr 12, 2022
Other: Upgraded the CKEditor 5 packages to their latest versions. Closes #304.

Other: Aligned the `<CKEditor>` component API to use the new lock mechanism when enabling/disabling the read-only mode.

MAJOR BREAKING CHANGE: Due to introducing the lock mechanism for the `Editor#isReadOnly` property, the `<CKEditor>` component uses the new way of enabling the read-only mode in the editor. The component requires an instance of CKEditor 5 in version 34 or higher. See ckeditor/ckeditor5#10496.
pomek added a commit to ckeditor/ckeditor5-react that referenced this issue Apr 12, 2022
Other: Aligned the `<CKEditor>` component API to use the new lock mechanism when enabling/disabling the read-only mode.

MAJOR BREAKING CHANGE: Due to introducing the lock mechanism for the `Editor#isReadOnly` property, the `<CKEditor>` component uses the new way of enabling the read-only mode in the editor. The component requires an instance of CKEditor 5 in version 34 or higher. See ckeditor/ckeditor5#10496.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bc:major Resolving this issue will introduce a major breaking change. squad:collaboration Issue to be handled by the Collaboration team. type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants