Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/class/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,11 @@ Entry.Playground = class Playground {

updatePictureView() {
if (this.pictureSortableListWidget) {
this.pictureSortableListWidget.setData({ items: [] });
this.pictureSortableListWidget.setData({
items: this._getSortablePictureList(),
Entry.Utils.runWithScrollPreserved(this.pictureListView_, () => {
this.pictureSortableListWidget.setData({ items: [] });
this.pictureSortableListWidget.setData({
items: this._getSortablePictureList(),
});
});
}
this.reloadPlayground();
Expand Down Expand Up @@ -1102,8 +1104,10 @@ Entry.Playground = class Playground {

updateSoundsView() {
if (this.soundSortableListWidget) {
this.soundSortableListWidget.setData({
items: this._getSortableSoundList(),
Entry.Utils.runWithScrollPreserved(this.soundListView_, () => {
this.soundSortableListWidget.setData({
items: this._getSortableSoundList(),
});
});
}

Expand Down
6 changes: 5 additions & 1 deletion src/class/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ Entry.Scene = class {
updateSceneView() {
const items = this._getSortableSceneList();
if (this.sceneSortableListWidget) {
setTimeout(() => this.sceneSortableListWidget.setData({ items }), 0);
setTimeout(() => {
Entry.Utils.runWithScrollPreserved(this.listView_, () => {
this.sceneSortableListWidget.setData({ items });
});
}, 0);
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,27 @@ Entry.Utils.generateId = function () {
return `0000${((Math.random() * Math.pow(36, 4)) << 0).toString(36)}`.substr(-4);
};

/**
* Sortable 위젯의 setData 등 리렌더 콜백 실행 중에도
* 내부 스크롤 컨테이너(.rcs-inner-container)의 스크롤 위치를 유지한다.
* @param {HTMLElement} containerEl Sortable이 마운트된 컨테이너
* @param {Function} callback 리스트를 갱신하는 동기 콜백
*/
Entry.Utils.runWithScrollPreserved = function (containerEl, callback) {
const getScrollEl = () => containerEl && containerEl.querySelector('.rcs-inner-container');
const before = getScrollEl();
const top = before ? before.scrollTop : 0;
const left = before ? before.scrollLeft : 0;

callback();

const after = getScrollEl();
if (after) {
after.scrollTop = top;
after.scrollLeft = left;
}
};

Entry.Utils.randomColor = function () {
const letters = '0123456789ABCDEF';
let color = '#';
Expand Down
Loading