Skip to content

Commit 972ecfd

Browse files
committed
Fix: when page moved , the setModified of type "PAGE_MOVED" has not excute #943
1 parent fed3256 commit 972ecfd

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/components/pages-editor.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ko from "knockout";
2-
import { SurveyHelper, editorLocalization } from '../entries';
2+
import { SurveyHelper, editorLocalization } from "../entries";
33
import "./pages-editor.scss";
44
import { PagesEditor } from "../pages-editor";
55
import { StylesManager } from "../stylesmanager";
@@ -18,9 +18,7 @@ export class PagesEditorViewModel {
1818
".svd-pages"
1919
);
2020
if (!!pagesElement) {
21-
this.hasScroller(
22-
pagesElement.scrollWidth > pagesElement.offsetWidth
23-
);
21+
this.hasScroller(pagesElement.scrollWidth > pagesElement.offsetWidth);
2422
}
2523
}, 100);
2624

@@ -55,7 +53,7 @@ export class PagesEditorViewModel {
5553
pagesElement.offsetLeft -
5654
pagesElement.offsetWidth / 2;
5755
this.updateMenuPosition();
58-
}
56+
};
5957

6058
onWheel(model, event) {
6159
var pagesElement = model.element.querySelector(".svd-pages");
@@ -86,7 +84,9 @@ export class PagesEditorViewModel {
8684

8785
getPageClass = (page) => {
8886
var result =
89-
page === this.model.selectedPage() ? "svd_selected_page svd-light-bg-color" : "";
87+
page === this.model.selectedPage()
88+
? "svd_selected_page svd-light-bg-color"
89+
: "";
9090

9191
if (this.model.pages.indexOf(page) !== this.model.pages.length - 1) {
9292
result += " svd-border-right-none";
@@ -96,7 +96,8 @@ export class PagesEditorViewModel {
9696
};
9797

9898
getPageMenuIconClass = (page) => {
99-
var baseIconName = StylesManager.currentTheme() === "modern" ? "dots" : "gear";
99+
var baseIconName =
100+
StylesManager.currentTheme() === "modern" ? "dots" : "gear";
100101
return page === this.model.selectedPage() && this.model.isActive()
101102
? "icon-" + baseIconName + "active"
102103
: "icon-" + baseIconName;
@@ -110,12 +111,14 @@ export class PagesEditorViewModel {
110111
};
111112

112113
public movingPage = null;
114+
private movedFrom: number = -1;
113115
get sortableOptions() {
114116
return {
115117
handle: ".svd-page-name",
116118
animation: 150,
117119
onStart: () => {
118120
this.movingPage = null;
121+
this.movedFrom = -1;
119122
this.model.creator.undoRedoManager.startTransaction(
120123
"pages drag drop transaction"
121124
);
@@ -126,12 +129,17 @@ export class PagesEditorViewModel {
126129
this.model.blockPagesRebuilt(false);
127130
this.model.creator.undoRedoManager.stopTransaction();
128131
if (!!this.movingPage) {
129-
this.model.selectedPage(this.movingPage);
132+
this.model.movePage(this.movingPage, this.movedFrom);
130133
}
131134
},
132135
onUpdate: (evt, itemV) => {
133136
this.movingPage = itemV;
134-
if (SurveyHelper.moveItemInArray(this.model.pages, itemV, evt.newIndex)) {
137+
if (this.movedFrom < 0) {
138+
this.movedFrom = this.model.pages.indexOf(this.movingPage);
139+
}
140+
if (
141+
SurveyHelper.moveItemInArray(this.model.pages, itemV, evt.newIndex)
142+
) {
135143
// Remove sortables "unbound" element
136144
evt.item.parentNode.removeChild(evt.item);
137145
}

src/editor.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1857,11 +1857,8 @@ export class SurveyCreator implements ISurveyObjectEditorOptions {
18571857
public getLocString(str: string) {
18581858
return editorLocalization.getString(str);
18591859
}
1860-
public movePage = (indexFrom: number, indexTo: number) => {
1861-
var page = <Survey.Page>this.survey.pages[indexTo];
1862-
this.surveyObjects.survey = null; // TODO may be we don't need this hack
1863-
this.surveyObjects.survey = this.survey;
1864-
this.selectedElement = page;
1860+
public movePage = (page: Survey.PageModel, indexFrom: number) => {
1861+
var indexTo = this.survey.pages.indexOf(page);
18651862
this.setModified({
18661863
type: "PAGE_MOVED",
18671864
page: page,

src/pages-editor.ts

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export class PagesEditor {
8989
this.creator.deletePage();
9090
};
9191

92+
movePage = (page: Survey.PageModel, indexFrom: number) => {
93+
this.selectedPage(page);
94+
this.creator.movePage(page, indexFrom);
95+
};
96+
9297
showPageSettings(page: Survey.PageModel) {
9398
this.creator.showQuestionEditor(page);
9499
}

0 commit comments

Comments
 (0)