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

Atoms #226

Closed
wants to merge 29 commits into from
Closed

Atoms #226

wants to merge 29 commits into from

Conversation

rlivsey
Copy link
Collaborator

@rlivsey rlivsey commented Nov 12, 2015

Work in progress thoughts on Atoms

Will implement #222

Maybe:

  • add default unknownAtomHandler implementation which just renders the value?

* `buffer` is an array passed to the `html` hook instead of a DOM element.
The content for the atom should be pushed on that array as a string.
* `options` is the `cardOptions` argument passed to the editor or renderer.
* `env` contains information about the running of this hook. It may contain
Copy link
Contributor

Choose a reason for hiding this comment

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

If a card can remove itself, can it also save itself? It if can trigger its own destruction, it seems reasonable that it could change its payload as well.

On the other hand, part of me thinks it should not be able to remove or edit itself. The most conservative approach is that they can only be created and if they are removed it must be through normal editing operations like backspace and delete. Thoughts?

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 took out all the other ones from cards because save/cancel/edit/section didn't seem to be needed for atoms at first glance.

I can picture a use-case for remove such as showing an x on hover and letting you click it to remove the atom, but certainly happy to leave that out initially!

If we do have remove, I can think of some use-cases where an atom could be expose an interface which alters it and therefor would want to update its payload. Not something I personally need right now hence why it didn't spring to mind initially.

Copy link
Contributor

Choose a reason for hiding this comment

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

remove with an x implies that the atom is (partially) in charge of its editing interface. I'd prefer to lean on the conservative path for now and ensure they have zero control over their editing interface.

We can revisit as we get more complex use-cases, if that seems reasonable to you as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

var demoAtom = {
name: 'mention',
display: {
setup(element, options, env, text, payload) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is annoying, but let's change this to follow the new card schema as suggested in #228 (comment)

// package: mda-profile-dom
export default {
  name: 'profile',
  type: 'dom',
  render({element, options, env, text, payload}) {
  }
};

@mixonic
Copy link
Contributor

mixonic commented Nov 16, 2015

Looks good to go :-) @rlivsey I presume we will just leave it open while you spike on implementation this week.

We should attempt to preserve the 0.2 compatibility as we make changes. It will be a bit more painful in the short term since the versioning of parsers/renderer will need to be implemented, but will allow us to merge patches incrementally.

}

remove() {
// this.editor.run(postEditor => postEditor.removeSection(this.model));
Copy link
Contributor

Choose a reason for hiding this comment

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

should likely teardown here

Copy link
Contributor

Choose a reason for hiding this comment

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

This can just be removed.

@bantic
Copy link
Collaborator

bantic commented Nov 17, 2015

This looks good — probably the first set of challenges will be breakage caused by methods in models/_markerable expecting to always encounter markers.
The tests are a little thin around this area, but the unit tests for markupSection would be the right spot to add some more tests that those methods work properly when there is a mix of atoms and markers.

@rlivsey
Copy link
Collaborator Author

rlivsey commented Nov 30, 2015

Getting close…


## Atom format

An atom is a javascript object with 3 *required* properties:
Copy link
Contributor

Choose a reason for hiding this comment

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

"JavaScript" nit pick :-p

@rlivsey
Copy link
Collaborator Author

rlivsey commented Dec 5, 2015

Atoms now have ZWNJ's around them, so when in a section on their own the cursor appears correctly.

Next up is figuring out that the cursor is directly before/after the atom so we can jump across when hitting left/right. For cards this is easy enough as the whole section is a card and so position.section.isCardSection is all that's needed.

Detecting if you're next to an atom is a little trickier by the looks of it.

The atom's DOM looks like:

<span>
  ZWNJ
  <span class="-mobiledoc-kit__atom">...</span>
  ZWNJ
</span>

If the cursor is right after the atom, or in the ZWNJ, then it looks like this.cursor.selection.anchorNode is the ZWNJ and we can do something like this to see if we're in the atom:

let renderNode = this._renderTree.getElementRenderNode(anchorNode.parentNode);
if (renderNode && renderNode.postNode.isAtom) {
   // ...
}

If the cursor is directly before the atom however, it's not in the ZWNJ, at this point we could do something like:

let _comparePosition = comparePosition(this.cursor.selection);
if (_comparePosition.tailNode.length === _comparenPosition.tailOffset) { // at the end of the node
  let nextNode = _comparePosition.tailNode.nextElementSibling;
  let renderNode = nextNode && this._renderTree.getElementRenderNode(nextNode);
  if (renderNode && renderNode.postNode.isAtom) {
     // ...
  }
}

Any thoughts on a nicer way of handling this?

 * change _findCursorForPosition to focus on atom markers properly
 * dom parser marks sections dirty when adding a new marker
 * postEditor#deleteBackwardFrom removes atom marker appropriately
@bantic
Copy link
Collaborator

bantic commented Jan 21, 2016

I am finding one outstanding bug that I'm working on fixing:

  • select only atom, make it bold (=> rendering errors/inconsistencies, e.g. type character at left side of bolded atom)

And have fixed the following bugs that now need test coverage:

  • type text between two atoms
  • before 1st atom: type text (ensure cursor is correct place)
  • after last atom: type text (ensure cursor is in correct place)
  • hitting left arrow in at start of 1st atom in section (should go to end of prev section)
  • hitting right arrow at end of last atom in section
  • hitting right arrow at left of last atom -> cursor does not move to right side of atom (cursor._findNodeForPosition was finding the wrong node for the position)
  • ensure the rendered output after editor#reparse when there is text content in the atom zwnj is correct output (must mark the section as dirty so that the newly-inserted marker gets rendered)
  • [ ] ctr-A does not move to start of atom when atom is at beginning of line
  • [ ] ctr-E does not move to end of line when cursor is left (anywhere left of) an atom
  • “Hello Bobbob” => write test to ensure that neighboring atoms are not coalesced
  • FIXED, needs tests: deleting text from right side of the atom => hitting delete when 1 character after right side deletes and places cursor on left side of atom (this is fixed, but I forget how)
  • select text that ends in the middle of two “Hello Bob” atoms and delete => atoms become “Hello B”. (section.markersFor does not work properly with atoms (it cuts their value in pieces))

This was referenced Feb 2, 2016
@mixonic
Copy link
Contributor

mixonic commented Feb 3, 2016

Closing in favor of #311

@mixonic mixonic closed this Feb 3, 2016
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.

None yet

3 participants