Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Fixed integration with undo #54

Merged
merged 6 commits into from
Mar 12, 2018
Merged

Fixed integration with undo #54

merged 6 commits into from
Mar 12, 2018

Conversation

szymonkups
Copy link
Contributor

@szymonkups szymonkups commented Mar 12, 2018

Suggested merge commit message (convention)

Fix: Fixed integration with undo. Closes ckeditor/ckeditor5#2397.

@szymonkups szymonkups requested review from Reinmar and scofalik March 12, 2018 07:24
@coveralls
Copy link

coveralls commented Mar 12, 2018

Coverage Status

Coverage increased (+4.8%) to 100.0% when pulling 9024f2b on t/53 into 62e2627 on master.

@Reinmar
Copy link
Member

Reinmar commented Mar 12, 2018

Redo is still funky, but undo works fine.

TC:

  1. Type xxx
  2. Type **yyy**
  3. Type zzz
  4. Undo 1: xxx<b>yyy</b>
  5. Undo 2: xxx**yyy**
  6. Undo 3: empty
  7. Redo 1:
    • Expected: xxx**yyy**
    • Actual: xxx<b>yyy</b>

@Reinmar
Copy link
Member

Reinmar commented Mar 12, 2018

What's more – it's completely impossible to redo to the full text (xxxyyyzzz) on this branch. But this is something we might live with for a while.

@Reinmar
Copy link
Member

Reinmar commented Mar 12, 2018

@scofalik, if fixing redo is not feasible now, this PR LGTM in terms of behaviour.

continue;
}
// Do nothing if selection is not collapsed.
if ( !selection.isCollapsed || !selection.focus || !selection.focus.parent ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall ever checking .focus not to say .focus.parent in selection checks anywhere in the code base. Are these needed? When do they matter?

// Use enqueueChange to create new batch to separate typing batch from the auto-format changes.
editor.model.enqueueChange( writer => {
const validRanges = editor.model.schema.getValidRanges( rangesToFormat, attributeKey );
rangesToFormat.push( LiveRange.createFromParentsAndOffsets(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use LiveRanges anymore? I understand that earlier we had to use them, cause the callback was added to (something like) applyOperation and there might be more operations incoming and the range could change. However, now, we fire callback after all changes are done, so the ranges should not change. Additionally, we are reversing the order to prevent messing up positions. Maybe LiveRanges are not needed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. It looks like live ranges are not needed anymore.

// Detach ranges used to apply Autoformat. Prevents memory leaks. #39
rangesToFormat.forEach( range => range.detach() );
// Reverse order to not mix the offsets while removing.
ranges.remove.slice().reverse().forEach( range => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why .slice() here? (I know this is not originally your code).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and above arrays transformation look alike. Maybe helper function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why .slice() here? (I know this is not originally your code).

Probably to create a copy of the array since reverse() is working in place. I will try to simplify it and use a helper.

continue;
}
// Typing is represented by only a single change.
if ( changes.length != 1 || entry.type !== 'insert' || entry.name != '$text' ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if there was only one letter inserted (change size is 1).

// @param {module:engine/model/element~Element} block
// @param {Array.<Array>} arrays
function testOutputToRanges( block, arrays ) {
return arrays.map( array => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be easier to read, if .filter was first and then .map?

@scofalik scofalik merged commit f5d68f4 into master Mar 12, 2018
@scofalik scofalik deleted the t/53 branch March 12, 2018 14:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undo not working with inline auto format
4 participants