From 3fb695a7a0f93904fab48d5ad4ffd5f9131ba436 Mon Sep 17 00:00:00 2001 From: Luiza Pagliari Date: Wed, 30 Mar 2016 11:51:18 -0300 Subject: [PATCH 1/2] Create hook to register events that won't scroll editor after aceEditEvt --- doc/api/hooks_client-side.md | 11 +++++++++-- src/static/js/ace2_inner.js | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/doc/api/hooks_client-side.md b/doc/api/hooks_client-side.md index b22db5dad5e..9d9cae25087 100644 --- a/doc/api/hooks_client-side.md +++ b/doc/api/hooks_client-side.md @@ -134,6 +134,13 @@ 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. + ## aceRegisterBlockElements Called from: src/static/js/ace2_inner.js @@ -166,11 +173,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]() diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 8576ee33609..24684b6d0c8 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -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) @@ -506,7 +519,7 @@ function Ace2Inner(){ { updateBrowserSelectionFromRep(); } - if ((cs.docTextChanged || cs.userChangedSelection) && cs.type != "applyChangesToBase") + if ((cs.docTextChanged || cs.userChangedSelection) && isScrollableEditEvent(cs.type)) { scrollSelectionIntoView(); } From 69ac8e172278dd337ab61a8c0a53739db7d6a559 Mon Sep 17 00:00:00 2001 From: Luiza Pagliari Date: Mon, 20 Jun 2016 06:31:11 -0300 Subject: [PATCH 2/2] Include usage example for aceRegisterNonScrollableEditEvents --- doc/api/hooks_client-side.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/api/hooks_client-side.md b/doc/api/hooks_client-side.md index 9d9cae25087..9af0356987a 100644 --- a/doc/api/hooks_client-side.md +++ b/doc/api/hooks_client-side.md @@ -141,6 +141,13 @@ 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