diff --git a/Text Editor 0.8.c b/Text Editor 0.9.c similarity index 90% rename from Text Editor 0.8.c rename to Text Editor 0.9.c index 2bc8149..34a8ce5 100644 --- a/Text Editor 0.8.c +++ b/Text Editor 0.9.c @@ -173,6 +173,11 @@ int FindMatch(int r, int c1, char ch) { continue; } + if(ch == '"' && content[r][c-1] == '\\' + && c-2 >= 0 && content[r][c-2] != '\\')//判断"\""和"\\" + { + continue; + } return c; } } @@ -181,7 +186,7 @@ int FindMatch(int r, int c1, char ch) int FindReservedWord(int r1, int c1) { - static char* word[36] = { + static char* word[48] = { // C语言33关键字 "auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", @@ -190,11 +195,15 @@ int FindReservedWord(int r1, int c1) "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while", - // 常见关键字增补3 - "bool", "false", "true" + // 常见C++关键字增补11 + "bool", "class", "delete", "false", "namespace", + "new", "private", "public", "this", "true", + "using", + // 常见Python关键字增补4 + "def", "from", "import", "in" }; int i, j; - for(i=0; i<36; i++)//在所有关键字中比较 + for(i=0; i<48; i++)//在所有关键字中比较 { for(j=0; word[i][j]!=0; j++) { @@ -526,6 +535,19 @@ int TabBefore(int r, int c1) return num; } +int NegBefore(int r, int c1) +{ + int c, num = 0; + for(c=0; c= 32 && content[r][c] <= 126) putchar(content[r][c]); + else + { + putchar(content[r][c]); + putchar(content[r][c+1]); + putchar(content[r][c+2]); + printf("[%d %d %d]", content[r][c], content[r][c+1], content[r][c+2]); + c+=2; + } } printf("\n"); } @@ -705,7 +738,7 @@ void ReadContent(char* fileName) content =(char**) calloc(numberOfRow, sizeof(char*)); numberOfColumn =(int*) calloc(numberOfRow, sizeof(int)); content[0] =(char*) calloc(1, sizeof(char)); - content[0][0] = '\n'; + content[0][0] = EOF; numberOfColumn[0] = 1; } fclose(file); @@ -717,7 +750,7 @@ void WriteContent(char* fileName) int r, c; for(r=0; r numberOfRow-1) cursorR = numberOfRow-1; - cursorC = mousePos.X-3*TabBefore(cursorR, mousePos.X)-Place(numberOfRow)-1; - while(cursorC+3*TabBefore(cursorR, cursorC)+Place(numberOfRow)+1 < mousePos.X) cursorC++; + cursorC = mousePos.X-3*TabBefore(cursorR, mousePos.X)-Place(numberOfRow)-1+NegBefore(cursorR, cursorC)/3; + while(cursorC+3*TabBefore(cursorR, cursorC)+Place(numberOfRow)+1-NegBefore(cursorR, cursorC)/3 < mousePos.X) cursorC++; + while(NegBefore(cursorR, cursorC)%3 != 0 && content[cursorR][cursorC] < 0) cursorC++; if(cursorC > numberOfColumn[cursorR]-1) cursorC = numberOfColumn[cursorR]-1; PrintGutter(cursorR, 1); - gotoxy(cursorC+3*TabBefore(cursorR, cursorC)+Place(numberOfRow)+1, cursorR); + gotoxy(cursorC+3*TabBefore(cursorR, cursorC)+Place(numberOfRow)+1-NegBefore(cursorR, cursorC)/3, cursorR); } if(rcd.Event.MouseEvent.dwEventFlags == MOUSE_WHEELED) { @@ -898,16 +935,17 @@ int EditContent() if(rcd.Event.MouseEvent.dwButtonState/0x10000 == 0xff88)//4287102976滚轮向下 { if(cursorR+3 < numberOfRow) cursorR += 3; - else if(cursorR+1 < numberOfRow) cursorR++; + else if(cursorR < numberOfRow-1) cursorR = numberOfRow-1; } else if(rcd.Event.MouseEvent.dwButtonState/0x10000 == 0x78)//7864320滚轮向上 { if(cursorR-3 >= 0) cursorR -= 3; - else if(cursorR > 0) cursorR--; + else if(cursorR > 0) cursorR = 0; } + while(NegBefore(cursorR, cursorC)%3 != 0 && content[cursorR][cursorC] < 0) cursorC++; if(cursorC > numberOfColumn[cursorR]-1) cursorC = numberOfColumn[cursorR]-1; PrintGutter(cursorR, 1); - gotoxy(cursorC+3*TabBefore(cursorR, cursorC)+Place(numberOfRow)+1, cursorR); + gotoxy(cursorC+3*TabBefore(cursorR, cursorC)+Place(numberOfRow)+1-NegBefore(cursorR, cursorC)/3, cursorR); } } else if(rcd.EventType == KEY_EVENT && rcd.Event.KeyEvent.bKeyDown == 1) @@ -923,7 +961,11 @@ int EditContent() } else if(operation == VK_LEFT) { - if(cursorC > 0) cursorC--; + if(cursorC > 0) + { + if(content[cursorR][cursorC-1] < 0 && cursorC > 2) cursorC -= 3; + else cursorC--; + } else if(cursorR > 0)//行首左移尝试上一行 { cursorR--; @@ -944,8 +986,9 @@ int EditContent() cursorC = 0; } } + while(NegBefore(cursorR, cursorC)%3 != 0 && content[cursorR][cursorC] < 0) cursorC++; PrintGutter(cursorR, 1); - gotoxy(cursorC+3*TabBefore(cursorR, cursorC)+Place(numberOfRow)+1, cursorR); + gotoxy(cursorC+3*TabBefore(cursorR, cursorC)+Place(numberOfRow)+1-NegBefore(cursorR, cursorC)/3, cursorR); continue; } if(operation == VK_CAPITAL) @@ -1043,17 +1086,20 @@ int EditContent() } if(operation == '\r') { - if(cursorC > 0 && content[cursorR][cursorC-1] == '{' && content[cursorR][cursorC] == '}') + if(cursorC > 0 && content[cursorR][cursorC-1] == '{') { tab = TabBefore(cursorR, cursorC); Operate('\r'); - Operate('\r'); - for(c=0; c 2 + && content[cursorR][cursorC-1] < 0 + && content[cursorR][cursorC-2] < 0 + && content[cursorR][cursorC-3] < 0) + { + Operate('\b'); + Operate('\b'); + Operate('\b');//UTF-8中文删除时连续删除3字符 + Operate(' ');//空格去残影 + PrintContentR(cursorR); + } } return Operate(operation); } @@ -1138,13 +1195,13 @@ int main() SetConsoleMouseMode(1); while(1) { + //getchar(); + f = EditContent(); for(r=0; r