Skip to content

Commit 3bfe7f8

Browse files
committed
fixed bugs
1 parent 56cfdc3 commit 3bfe7f8

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

src/Core/datatypes.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ better::Text better::backspace(better::Text text) { //couple of bugs with backsp
2525
immer::flex_vector<char> newLine;
2626

2727
if(text.cursor.column > 0) {
28+
if(text.topColumnNumber == text.cursor.column) {
29+
text.topColumnNumber -= 1;
30+
}
2831
newLine = text.textEdit[text.cursor.row].erase(text.cursor.column - 1); //make case for deleting newline
2932
}
3033
else {
@@ -47,9 +50,19 @@ better::Text better::backspace(better::Text text) { //couple of bugs with backsp
4750
better::Text better::newLine(better::Text textEdit) { //create cases for the following: newline at start of line, newline at end of line, newline in middle of line, newline at end of text
4851
const int textWidth {150};
4952
const int textHeight {60};
53+
54+
std::vector<better::Text> texts {};
55+
5056
bool endOfText {textEdit.cursor.row == textEdit.textEdit.size() - 1 ? true : false};
5157
bool textSizeRightSize {textEdit.textEdit.size() > (textHeight - 1) ? true : false}; //if end of text make sure to not just append a new row
52-
return {endOfText ? textEdit.textEdit.set(textEdit.cursor.row, textEdit.textEdit[textEdit.cursor.row].take(textEdit.cursor.column)).push_back(textEdit.textEdit[textEdit.cursor.row].drop(textEdit.cursor.column)) : textEdit.textEdit.insert(textEdit.cursor.row + 1, textEdit.textEdit[textEdit.cursor.row].drop(textEdit.cursor.column)).set(textEdit.cursor.row, textEdit.textEdit[textEdit.cursor.row].take(textEdit.cursor.column)), {textEdit.cursor.row + 1, 0}, {{false,false,false,false},textEdit.data.isShift,textEdit.data.isCaps,textEdit.data.isScroll,textEdit.data.isCtrl,textEdit.data.clearHistory,-1,textEdit.data.menu,textEdit.data.filename}, endOfText ? (textSizeRightSize ? textEdit.topLineNumber + 1 : 0) : textEdit.topLineNumber, 0, textEdit.highlightStart, textEdit.highlightEnd}; //insert newline unless at bottom
58+
better::Text newText {endOfText ? textEdit.textEdit.set(textEdit.cursor.row, textEdit.textEdit[textEdit.cursor.row].take(textEdit.cursor.column)).push_back(textEdit.textEdit[textEdit.cursor.row].drop(textEdit.cursor.column)) : textEdit.textEdit.insert(textEdit.cursor.row + 1, textEdit.textEdit[textEdit.cursor.row].drop(textEdit.cursor.column)).set(textEdit.cursor.row, textEdit.textEdit[textEdit.cursor.row].take(textEdit.cursor.column)), {textEdit.cursor.row + 1, 0}, {{false,false,false,false},textEdit.data.isShift,textEdit.data.isCaps,textEdit.data.isScroll,textEdit.data.isCtrl,textEdit.data.clearHistory,-1,textEdit.data.menu,textEdit.data.filename}, endOfText ? (textSizeRightSize ? textEdit.topLineNumber + 1 : 0) : textEdit.topLineNumber, 0, textEdit.highlightStart, textEdit.highlightEnd}; //insert newline unless at bottom
59+
int prevIndent {better::getPreviousIndentLevel(textEdit, textEdit.cursor.row)};
60+
texts.push_back(newText);
61+
for(int i{}; i < prevIndent; ++i) {
62+
texts.push_back(better::updateText(texts.back(),' '));
63+
}
64+
//create new case for between {},[] and ()
65+
return texts.back();
5366
}
5467

5568
better::charMapArr better::makeCharMapArr(::Uint8 charArray[16]) {
@@ -81,3 +94,17 @@ Uint8 better::getBlue(Uint32 color) {
8194
Uint8 better::getAlpha(Uint32 color) {
8295
return static_cast<Uint8>(color & 0x000000FF);
8396
}
97+
98+
int better::getPreviousIndentLevel(better::Text text, int row) {
99+
int notSpace {0};
100+
for(int i{}; i < text.textEdit[row].size(); ++i) {
101+
if(text.textEdit[row][i] == ' ') {
102+
notSpace++;
103+
}
104+
else {
105+
break;
106+
}
107+
}
108+
return notSpace;
109+
}
110+

src/Core/datatypes.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Uint8 getGreen(Uint32 color);
5757
Uint8 getBlue(Uint32 color);
5858
Uint8 getAlpha(Uint32 color);
5959

60+
int getPreviousIndentLevel(better::Text text, int row);
61+
6062
}
6163

6264
#endif

src/Core/main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <vector>
99
#include <string>
1010
#include <unordered_map>
11-
#include <iostream>
1211

1312
#include "datatypes.hpp"
1413
#include "fileUtils.hpp"
@@ -328,6 +327,7 @@ better::Text better::keyDown(better::Text text, SDL_Event event, SDL_Surface* su
328327
return better::horizontalNav(text, event.key.keysym.scancode, text.data.textHeight, text.data.textWidth);
329328
}
330329
else if(event.key.keysym.scancode == SDL_SCANCODE_RETURN) {
330+
text.highlightStart = text.highlightEnd;
331331
return better::newLine(text);
332332
}
333333

@@ -417,14 +417,12 @@ better::Text better::handleKey(better::Text text, char key) {
417417
switch(key) {
418418
case '\b':
419419
return better::backspace(text);
420-
case '{':
421-
return better::verticalNav(better::horizontalNav(better::updateText(better::newLine(better::newLine(better::updateText(text,key))),'}'), SDL_SCANCODE_LEFT, text.data.textHeight, text.data.textWidth), SDL_SCANCODE_UP, text.data.textHeight, text.data.textWidth);
422420
case '\'':
423421
return better::horizontalNav(better::updateText(better::updateText(text,'\''),'\''),SDL_SCANCODE_LEFT, text.data.textHeight, text.data.textWidth);
424422
case '\"':
425423
return better::horizontalNav(better::updateText(better::updateText(text,key),'\"'),SDL_SCANCODE_LEFT, text.data.textHeight, text.data.textWidth);
426424
default:
427-
if(key == '(' || key == '<' || key == '[') {
425+
if(key == '(' || key == '{' || key == '[') {
428426
return better::autoBracket(text,key);
429427
}
430428
else {

src/Core/makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
main: main.cpp datatypes.cpp fileUtils.cpp renderchars.cpp menubar.cpp
2-
clang++ -g -O3 -std=c++20 -o BetterCode.exe main.cpp datatypes.cpp fileUtils.cpp renderchars.cpp menubar.cpp -m64 -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/" -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/immer/" -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/immer/detail/rbts/" -lC:/Users/TFran/VisionCode/src/Libs/SDL2main -lC:/Users/TFran/VisionCode/src/Libs/SDL2
2+
clang++ -O3 -std=c++20 -o BetterCode.exe main.cpp datatypes.cpp fileUtils.cpp renderchars.cpp menubar.cpp -m64 -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/" -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/immer/" -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/immer/detail/rbts/" -lC:/Users/TFran/VisionCode/src/Libs/SDL2main -lC:/Users/TFran/VisionCode/src/Libs/SDL2

src/Core/renderchars.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void better::renderText(SDL_Surface* surface, immer::flex_vector<immer::flex_vec
167167
colSize = topColumn + textWidth;
168168
}
169169
comment = false;
170-
for(int j{topColumn}, otherj{}; j < colSize; ++j, ++otherj) {
170+
for(int j{}, otherj{}; j < colSize; ++j, ++otherj) {
171171
if(highlight && ((i >= highlightStart.row && i <= highlightEnd.row) && (j >= highlightStart.column && j <= highlightEnd.column)) || (((highlightEnd.row != highlightStart.row && highlightEnd.column != highlightStart.column)) && ((i == highlightStart.row && j >= highlightStart.column) || (i == highlightEnd.row && j <= highlightEnd.column) || (i < highlightEnd.row && i > highlightStart.row)))) {
172172
background = colorhighlight;
173173
}
@@ -202,7 +202,9 @@ void better::renderText(SDL_Surface* surface, immer::flex_vector<immer::flex_vec
202202
else {
203203
foreground = colorfg;
204204
}
205-
better::createLetter(surface, vector[i][j], otherj, otheri, foreground, background); //render text line by line
205+
if(j >= topColumn && j < topColumn + textWidth) {
206+
better::createLetter(surface, vector[i][j], otherj - topColumn, otheri, foreground, background); //render text line by line
207+
}
206208
}
207209
}
208210
}

0 commit comments

Comments
 (0)