From 8a5b3ef8067453f9c45ce999feb7d55e405f4e25 Mon Sep 17 00:00:00 2001 From: Konstantin Kireyev Date: Mon, 3 Jun 2024 11:04:40 +0500 Subject: [PATCH 1/5] fix/67798: save scroll location when new heading added --- apps/common/main/lib/component/DataView.js | 12 ++++++++++++ .../main/app/controller/Navigation.js | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/apps/common/main/lib/component/DataView.js b/apps/common/main/lib/component/DataView.js index 47cdc20ccf..ffb4cbcd61 100644 --- a/apps/common/main/lib/component/DataView.js +++ b/apps/common/main/lib/component/DataView.js @@ -1103,6 +1103,18 @@ define([ focusInner: function(e) { this.focus(e.keyCode == Common.UI.Keys.DOWN ? 'first' : 'last'); + }, + + willBeVisibleAtScroll: function(index, scrollPosition) { + var child = this.dataViewItems[index]; + if (!child) { + return false; + } + + var elementOffset = child.$el.first().offset().top; + var viewportHeight = $(this.el).first().height(); + + return elementOffset >= scrollPosition && elementOffset < (scrollPosition + viewportHeight); } }); diff --git a/apps/documenteditor/main/app/controller/Navigation.js b/apps/documenteditor/main/app/controller/Navigation.js index 14be80b3e9..9ddf1cc22c 100644 --- a/apps/documenteditor/main/app/controller/Navigation.js +++ b/apps/documenteditor/main/app/controller/Navigation.js @@ -170,6 +170,8 @@ define([ } var me = this; + this._scrollTop = me.panelNavigation.viewNavigationList.scroller.el.scrollTop; + var store = this.getApplication().getCollection('Navigation'); store.reset(arr.splice(0, 50)); @@ -195,13 +197,21 @@ define([ item.set('isEmptyItem', me._navigationObject.isEmptyItem(idx)); }); store.add(added); - if (me._currentPos>-1 && me._currentPos 1) { + if (me._scrollTop > 0 && me.panelNavigation.viewNavigationList.willBeVisibleAtScroll(me._currentPos, me._scrollTop)) { + me.panelNavigation.viewNavigationList.scroller.el.scrollTop = me._scrollTop; + } else { + if (me._currentPos < store.length) { + me.onChangeOutlinePosition(me._currentPos); + me._currentPos = -1; + } + } } addToPanel(); }, 1); } + addToPanel(); }, From c1da9fb4f1e2ad8397ba401a7624e6a5eef0d399 Mon Sep 17 00:00:00 2001 From: Konstantin Kireyev Date: Mon, 3 Jun 2024 15:57:45 +0500 Subject: [PATCH 2/5] fix: scroll didn't work for 0-1 indexes --- apps/common/main/lib/component/DataView.js | 2 +- apps/documenteditor/main/app/controller/Navigation.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/common/main/lib/component/DataView.js b/apps/common/main/lib/component/DataView.js index ffb4cbcd61..92c4046929 100644 --- a/apps/common/main/lib/component/DataView.js +++ b/apps/common/main/lib/component/DataView.js @@ -1105,7 +1105,7 @@ define([ this.focus(e.keyCode == Common.UI.Keys.DOWN ? 'first' : 'last'); }, - willBeVisibleAtScroll: function(index, scrollPosition) { + childWillBeVisibleAtScroll: function(index, scrollPosition) { var child = this.dataViewItems[index]; if (!child) { return false; diff --git a/apps/documenteditor/main/app/controller/Navigation.js b/apps/documenteditor/main/app/controller/Navigation.js index 9ddf1cc22c..2c887cfbee 100644 --- a/apps/documenteditor/main/app/controller/Navigation.js +++ b/apps/documenteditor/main/app/controller/Navigation.js @@ -198,8 +198,8 @@ define([ }); store.add(added); - if (me._currentPos > 1) { - if (me._scrollTop > 0 && me.panelNavigation.viewNavigationList.willBeVisibleAtScroll(me._currentPos, me._scrollTop)) { + if (me._currentPos > -1) { + if (me._scrollTop > 0 && me.panelNavigation.viewNavigationList.childWillBeVisibleAtScroll(me._currentPos, me._scrollTop)) { me.panelNavigation.viewNavigationList.scroller.el.scrollTop = me._scrollTop; } else { if (me._currentPos < store.length) { From b31b6f831a0b0f666a4915db8e18c313265c6a65 Mon Sep 17 00:00:00 2001 From: Konstantin Kireyev Date: Mon, 3 Jun 2024 16:16:36 +0500 Subject: [PATCH 3/5] fix: scroll slow changing --- apps/documenteditor/main/app/controller/Navigation.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Navigation.js b/apps/documenteditor/main/app/controller/Navigation.js index 2c887cfbee..04548d757a 100644 --- a/apps/documenteditor/main/app/controller/Navigation.js +++ b/apps/documenteditor/main/app/controller/Navigation.js @@ -198,14 +198,12 @@ define([ }); store.add(added); - if (me._currentPos > -1) { + if (me._currentPos > -1 && me._currentPos < store.length) { if (me._scrollTop > 0 && me.panelNavigation.viewNavigationList.childWillBeVisibleAtScroll(me._currentPos, me._scrollTop)) { me.panelNavigation.viewNavigationList.scroller.el.scrollTop = me._scrollTop; } else { - if (me._currentPos < store.length) { - me.onChangeOutlinePosition(me._currentPos); - me._currentPos = -1; - } + me.onChangeOutlinePosition(me._currentPos); + me._currentPos = -1; } } addToPanel(); From 1e080a3a349870b7515c1e83ee4e30bc35a01741 Mon Sep 17 00:00:00 2001 From: Konstantin Kireyev Date: Thu, 6 Jun 2024 10:31:14 +0500 Subject: [PATCH 4/5] fix: childWillBeVisibleAtScroll calculations --- apps/common/main/lib/component/DataView.js | 9 ++++-- .../main/app/controller/Navigation.js | 30 +++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/apps/common/main/lib/component/DataView.js b/apps/common/main/lib/component/DataView.js index 92c4046929..91e5ccf9ae 100644 --- a/apps/common/main/lib/component/DataView.js +++ b/apps/common/main/lib/component/DataView.js @@ -1111,10 +1111,13 @@ define([ return false; } - var elementOffset = child.$el.first().offset().top; - var viewportHeight = $(this.el).first().height(); + var $childEl = child.$el.first(); + var $containerEl = $(this.el).first(); - return elementOffset >= scrollPosition && elementOffset < (scrollPosition + viewportHeight); + var elementOffset = $childEl.offset().top - $containerEl.offset().top + $containerEl.scrollTop(); + var viewportHeight = scrollPosition + $containerEl.height() + $childEl.outerHeight(); + + return elementOffset - scrollPosition > 0 && elementOffset <= viewportHeight; } }); diff --git a/apps/documenteditor/main/app/controller/Navigation.js b/apps/documenteditor/main/app/controller/Navigation.js index 04548d757a..b74b8cb0d9 100644 --- a/apps/documenteditor/main/app/controller/Navigation.js +++ b/apps/documenteditor/main/app/controller/Navigation.js @@ -170,23 +170,35 @@ define([ } var me = this; - this._scrollTop = me.panelNavigation.viewNavigationList.scroller.el.scrollTop; + this._scrollTop = me.panelNavigation.viewNavigationList.scroller.getScrollTop(); var store = this.getApplication().getCollection('Navigation'); store.reset(arr.splice(0, 50)); this._currentPos = this._navigationObject.get_CurrentPosition(); + function checkScrollFocus() { + if (me._currentPos > -1 && me._currentPos < store.length) { + if (me._scrollTop > 0 && me.panelNavigation.viewNavigationList.childWillBeVisibleAtScroll(me._currentPos, me._scrollTop)) { + me.panelNavigation.viewNavigationList.scroller.scrollTop(me._scrollTop); + } else { + me.onChangeOutlinePosition(me._currentPos); + me._currentPos = -1; + } + } + } + function addToPanel() { if (arr.length<1) { if (me.timerUpdateId) { clearTimeout(me.timerUpdateId); me.timerUpdateId = 0; } + me.panelNavigation.viewNavigationList.scroller && me.panelNavigation.viewNavigationList.scroller.update({alwaysVisibleY: true}); - if (me._currentPos>-1 && me._currentPos -1 && me._currentPos < store.length) { - if (me._scrollTop > 0 && me.panelNavigation.viewNavigationList.childWillBeVisibleAtScroll(me._currentPos, me._scrollTop)) { - me.panelNavigation.viewNavigationList.scroller.el.scrollTop = me._scrollTop; - } else { - me.onChangeOutlinePosition(me._currentPos); - me._currentPos = -1; - } - } + checkScrollFocus(); addToPanel(); }, 1); } From 42e28377884505647ac0621928e3d5c399d4891e Mon Sep 17 00:00:00 2001 From: Konstantin Kireyev Date: Fri, 7 Jun 2024 21:17:08 +0500 Subject: [PATCH 5/5] fix: element unfocus fix --- apps/documenteditor/main/app/controller/Navigation.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/documenteditor/main/app/controller/Navigation.js b/apps/documenteditor/main/app/controller/Navigation.js index b74b8cb0d9..48b790a17a 100644 --- a/apps/documenteditor/main/app/controller/Navigation.js +++ b/apps/documenteditor/main/app/controller/Navigation.js @@ -181,6 +181,7 @@ define([ if (me._currentPos > -1 && me._currentPos < store.length) { if (me._scrollTop > 0 && me.panelNavigation.viewNavigationList.childWillBeVisibleAtScroll(me._currentPos, me._scrollTop)) { me.panelNavigation.viewNavigationList.scroller.scrollTop(me._scrollTop); + me.panelNavigation.viewNavigationList.selectByIndex(me._currentPos); } else { me.onChangeOutlinePosition(me._currentPos); me._currentPos = -1;