lowcode-engine icon indicating copy to clipboard operation
lowcode-engine copied to clipboard

历史记录不可用

Open zboMa opened this issue 3 years ago • 0 comments

现在的历史记录功能完全不可用,撤回只能撤回一次,重做不可点击。

测试官方demo即可发现问题 https://lowcode-engine.cn/demo/index.html。

自行调试时问题如下 image

调试代码如下 packages\designer\src\document\history.ts

back() {
    if (!this.session) {
      return;
    }
    // console
    console.log('this.session - back', this.session);
    const cursor = this.session.cursor - 1;
    // console
    console.log('back cursor', cursor);
    this.go(cursor);
    const editor = globalContext.get(Editor);
    if (!editor) {
      return;
    }
    editor.emit('history.back', cursor);
  }
go(cursor: number) {
    this.session.end();

    // console
    console.log('go cursor', cursor);

    const currentCursor = this.session.cursor;
    cursor = +cursor;
    if (cursor < 0) {
      cursor = 0;
    } else if (cursor >= this.records.length) {
      cursor = this.records.length - 1;
    }
    if (cursor === currentCursor) {
      return;
    }
    // console
    console.log('go cursor if elso', cursor);

    const session = this.records[cursor];
    const hotData = session.data;

    this.sleep();
    try {
      this.redoer(this.currentSerialization.unserialize(hotData));
      this.emitter.emit('cursor', hotData);
    } catch (e) /* istanbul ignore next */ {
      console.error(e);
    }

    this.wakeup();
    this.session = session;
    // console
    console.log('this.session', this.session);

    this.emitter.emit('statechange', this.getState());
  }

另:采用如下方案可回退

this.history.back();
    this.history[historySymbol].session =
      this.history[historySymbol].records[
        Math.max(0, this.history[historySymbol].session.cursor - 1)
      ];

但是历史记录在回退之后会清除掉回退的那条,导致一直不可forward。 观测onStageChange发现连续调用两次,第一次records列表正常,第二次cursor后面的记录消失。

    const { cursor } = this.history[historySymbol].session;
    const length = this.history[historySymbol].records.length;
    console.log('setState', cursor, length);

image 上图中,第一个number为cursor位置,第二个number为records长度。

zboMa avatar Aug 30 '22 07:08 zboMa