-
Notifications
You must be signed in to change notification settings - Fork 152
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
Conversation
} | ||
|
||
this._renderTree = this.prepareRenderTree(this.post); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
92541a8
to
f467202
Compare
marker: offsets.headMarker, | ||
offset: offsets.headOffset | ||
}; | ||
results = postEditor.deleteFrom(deletePosition, direction); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
f467202
to
faf6a63
Compare
]) | ||
}) | ||
*/ | ||
function makeMD(treeFn) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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')])
])
]);
});
There was a problem hiding this comment.
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
6561993
to
c827e09
Compare
c827e09
to
cbb7182
Compare
Add forward and backward deletion to PostEditor
Changes
postEditor#deleteCharAt
to bepostEditor#deleteFrom(position, direction)
.Adds unit tests for the
postEditor
directly that assert that it changesthe AT as expected.
Some cleanup in the editor as well to remove some duplicated code.
fixes #36
cc @mixonic