Skip to content

Commit

Permalink
Merge pull request #2944 from storytouch/aceRegisterNonScrollableEdit…
Browse files Browse the repository at this point in the history
…Events

Create hook to register events that won't scroll editor after aceEditEvt
  • Loading branch information
JohnMcLear committed Jun 20, 2016
2 parents 3f4c8d3 + 69ac8e1 commit f09e10b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
18 changes: 16 additions & 2 deletions doc/api/hooks_client-side.md
Expand Up @@ -134,6 +134,20 @@ Things in context:

This hook is made available to edit the edit events that might occur when changes are made. Currently you can change the editor information, some of the meanings of the edit, and so on. You can also make internal changes (internal to your plugin) that use the information provided by the edit event.

## aceRegisterNonScrollableEditEvents
Called from: src/static/js/ace2_inner.js

Things in context: None

When aceEditEvent (documented above) finishes processing the event, it scrolls the viewport to make caret visible to the user, but if you don't want that behavior to happen you can use this hook to register which edit events should not scroll viewport. The return value of this hook should be a list of event names.

Example:
```
exports.aceRegisterNonScrollableEditEvents = function(){
return [ 'repaginate', 'updatePageCount' ];
}
```

## aceRegisterBlockElements
Called from: src/static/js/ace2_inner.js

Expand Down Expand Up @@ -166,11 +180,11 @@ Called from: src/static/js/pad_editbar.js
Things in context:

1. ace - the ace object that is applied to this editor.
2. toolbar - Editbar instance. See below for the Editbar documentation.
2. toolbar - Editbar instance. See below for the Editbar documentation.

Can be used to register custom actions to the toolbar.

Usage examples:
Usage examples:

* [https://github.com/tiblu/ep_authorship_toggle]()

Expand Down
15 changes: 14 additions & 1 deletion src/static/js/ace2_inner.js
Expand Up @@ -369,6 +369,19 @@ function Ace2Inner(){
return thisAuthor;
}

var _nonScrollableEditEvents = {
"applyChangesToBase": 1
};

_.each(hooks.callAll('aceRegisterNonScrollableEditEvents'), function(eventType) {
_nonScrollableEditEvents[eventType] = 1;
});

function isScrollableEditEvent(eventType)
{
return !_nonScrollableEditEvents[eventType];
}

var currentCallStack = null;

function inCallStack(type, action)
Expand Down Expand Up @@ -506,7 +519,7 @@ function Ace2Inner(){
{
updateBrowserSelectionFromRep();
}
if ((cs.docTextChanged || cs.userChangedSelection) && cs.type != "applyChangesToBase")
if ((cs.docTextChanged || cs.userChangedSelection) && isScrollableEditEvent(cs.type))
{
scrollSelectionIntoView();
}
Expand Down

0 comments on commit f09e10b

Please sign in to comment.