MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / Backspace

Method Backspace

plugins/Cardinal/src/DearImGuiColorTextEditor/TextEditor.cpp:1820–1896  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1818}
1819
1820void TextEditor::Backspace()
1821{
1822 assert(!mReadOnly);
1823
1824 if (mLines.empty())
1825 return;
1826
1827 UndoRecord u;
1828 u.mBefore = mState;
1829
1830 if (HasSelection())
1831 {
1832 u.mRemoved = GetSelectedText();
1833 u.mRemovedStart = mState.mSelectionStart;
1834 u.mRemovedEnd = mState.mSelectionEnd;
1835
1836 DeleteSelection();
1837 }
1838 else
1839 {
1840 auto pos = GetActualCursorCoordinates();
1841 SetCursorPosition(pos);
1842
1843 if (mState.mCursorPosition.mColumn == 0)
1844 {
1845 if (mState.mCursorPosition.mLine == 0)
1846 return;
1847
1848 u.mRemoved = '\n';
1849 u.mRemovedStart = u.mRemovedEnd = Coordinates(pos.mLine - 1, GetLineMaxColumn(pos.mLine - 1));
1850 Advance(u.mRemovedEnd);
1851
1852 auto& line = mLines[mState.mCursorPosition.mLine];
1853 auto& prevLine = mLines[mState.mCursorPosition.mLine - 1];
1854 auto prevSize = GetLineMaxColumn(mState.mCursorPosition.mLine - 1);
1855 prevLine.insert(prevLine.end(), line.begin(), line.end());
1856
1857 ErrorMarkers etmp;
1858 for (auto& i : mErrorMarkers)
1859 etmp.insert(ErrorMarkers::value_type(i.first - 1 == mState.mCursorPosition.mLine ? i.first - 1 : i.first, i.second));
1860 mErrorMarkers = std::move(etmp);
1861
1862 RemoveLine(mState.mCursorPosition.mLine);
1863 --mState.mCursorPosition.mLine;
1864 mState.mCursorPosition.mColumn = prevSize;
1865 }
1866 else
1867 {
1868 auto& line = mLines[mState.mCursorPosition.mLine];
1869 auto cindex = GetCharacterIndex(pos) - 1;
1870 auto cend = cindex + 1;
1871 while (cindex > 0 && IsUTFSequence(line[cindex].mChar))
1872 --cindex;
1873
1874 //if (cindex > 0 && UTF8CharLength(line[cindex].mChar) > 1)
1875 // --cindex;
1876
1877 u.mRemovedStart = u.mRemovedEnd = GetActualCursorCoordinates();

Callers

nothing calls this directly

Calls 9

HasSelectionFunction · 0.85
CoordinatesClass · 0.85
IsUTFSequenceFunction · 0.85
insertMethod · 0.80
eraseMethod · 0.80
emptyMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected