diff --git a/src/util/utils.js b/src/util/utils.js index b2e6176d62..84ff308798 100644 --- a/src/util/utils.js +++ b/src/util/utils.js @@ -2168,14 +2168,37 @@ Entry.Utils.stopProjectWithToast = _throttle( if (scope.block && 'funcBlock' in scope.block) { block = scope.block.funcBlock; } else if (scope.funcExecutor) { - block = scope.funcExecutor.scope.block; - Entry.Func.edit(scope.type); + const errorBlock = scope.funcExecutor.scope.block; + const errorBlockId = errorBlock && errorBlock.id; + const funcId = (/(func_)?(.*)/.exec(scope.type) || [])[2]; + + // 한 번 실행에서 서로 다른 블록의 런타임 에러가 여러 번 올라올 수 있다. + // 그때마다 Entry.Func.edit 을 다시 호출하면 cancelEdit → initEditView 로 + // 함수 보드가 재렌더되어 앞서 붙인 하이라이트가 지워진다. 마지막 호출이 + // 하이라이트를 복구하지 못하면 경고만 남고 테두리는 사라진다. + // 이미 같은 함수를 편집 중이면 다시 열지 않는다. + const isEditingSameFunc = + Entry.Func.isEdit && + Entry.Func.targetFunc && + Entry.Func.targetFunc.id === funcId; + + if (!isEditingSameFunc) { + Entry.Func.edit(scope.type); + } + + // edit 가 실행된 경우 Block 인스턴스가 교체될 수 있으므로 id 로 다시 찾는다. + const func = funcId && Entry.variableContainer.getFunction(funcId); + const reloadedBlock = + errorBlockId && func && func.content && func.content.findById(errorBlockId); + + block = reloadedBlock || errorBlock; } if (block) { - const id = block.getCode().object && block.getCode().object.id; + const code = block.getCode(); + const id = code && code.object && code.object.id; if (id) { - Entry.container.selectObject(block.getCode().object.id, true); + Entry.container.selectObject(id, true); } const view = block.view; view && view.getBoard().activateBlock(block);