Closed eguitarz closed 8 years ago
@eguitarz Is this because you want to do the conversion only after hitting enter on the line? Would it work for your purposes to convert to h* after the user hits the space? e.g.:
To answer you question, the "\n" is not matched by the onTextInput
— enter is handled by editor.insertNewline()
instead. We can certainly add hooks similar to the delete hooks for before/after inserting a newline. As discussed here (https://github.com/bustlelabs/mobiledoc-kit/issues/451#issuecomment-239449216), it would be useful for some folks to be able to have a little more control over what the insertNewline
functionality means (the ability to keep or change the current markup section tagname, e.g. — right now any newline resets to a standard "p" markup section).
There's also a request for the ability to special-case newline-handling for different section types here: https://github.com/bustlelabs/mobiledoc-kit/issues/432#issuecomment-239194830
@bantic I agree this could be a temporary solution, but if we can control insertNewline
would be great. Because when implementing image or link markdown syntax, it would be nice to insert a card or atom after you press enter
.
![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png)
I believe this could make mobiledoc allows more interesting customizations. This might also be helpful if we are supporting pre
tag. We can enter code editing mode when detected + enter. In code editing mode, every `enter` will be converted to `\n` instead of adding new section. Once users finished editing code, they can type
+ enter to exit coding mode.
+1 yes, if you are interested in making a PR that'd be great. Otherwise I'll mark this as a feature request and we'll get it in as soon as we can.
Thanks, will see what I can do to make this happen!
@bantic After thinking about this feature, I'm proposing two modifications.
willHandleNewline
/didHandleNewline
hooks.disableNewline
function in editorThis could grant fully controls on handling newline. For user to define their own newline behavior, they can disableNewline
in willHandleNewline
hook, perform customized function, then enable newline again in didHandleNewline
.
How do you think about this?
@eguitarz How about if willHandleNewline
returns an explicit false
, mobiledoc-kit skips the default handling? So if you want to do something special you do it in willHandleNewline
and just return false
?
@bantic That sounds perfect to me! I'll work on this - Add willHandleNewline
hook prior to handleNewLine
and will stop handling new line if willHandleNewline
returns explicit false
(It works as default if willHandleNewline
didn't return or it returns true).
I believe this is closed by #489. thanks @eguitarz ! Feel free to reopen if necessary.
When implementing heading (H1, H2, H3) in WYSIWYG markdown editor, it would requires detecting if
newline
is entered. So I can do something like this:Is this possible in current structure?