impr: Replace all asserts with IM_ASSERT in the Text Editor (#1979)
All asserts in TextEditor.cpp were replaced with IM_ASSERTs so that if they are hit ImHex won't crash and give a nice popup message instead.
This commit is contained in:
parent
4b8f9984d5
commit
d45e0d1cac
@ -203,8 +203,8 @@ void TextEditor::Advance(Coordinates &aCoordinates) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::DeleteRange(const Coordinates &aStart, const Coordinates &aEnd) {
|
void TextEditor::DeleteRange(const Coordinates &aStart, const Coordinates &aEnd) {
|
||||||
assert(aEnd >= aStart);
|
IM_ASSERT(aEnd >= aStart);
|
||||||
assert(!mReadOnly);
|
IM_ASSERT(!mReadOnly);
|
||||||
|
|
||||||
// printf("D(%d.%d)-(%d.%d)\n", aStart.mLine, aStart.mColumn, aEnd.mLine, aEnd.mColumn);
|
// printf("D(%d.%d)-(%d.%d)\n", aStart.mLine, aStart.mColumn, aEnd.mLine, aEnd.mColumn);
|
||||||
|
|
||||||
@ -293,7 +293,7 @@ int TextEditor::InsertTextAt(Coordinates & /* inout */ aWhere, const char *aValu
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::AddUndo(UndoRecord &aValue) {
|
void TextEditor::AddUndo(UndoRecord &aValue) {
|
||||||
assert(!mReadOnly);
|
IM_ASSERT(!mReadOnly);
|
||||||
// printf("AddUndo: (@%d.%d) +\'%s' [%d.%d .. %d.%d], -\'%s', [%d.%d .. %d.%d] (@%d.%d)\n",
|
// printf("AddUndo: (@%d.%d) +\'%s' [%d.%d .. %d.%d], -\'%s', [%d.%d .. %d.%d] (@%d.%d)\n",
|
||||||
// aValue.mBefore.mCursorPosition.mLine, aValue.mBefore.mCursorPosition.mColumn,
|
// aValue.mBefore.mCursorPosition.mLine, aValue.mBefore.mCursorPosition.mColumn,
|
||||||
// aValue.mAdded.c_str(), aValue.mAddedStart.mLine, aValue.mAddedStart.mColumn, aValue.mAddedEnd.mLine, aValue.mAddedEnd.mColumn,
|
// aValue.mAdded.c_str(), aValue.mAddedStart.mLine, aValue.mAddedStart.mColumn, aValue.mAddedEnd.mLine, aValue.mAddedEnd.mColumn,
|
||||||
@ -581,8 +581,8 @@ bool TextEditor::IsOnWordBoundary(const Coordinates &aAt) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::RemoveLine(int aStart, int aEnd) {
|
void TextEditor::RemoveLine(int aStart, int aEnd) {
|
||||||
assert(!mReadOnly);
|
IM_ASSERT(!mReadOnly);
|
||||||
assert(aEnd >= aStart);
|
IM_ASSERT(aEnd >= aStart);
|
||||||
|
|
||||||
ErrorMarkers etmp;
|
ErrorMarkers etmp;
|
||||||
for (auto &i : mErrorMarkers) {
|
for (auto &i : mErrorMarkers) {
|
||||||
@ -614,8 +614,8 @@ void TextEditor::RemoveLine(int aStart, int aEnd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::RemoveLine(int aIndex) {
|
void TextEditor::RemoveLine(int aIndex) {
|
||||||
assert(!mReadOnly);
|
IM_ASSERT(!mReadOnly);
|
||||||
assert(mLines.size() > 1);
|
IM_ASSERT(mLines.size() > 1);
|
||||||
|
|
||||||
ErrorMarkers etmp;
|
ErrorMarkers etmp;
|
||||||
for (auto &i : mErrorMarkers) {
|
for (auto &i : mErrorMarkers) {
|
||||||
@ -638,7 +638,7 @@ void TextEditor::RemoveLine(int aIndex) {
|
|||||||
mBreakpoints = std::move(btmp);
|
mBreakpoints = std::move(btmp);
|
||||||
|
|
||||||
mLines.erase(mLines.begin() + aIndex);
|
mLines.erase(mLines.begin() + aIndex);
|
||||||
assert(!mLines.empty());
|
IM_ASSERT(!mLines.empty());
|
||||||
|
|
||||||
mTextChanged = true;
|
mTextChanged = true;
|
||||||
}
|
}
|
||||||
@ -844,7 +844,7 @@ void TextEditor::Render() {
|
|||||||
mPalette[i] = ImGui::ColorConvertFloat4ToU32(color);
|
mPalette[i] = ImGui::ColorConvertFloat4ToU32(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(mLineBuffer.empty());
|
IM_ASSERT(mLineBuffer.empty());
|
||||||
|
|
||||||
auto contentSize = ImGui::GetCurrentWindowRead()->ContentRegionRect.Max - ImGui::GetWindowPos() - ImVec2(0,mTopMargin);
|
auto contentSize = ImGui::GetCurrentWindowRead()->ContentRegionRect.Max - ImGui::GetWindowPos() - ImVec2(0,mTopMargin);
|
||||||
auto drawList = ImGui::GetWindowDrawList();
|
auto drawList = ImGui::GetWindowDrawList();
|
||||||
@ -894,7 +894,7 @@ void TextEditor::Render() {
|
|||||||
float sstart = -1.0f;
|
float sstart = -1.0f;
|
||||||
float ssend = -1.0f;
|
float ssend = -1.0f;
|
||||||
|
|
||||||
assert(mState.mSelectionStart <= mState.mSelectionEnd);
|
IM_ASSERT(mState.mSelectionStart <= mState.mSelectionEnd);
|
||||||
if (mState.mSelectionStart <= lineEndCoord)
|
if (mState.mSelectionStart <= lineEndCoord)
|
||||||
sstart = mState.mSelectionStart > lineStartCoord ? TextDistanceToLineStart(mState.mSelectionStart) : 0.0f;
|
sstart = mState.mSelectionStart > lineStartCoord ? TextDistanceToLineStart(mState.mSelectionStart) : 0.0f;
|
||||||
if (mState.mSelectionEnd > lineStartCoord)
|
if (mState.mSelectionEnd > lineStartCoord)
|
||||||
@ -1235,7 +1235,7 @@ void TextEditor::SetTextLines(const std::vector<std::string> &aLines) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::EnterCharacter(ImWchar aChar, bool aShift) {
|
void TextEditor::EnterCharacter(ImWchar aChar, bool aShift) {
|
||||||
assert(!mReadOnly);
|
IM_ASSERT(!mReadOnly);
|
||||||
|
|
||||||
UndoRecord u;
|
UndoRecord u;
|
||||||
|
|
||||||
@ -1522,7 +1522,7 @@ void TextEditor::InsertText(const char *aValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::DeleteSelection() {
|
void TextEditor::DeleteSelection() {
|
||||||
assert(mState.mSelectionEnd >= mState.mSelectionStart);
|
IM_ASSERT(mState.mSelectionEnd >= mState.mSelectionStart);
|
||||||
|
|
||||||
if (mState.mSelectionEnd == mState.mSelectionStart)
|
if (mState.mSelectionEnd == mState.mSelectionStart)
|
||||||
return;
|
return;
|
||||||
@ -1562,7 +1562,7 @@ void TextEditor::MoveUp(int aAmount, bool aSelect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::MoveDown(int aAmount, bool aSelect) {
|
void TextEditor::MoveDown(int aAmount, bool aSelect) {
|
||||||
assert(mState.mCursorPosition.mColumn >= 0);
|
IM_ASSERT(mState.mCursorPosition.mColumn >= 0);
|
||||||
ResetCursorBlinkTime();
|
ResetCursorBlinkTime();
|
||||||
auto oldPos = mState.mCursorPosition;
|
auto oldPos = mState.mCursorPosition;
|
||||||
mState.mCursorPosition.mLine = std::max(0, std::min((int)mLines.size() - 1, mState.mCursorPosition.mLine + aAmount));
|
mState.mCursorPosition.mLine = std::max(0, std::min((int)mLines.size() - 1, mState.mCursorPosition.mLine + aAmount));
|
||||||
@ -1629,7 +1629,7 @@ void TextEditor::MoveLeft(int aAmount, bool aSelect, bool aWordMode) {
|
|||||||
|
|
||||||
mState.mCursorPosition = Coordinates(lindex, GetCharacterColumn(lindex, cindex));
|
mState.mCursorPosition = Coordinates(lindex, GetCharacterColumn(lindex, cindex));
|
||||||
|
|
||||||
assert(mState.mCursorPosition.mColumn >= 0);
|
IM_ASSERT(mState.mCursorPosition.mColumn >= 0);
|
||||||
if (aSelect) {
|
if (aSelect) {
|
||||||
if (oldPos == mInteractiveStart)
|
if (oldPos == mInteractiveStart)
|
||||||
mInteractiveStart = mState.mCursorPosition;
|
mInteractiveStart = mState.mCursorPosition;
|
||||||
@ -1685,7 +1685,7 @@ void TextEditor::MoveRight(int aAmount, bool aSelect, bool aWordMode) {
|
|||||||
|
|
||||||
mState.mCursorPosition = Coordinates(lindex, GetCharacterColumn(lindex, cindex));
|
mState.mCursorPosition = Coordinates(lindex, GetCharacterColumn(lindex, cindex));
|
||||||
|
|
||||||
assert(mState.mCursorPosition.mColumn >= 0);
|
IM_ASSERT(mState.mCursorPosition.mColumn >= 0);
|
||||||
if (aSelect) {
|
if (aSelect) {
|
||||||
if (oldPos == mInteractiveEnd)
|
if (oldPos == mInteractiveEnd)
|
||||||
mInteractiveEnd = SanitizeCoordinates(mState.mCursorPosition);
|
mInteractiveEnd = SanitizeCoordinates(mState.mCursorPosition);
|
||||||
@ -1774,7 +1774,7 @@ void TextEditor::MoveEnd(bool aSelect) {
|
|||||||
|
|
||||||
void TextEditor::Delete() {
|
void TextEditor::Delete() {
|
||||||
ResetCursorBlinkTime();
|
ResetCursorBlinkTime();
|
||||||
assert(!mReadOnly);
|
IM_ASSERT(!mReadOnly);
|
||||||
|
|
||||||
if (isEmpty())
|
if (isEmpty())
|
||||||
return;
|
return;
|
||||||
@ -1831,7 +1831,7 @@ void TextEditor::Delete() {
|
|||||||
|
|
||||||
void TextEditor::Backspace() {
|
void TextEditor::Backspace() {
|
||||||
ResetCursorBlinkTime();
|
ResetCursorBlinkTime();
|
||||||
assert(!mReadOnly);
|
IM_ASSERT(!mReadOnly);
|
||||||
|
|
||||||
if (isEmpty())
|
if (isEmpty())
|
||||||
return;
|
return;
|
||||||
@ -2016,7 +2016,7 @@ void TextEditor::Redo(int aSteps) {
|
|||||||
|
|
||||||
// the index here is array index so zero based
|
// the index here is array index so zero based
|
||||||
void TextEditor::FindReplaceHandler::SelectFound(TextEditor *editor, int index) {
|
void TextEditor::FindReplaceHandler::SelectFound(TextEditor *editor, int index) {
|
||||||
assert(index >= 0 && index < mMatches.size());
|
IM_ASSERT(index >= 0 && index < mMatches.size());
|
||||||
auto selectionStart = mMatches[index].mSelectionStart;
|
auto selectionStart = mMatches[index].mSelectionStart;
|
||||||
auto selectionEnd = mMatches[index].mSelectionEnd;
|
auto selectionEnd = mMatches[index].mSelectionEnd;
|
||||||
editor->SetSelection(selectionStart, selectionEnd);
|
editor->SetSelection(selectionStart, selectionEnd);
|
||||||
@ -2868,8 +2868,8 @@ TextEditor::UndoRecord::UndoRecord(
|
|||||||
TextEditor::EditorState &aBefore,
|
TextEditor::EditorState &aBefore,
|
||||||
TextEditor::EditorState &aAfter)
|
TextEditor::EditorState &aAfter)
|
||||||
: mAdded(aAdded), mAddedStart(aAddedStart), mAddedEnd(aAddedEnd), mRemoved(aRemoved), mRemovedStart(aRemovedStart), mRemovedEnd(aRemovedEnd), mBefore(aBefore), mAfter(aAfter) {
|
: mAdded(aAdded), mAddedStart(aAddedStart), mAddedEnd(aAddedEnd), mRemoved(aRemoved), mRemovedStart(aRemovedStart), mRemovedEnd(aRemovedEnd), mBefore(aBefore), mAfter(aAfter) {
|
||||||
assert(mAddedStart <= mAddedEnd);
|
IM_ASSERT(mAddedStart <= mAddedEnd);
|
||||||
assert(mRemovedStart <= mRemovedEnd);
|
IM_ASSERT(mRemovedStart <= mRemovedEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::UndoRecord::Undo(TextEditor *aEditor) {
|
void TextEditor::UndoRecord::Undo(TextEditor *aEditor) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user