fix bug propagete modify to grandparent

This commit is contained in:
Grol Grol 2025-07-13 21:03:02 +03:00
parent 93bb79bb3e
commit c64f943ca8
5 changed files with 77 additions and 5 deletions

View file

@ -146,7 +146,7 @@ describe('CheckboxUtils2', () => {
expect(utils.syncText(textBefore, textBefore)).toBe(textBefore);
});
it('checkbox, list', ()=> {
it('checkbox, list', () => {
const utils = new CheckboxUtils2(createSettings({
enableAutomaticChildState: true,
enableAutomaticParentState: true,
@ -171,7 +171,7 @@ describe('CheckboxUtils2', () => {
expect(utils.syncText(actualText, textBefore)).toBe(expectedText);
});
it('checkbox, plain text', ()=> {
it('checkbox, plain text', () => {
const utils = new CheckboxUtils2(createSettings({
enableAutomaticChildState: true,
enableAutomaticParentState: true,
@ -305,7 +305,50 @@ describe('CheckboxUtils2', () => {
' Child3',
].join('\n');
expect(utils.syncText(actualText, textBefore)).toBe(expected);
});
});
});
describe('bags', () => {
it('bag 1', () => {
const utils = new CheckboxUtils2(createSettings({
enableAutomaticChildState: true,
enableAutomaticParentState: true,
}));
const oldText = [
'- [ ] 3д детали',
' - [ ] грузики для веревки ^be5c11',
' - [ ] привод жалюзи ^202ccf',
' - [ ] 3д детали',
' - [ ] корпус',
' - [ ] бобина для веревки',
' - [ ] основной редуктор',
' - [ ] червячный редуктор',
' - [ ] подшипник',
].join('\n');
const actualText = [
'- [ ] 3д детали',
' - [ ] грузики для веревки ^be5c11',
' - [ ] привод жалюзи ^202ccf',
' - [x] 3д детали',
' - [ ] корпус',
' - [ ] бобина для веревки',
' - [ ] основной редуктор',
' - [ ] червячный редуктор',
' - [ ] подшипник',
].join('\n');
const expected = [
'- [ ] 3д детали',
' - [ ] грузики для веревки ^be5c11',
' - [ ] привод жалюзи ^202ccf',
' - [x] 3д детали',
' - [x] корпус',
' - [x] бобина для веревки',
' - [ ] основной редуктор',
' - [ ] червячный редуктор',
' - [ ] подшипник',
].join('\n');
expect(utils.syncText(actualText, oldText)).toBe(expected);
});
});
});

View file

@ -19,11 +19,22 @@ export class CheckboxUtils2 implements ICheckboxUtils {
if (text === textBefore) {
return text;
}
console.log(`text before:`);
console.log(text);
console.log("___");
const context = ContextFactory.createContext(text, textBefore, this.settings);
this.propagateStateToChildrenProcess.process(context);
this.propagateStateToParentProcess.process(context);
console.log(`text after:`);
const res = context.getResultText()
console.log(res);
console.log("___");
return context.getResultText();
}
}

View file

@ -35,8 +35,14 @@ export class ContextFactory {
private static createFlatNodesFromLines(lines: Line[]): TreeNode[] {
const nodes: TreeNode[] = [];
const stack: TreeNode[] = [];
let changeNode: null | TreeNode = null;
for (const line of lines) {
const node = new TreeNode(line);
if (line instanceof CheckboxLine && line.isChange()) {
changeNode = node;
}
// найти родителя
let parent = undefined;
@ -56,6 +62,12 @@ export class ContextFactory {
nodes.push(node);
stack.push(node);
}
let parentChangeNode = changeNode?.getParent();
while (parentChangeNode) {
parentChangeNode.setModify(true);
parentChangeNode = parentChangeNode?.getParent();
}
return nodes;
}
@ -93,6 +105,8 @@ export class ContextFactory {
oldLine.getState() !== actualLine.getState()
) {
actualLine.setChange(true);
const text = actualLine.toResultText();
console.log(`ContextFactory:markChangeIfNeeded: ${text} is change`);
}
}

View file

@ -24,6 +24,10 @@ export class TreeNode {
return this.modify;
}
setModify(isModify:boolean){
this.modify = isModify;
}
private setParent(parent: TreeNode) {
this.parent = parent;
}
@ -35,8 +39,6 @@ export class TreeNode {
addChildren(children: TreeNode) {
this.childrens.push(children);
children.setParent(this);
this.modify = this.modify || children.isModify();
}
hasChildren(): boolean {

View file

@ -11,12 +11,14 @@ export class PropagateStateToChildrenProcess implements CheckboxProcess {
return;
}
if (!context.textBeforeChangeIsPresent()) {
console.log("PropagateStateToChildrenProcess: textBeforeChange is not present");
return;
}
// получить представление текста
const view = context.getView();
if (!view.isModify()) {
console.log("PropagateStateToChildrenProcess: not modify");
return;
}