Page Key Navigation in Disassembly (Fix #167)

This commit is contained in:
Florian Märkl 2017-12-17 15:11:27 +01:00
parent 0abcf20566
commit 6fa0e0d147

View File

@ -454,35 +454,69 @@ void DisassemblyWidget::moveCursorRelative(bool up, bool page)
{ {
if (page) if (page)
{ {
// TODO: implement page up/down RVA offset;
return; if (!up)
{
offset = Core()->nextOpAddr(bottomOffset, 1);
}
else
{
offset = Core()->prevOpAddr(topOffset, maxLines);
// disassembly from calculated offset may have more than maxLines lines
// move some instructions down if necessary.
auto lines = Core()->disassembleLines(offset, maxLines).toVector();
int oldTopLine;
for (oldTopLine=lines.length(); oldTopLine>0; oldTopLine--)
{
if (lines[oldTopLine - 1].offset < topOffset)
{
break;
}
}
int overflowLines = oldTopLine - maxLines;
if(overflowLines > 0)
{
while (lines[overflowLines-1].offset == lines[overflowLines].offset
&& overflowLines < lines.length()-1)
{
overflowLines++;
}
offset = lines[overflowLines].offset;
}
}
refreshDisasm(offset);
} }
else // normal arrow keys
int blockCount = mDisasTextEdit->blockCount();
if (blockCount < 1)
{ {
return; int blockCount = mDisasTextEdit->blockCount();
} if (blockCount < 1)
{
return;
}
int blockNumber = mDisasTextEdit->textCursor().blockNumber(); int blockNumber = mDisasTextEdit->textCursor().blockNumber();
if (blockNumber == blockCount - 1 && !up) if (blockNumber == blockCount - 1 && !up)
{ {
scrollInstructions(1); scrollInstructions(1);
} }
else if (blockNumber == 0 && up) else if (blockNumber == 0 && up)
{ {
scrollInstructions(-1); scrollInstructions(-1);
} }
mDisasTextEdit->moveCursor(up ? QTextCursor::Up : QTextCursor::Down); mDisasTextEdit->moveCursor(up ? QTextCursor::Up : QTextCursor::Down);
// handle cases where top instruction offsets change // handle cases where top instruction offsets change
RVA offset = readCurrentDisassemblyOffset(); RVA offset = readCurrentDisassemblyOffset();
if (offset != Core()->getOffset()) if (offset != Core()->getOffset())
{ {
Core()->seek(offset); Core()->seek(offset);
highlightCurrentLine(); highlightCurrentLine();
}
} }
} }