[FEATURE] [BUGFIX] Refactor editor hooks #357
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
postDidChange
hook -- called when post changescursorDidChange
to only fire when the cursorchanges (not when markup or section state changes)
inputModeDidChange
hook -- called when editor inputmode (active markups or active sections) changes
Fixes #319.
BREAKING CHANGE: This is a potentially breaking change for consumers (such as
ember-mobiledoc-editor
) that used thecursorDidChange
hook tomaintain toolbar state.
Most of the time the editor's input mode (active
markups and active section tagNames) changes it is due to changing
cursor position/selection, so listening to the
cursorDidChange
isoften appropriate, but it is possible to change the editor's input mode
without changing cursor position (e.g., hitting "cmd-B" to bold text).
Previously, the
cursorDidChange
hook fired over-eagerly, resulting init firing in some cases (but not all) when the cursor did not change
(but editor input mode did). So it served fairly effectively for keeping the
toolbar's buttons in appropriate active/inactive state. This PR fixes
cursorDidChange
so that it is only called when the cursor positionactually changes, making it even less effective as a hook to use to
infer the editor's active markups and sections (now no input mode change
that doesn't change the cursor will fire
cursorDidChange
).This PR introduces a new
inputModeDidChange
hook that only fires oninput mode changes. This cleanly separates the ability to listen for cursor changes
from listening for input mode changes. It is also more efficient for a consumer to use as a
hook (because most cursor changes do not change input mode at all, so
listening to that hook as a proxy for detecting input mode changes creates unnecessary work).
Also:
postDidChange
hook. Transitioning toedit
or callingenv.cancel
do not trigger the hook.on('update')
hookEditor#_notifyRangeChange
to use to alert the editorof possible cursor- or state-changing activity (e.g., keyup or mousedown,
because they might have moved the cursor).
cursorDidChange
is not fired after the editor isdestroyed
EditState
to better track changes tostate/cursor.