|
|
|
@ -4,41 +4,116 @@ import './styles/assembly-items.css' |
|
|
|
|
|
|
|
|
|
export const AssemblyItems = ({ registerEvent }) => { |
|
|
|
|
const [assemblyItems, dispatch] = useReducer(reducer, initialState) |
|
|
|
|
const [absoluteSelectedIndex, setAbsoluteSelectedIndex] = useState(0) |
|
|
|
|
const [selectedItem, setSelectedItem] = useState(0) |
|
|
|
|
const [nextSelectedItem, setNextSelectedItem] = useState(1) |
|
|
|
|
const [returnInstructionIndexes, setReturnInstructionIndexes] = useState([]) |
|
|
|
|
const [outOfGasInstructionIndexes, setOutOfGasInstructionIndexes] = useState([]) |
|
|
|
|
const refs = useRef({}) |
|
|
|
|
const asmItemsRef = useRef(null) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
registerEvent && registerEvent('codeManagerChanged', (code, address, index) => { |
|
|
|
|
dispatch({ type: 'FETCH_OPCODES_SUCCESS', payload: { code, address, index } }) |
|
|
|
|
registerEvent && registerEvent('codeManagerChanged', (code, address, index, nextIndex, returnInstructionIndexes, outOfGasInstructionIndexes) => { |
|
|
|
|
dispatch({ type: 'FETCH_OPCODES_SUCCESS', payload: { code, address, index, nextIndex, returnInstructionIndexes, outOfGasInstructionIndexes } }) |
|
|
|
|
}) |
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (selectedItem !== assemblyItems.index) { |
|
|
|
|
if (absoluteSelectedIndex !== assemblyItems.index) { |
|
|
|
|
clearItems() |
|
|
|
|
indexChanged(assemblyItems.index) |
|
|
|
|
nextIndexChanged(assemblyItems.nextIndex) |
|
|
|
|
returnIndexes(assemblyItems.returnInstructionIndexes) |
|
|
|
|
outOfGasIndexes(assemblyItems.outOfGasInstructionIndexes) |
|
|
|
|
} |
|
|
|
|
}, [assemblyItems.index]) |
|
|
|
|
|
|
|
|
|
const indexChanged = (index: number) => { |
|
|
|
|
if (index < 0) return |
|
|
|
|
let currentItem = refs.current[selectedItem] ? refs.current[selectedItem] : null |
|
|
|
|
}, [assemblyItems.opCodes.index]) |
|
|
|
|
|
|
|
|
|
const clearItem = (currentItem) => { |
|
|
|
|
if (currentItem) { |
|
|
|
|
currentItem.removeAttribute('selected') |
|
|
|
|
currentItem.removeAttribute('style') |
|
|
|
|
if (currentItem.firstChild) { |
|
|
|
|
currentItem.firstChild.removeAttribute('style') |
|
|
|
|
} |
|
|
|
|
const codeView = asmItemsRef.current |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const clearItems = () => { |
|
|
|
|
clearItem(refs.current[selectedItem] ? refs.current[selectedItem] : null) |
|
|
|
|
clearItem(refs.current[nextSelectedItem] ? refs.current[nextSelectedItem] : null) |
|
|
|
|
|
|
|
|
|
returnInstructionIndexes.map((index) => { |
|
|
|
|
if (index < 0) return |
|
|
|
|
clearItem(refs.current[index] ? refs.current[index] : null) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
outOfGasInstructionIndexes.map((index) => { |
|
|
|
|
if (index < 0) return |
|
|
|
|
clearItem(refs.current[index] ? refs.current[index] : null) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const indexChanged = (index: number) => { |
|
|
|
|
if (index < 0) return |
|
|
|
|
|
|
|
|
|
currentItem = codeView.children[index] |
|
|
|
|
currentItem.style.setProperty('border-color', 'var(--primary)') |
|
|
|
|
currentItem.style.setProperty('border-style', 'solid') |
|
|
|
|
const codeView = asmItemsRef.current |
|
|
|
|
|
|
|
|
|
const currentItem = codeView.children[index] |
|
|
|
|
if (currentItem) { |
|
|
|
|
currentItem.style.setProperty('background-color', 'var(--primary)') |
|
|
|
|
currentItem.style.setProperty('color', 'var(--light)') |
|
|
|
|
currentItem.setAttribute('selected', 'selected') |
|
|
|
|
codeView.scrollTop = currentItem.offsetTop - parseInt(codeView.offsetTop) |
|
|
|
|
setSelectedItem(index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setSelectedItem(index) |
|
|
|
|
setAbsoluteSelectedIndex(assemblyItems.opCodes.index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const nextIndexChanged = (index: number) => { |
|
|
|
|
if (index < 0) return |
|
|
|
|
|
|
|
|
|
const codeView = asmItemsRef.current |
|
|
|
|
|
|
|
|
|
const currentItem = codeView.children[index] |
|
|
|
|
if (currentItem) { |
|
|
|
|
currentItem.style.setProperty('border-color', 'var(--secondary)') |
|
|
|
|
currentItem.style.setProperty('border-style', 'dotted') |
|
|
|
|
currentItem.setAttribute('selected', 'selected') |
|
|
|
|
} |
|
|
|
|
setNextSelectedItem(index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const returnIndexes = (indexes) => { |
|
|
|
|
indexes.map((index) => { |
|
|
|
|
if (index < 0) return |
|
|
|
|
|
|
|
|
|
const codeView = asmItemsRef.current |
|
|
|
|
|
|
|
|
|
const currentItem = codeView.children[index] |
|
|
|
|
if (currentItem) { |
|
|
|
|
currentItem.style.setProperty('border-color', 'var(--warning)') |
|
|
|
|
currentItem.style.setProperty('border-style', 'dotted') |
|
|
|
|
currentItem.setAttribute('selected', 'selected') |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
setReturnInstructionIndexes(indexes) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const outOfGasIndexes = (indexes) => { |
|
|
|
|
indexes.map((index) => { |
|
|
|
|
if (index < 0) return |
|
|
|
|
|
|
|
|
|
const codeView = asmItemsRef.current |
|
|
|
|
|
|
|
|
|
const currentItem = codeView.children[index] |
|
|
|
|
if (currentItem) { |
|
|
|
|
currentItem.style.setProperty('border-color', 'var(--danger)') |
|
|
|
|
currentItem.style.setProperty('border-style', 'dotted') |
|
|
|
|
currentItem.setAttribute('selected', 'selected') |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
setOutOfGasInstructionIndexes(indexes) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|