Closed trevrdspcdev closed 2 years ago
There is a bug in the save function where index is incorrectly being used in place of indexInState.
save
index
indexInState
When determining the caretIndex, index is incorrectly used in the state[index].type === 'header' comparison
caretIndex
state[index].type === 'header'
/** * Adds the saved data in the history stack and updates current position. */ save(state) { if (this.position >= this.maxLength) { this.truncate(this.stack, this.maxLength); } this.position = Math.min(this.position, this.stack.length - 1); this.stack = this.stack.slice(0, this.position + 1); const index = this.blocks.getCurrentBlockIndex(); const blockCount = this.blocks.getBlocksCount(); let indexInState = index; if (!state[index]) indexInState -= (blockCount - state.length); const caretIndex = state[indexInState].type === 'paragraph' || state[index].type === 'header' ? this.getCaretIndex(index) : null; this.stack.push({ index: indexInState, state, caretIndex }); this.position += 1; this.onUpdate(); }
When determining the caretIndex, indexInState should be used in both comparisons
/** * Adds the saved data in the history stack and updates current position. */ save(state) { if (this.position >= this.maxLength) { this.truncate(this.stack, this.maxLength); } this.position = Math.min(this.position, this.stack.length - 1); this.stack = this.stack.slice(0, this.position + 1); const index = this.blocks.getCurrentBlockIndex(); const blockCount = this.blocks.getBlocksCount(); let indexInState = index; if (!state[index]) indexInState -= (blockCount - state.length); const caretIndex = state[indexInState].type === 'paragraph' || state[indexInState].type === 'header' ? this.getCaretIndex(index) : null; this.stack.push({ index: indexInState, state, caretIndex }); this.position += 1; this.onUpdate(); }
This issue was solved in the pull request #114.
Precheck
Description
There is a bug in the
save
function whereindex
is incorrectly being used in place ofindexInState
.Environment
Current behavior
When determining the
caretIndex
,index
is incorrectly used in thestate[index].type === 'header'
comparisonExpected behavior
When determining the
caretIndex
,indexInState
should be used in both comparisons