Add delete key functionality .Fix Backspace line erase bug.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2, Sig, Sigo 2 years ago
parent b5c57870ba
commit 3c134a917f
  1. BIN
      C++ProjectTemplate.wasm
  2. 12
      main.cpp

Binary file not shown.

@ -110,12 +110,22 @@ public:
void GetAnyKeyPress(olc::Key k)override{ void GetAnyKeyPress(olc::Key k)override{
lastBlinkTime=0.5f; lastBlinkTime=0.5f;
if (k==DEL){
if (cursors[0].pos==document[cursors[0].line].size()){
if (cursors[0].line<document.size()-1){
document[cursors[0].line].append(document[cursors[0].line+1]);
document.erase(document.begin()+cursors[0].line+1);
}
} else {
document[cursors[0].line].erase(cursors[0].pos,1);
}
} else
if (k==BACK){ if (k==BACK){
if (cursors[0].pos==0){ if (cursors[0].pos==0){
if (cursors[0].line>0){ if (cursors[0].line>0){
cursors[0].pos=document[cursors[0].line-1].size(); cursors[0].pos=document[cursors[0].line-1].size();
document[cursors[0].line-1].append(document[cursors[0].line]); document[cursors[0].line-1].append(document[cursors[0].line]);
document[cursors[0].line--].clear(); document.erase(document.begin()+cursors[0].line--);
} }
} else { } else {
document[cursors[0].line].erase(cursors[0].pos---1,1); document[cursors[0].line].erase(cursors[0].pos---1,1);

Loading…
Cancel
Save