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

Add forward and backward deletion to PostEditor #83

Merged
merged 1 commit into from
Aug 18, 2015

Conversation

bantic
Copy link
Collaborator

@bantic bantic commented Aug 17, 2015

Changes postEditor#deleteCharAt to be postEditor#deleteFrom(position, direction).

Adds unit tests for the postEditor directly that assert that it changes
the AT as expected.

Some cleanup in the editor as well to remove some duplicated code.

fixes #36

cc @mixonic

}

this._renderTree = this.prepareRenderTree(this.post);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@bantic bantic force-pushed the forward-delete-v2-36 branch from 92541a8 to f467202 Compare August 17, 2015 21:54
marker: offsets.headMarker,
offset: offsets.headOffset
};
results = postEditor.deleteFrom(deletePosition, direction);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, if we add a deleteFrom can it just be added on top of a deleteCharAt API? I imagine a generic character deletion API would be useful.

Or should the deleteRange just be used. Could be build both a deleteCharAt and deleteFrom on top of deleteRange? I found having all the logic for a given case flowing through one function was really useful for the linked list, ala insertBefore managing append, prepend, insertAfter etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I think directional deletion makes something like deleteCharAt feel awkward. If we are deleting, the direction matters. And we want to delete from a cursor position rather than at a character offset (that's why I changed the method name from deleteCharAt to deleteFrom). For instance to backward-delete "from" the beginning of a section (joining with the previous section) is semantically different than deleting the character "at" the 0th position of the section (in that case, at least to my ears, no joining would be implied, just removal of the character).

I could see an argument for a deleteCharAt method that had no implication of joining anything and only removes a character in a marker at a given character offset. I'd consider removeCharAt(marker, offset) to be a better name, though.

I still have a little trouble following the many conditionals of LL's insertBefore — I would be hesitant to combine the forward- and backward- deletion cases into a single method for fear that the logic would be tortuous. They have a lot of symmetric similarity, but only a little duplicated code (when the cursor offset is in the middle of a marker — that would be a good candidate to refactor into a removeCharAt method), and there's a real difference between them in that the nextCursor marker and offset do not need to change for forward-deletion but they do in nearly every case for backward-deletion.

Copy link
Contributor

@mixonic mixonic Aug 17, 2015 via email

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think when we have a lot of potentially different input formats floating around we're likely missing an abstraction. I've been wanting a Position or CursorPosition container that makes passing around positional information easier. The deleteFrom({marker, offset}) could become deleteFrom(positionInstance) in the future.

Having a position abstraction would open up deleteRange so that we could do things like deleteRange(from=cursorPosition, to=cursorPosition.moveBackOne()) and deleteRange(from=cursorPosition, to=cursorPosition.moveForwardOne()). I would like to tackle that in a future PR, though. There is good test coverage for deleteFrom now that we can lean on until then.

@bantic bantic force-pushed the forward-delete-v2-36 branch from f467202 to faf6a63 Compare August 17, 2015 22:00
])
})
*/
function makeMD(treeFn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be makeMobiledoc?

Additionally, those docs do not look like valid syntax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe change it to build or just make? It is used by Helpers.mobiledoc as Helpers.mobiledoc.makeMD, already slightly redundant. Changing to makeMobiledoc would make the code read Helpers.mobiledoc.makeMobiledoc.

The mobiledoc should be valid — it first builds a post and then converts it to mobiledoc.

Copy link
Contributor

Choose a reason for hiding this comment

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

build seems fine to me. I'm just railing against abbreviations.

makeMD({post, section, marker, markup} =>
  post([
    section('P', [
      marker('some text', [markup('B')])
    ])
  })

is not valid JS. I ported it to something that parses:

makeMD(({post, section, marker, markup}) => {
  return post([
    section('P', [
      marker('some text', [markup('B')])
    ])
  ]);
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see — fixed. And changed to build

@bantic bantic force-pushed the forward-delete-v2-36 branch 2 times, most recently from 6561993 to c827e09 Compare August 17, 2015 22:25
@bantic bantic force-pushed the forward-delete-v2-36 branch from c827e09 to cbb7182 Compare August 17, 2015 22:33
mixonic added a commit that referenced this pull request Aug 18, 2015
Add forward and backward deletion to PostEditor
@mixonic mixonic merged commit 019814e into master Aug 18, 2015
@bantic bantic deleted the forward-delete-v2-36 branch August 20, 2015 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Forward delete behaves the same as backspace
2 participants