|
|
I am writing a text editor for a homework assignment, but am struggling with two functions. I need to be able to delete a character to the left of the cursor and then the rest of characters move to the left to fill in the space, just like a regular delete key. I cannot get the rest of the row of characters over. I also need to delete the character to the right of the cursor, and then move the other characters over. For example, the cursor is in between the two 'd's:
abcdde - I delete the first 'd' with the delete key- and am left with - abcde (my program does NOT do this)
abcdde - I delete the second 'd' with ctrl-x - and am left with - abcde (my program does NOT do this either)
Here is the code for these functions:
case 0x08: // delete char to the left of the cursor ^h
case 0x7f: // 'delete' key
if(screenArray[currentRow][currentCol] != (char) 0x00) {
screenControl.cursorLeft(w);
currentCol--;
for(int i=currentCol; i<columns-1; i++)
{
screenArray[currentRow][i] = screenArray[currentRow][i+1];
w.write(screenArray[currentRow][i]); w.flush();
}
screenControl.cursorLeft(w);
} else {
screenControl.cursorLeft(w);
w.write(0x20); w.flush();
screenControl.cursorLeft(w);
currentCol--;
screenArray[currentRow][currentCol] = (char) 0x20;
}
break;
case 0x18: //delete char to the right of the cursor ^x
screenControl.cursorRight(w);
w.write(0x20);w.flush();
screenControl.cursorLeft(w);
currentCol++;
screenArray[currentRow][currentCol] = (char) 0x20;
break;I haven't tried to move any characters with the ctrl-x function because I can't get the other one to work. Right now, ctrl-x erases the character to the right of the cursor and leaves a space. Ctrl-h & 'delete' work if there is no characters to the right of the character to delete. i.e. I can have 'abcdee' and delete the last 'e' with no problems.
Please help me asap! I have been struggling with this for HOURS! Thank you so much. I hope this explains it well enough. Let me know if you have any questions. Thanks so much!