Chapter 5. Expressing Ideas
Just for something to do, I decided to clean up some code. Here’s what happened—not all of it good!
Something to Do
I think I’ll refactor the code a bit, just for something to do. Let’s take a look. Here’s the method that handles Enter:
public void Enter() { int cursorLine = CursorLine(); String[] newlines = new String[lines.Length+2]; for(int i = 0; i <= cursorLine; i++) { newlines[i] = lines[i]; } newlines[cursorLine+1] = ""; newlines[cursorLine+2] = "<P></P>"; for (int i = cursorLine+1; i < lines.Length; i++) { newlines[i+2] = lines[i]; } lines = newlines; selectionStart = NewSelectionStart(cursorLine + 2); }
Here are some of the ideas that went into this code:
Handle the Enter key.
Change the lines table to include a ...
Get Extreme Programming Adventures in C# now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.