Skip to content

Commit

Permalink
fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
vision-05 committed Dec 27, 2020
1 parent 56cfdc3 commit 3bfe7f8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
29 changes: 28 additions & 1 deletion src/Core/datatypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ better::Text better::backspace(better::Text text) { //couple of bugs with backsp
immer::flex_vector<char> newLine;

if(text.cursor.column > 0) {
if(text.topColumnNumber == text.cursor.column) {
text.topColumnNumber -= 1;
}
newLine = text.textEdit[text.cursor.row].erase(text.cursor.column - 1); //make case for deleting newline
}
else {
Expand All @@ -47,9 +50,19 @@ better::Text better::backspace(better::Text text) { //couple of bugs with backsp
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
const int textWidth {150};
const int textHeight {60};

std::vector<better::Text> texts {};

bool endOfText {textEdit.cursor.row == textEdit.textEdit.size() - 1 ? true : false};
bool textSizeRightSize {textEdit.textEdit.size() > (textHeight - 1) ? true : false}; //if end of text make sure to not just append a new row
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
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
int prevIndent {better::getPreviousIndentLevel(textEdit, textEdit.cursor.row)};
texts.push_back(newText);
for(int i{}; i < prevIndent; ++i) {
texts.push_back(better::updateText(texts.back(),' '));
}
//create new case for between {},[] and ()
return texts.back();
}

better::charMapArr better::makeCharMapArr(::Uint8 charArray[16]) {
Expand Down Expand Up @@ -81,3 +94,17 @@ Uint8 better::getBlue(Uint32 color) {
Uint8 better::getAlpha(Uint32 color) {
return static_cast<Uint8>(color & 0x000000FF);
}

int better::getPreviousIndentLevel(better::Text text, int row) {
int notSpace {0};
for(int i{}; i < text.textEdit[row].size(); ++i) {
if(text.textEdit[row][i] == ' ') {
notSpace++;
}
else {
break;
}
}
return notSpace;
}

2 changes: 2 additions & 0 deletions src/Core/datatypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Uint8 getGreen(Uint32 color);
Uint8 getBlue(Uint32 color);
Uint8 getAlpha(Uint32 color);

int getPreviousIndentLevel(better::Text text, int row);

}

#endif
6 changes: 2 additions & 4 deletions src/Core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <vector>
#include <string>
#include <unordered_map>
#include <iostream>

#include "datatypes.hpp"
#include "fileUtils.hpp"
Expand Down Expand Up @@ -328,6 +327,7 @@ better::Text better::keyDown(better::Text text, SDL_Event event, SDL_Surface* su
return better::horizontalNav(text, event.key.keysym.scancode, text.data.textHeight, text.data.textWidth);
}
else if(event.key.keysym.scancode == SDL_SCANCODE_RETURN) {
text.highlightStart = text.highlightEnd;
return better::newLine(text);
}

Expand Down Expand Up @@ -417,14 +417,12 @@ better::Text better::handleKey(better::Text text, char key) {
switch(key) {
case '\b':
return better::backspace(text);
case '{':
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);
case '\'':
return better::horizontalNav(better::updateText(better::updateText(text,'\''),'\''),SDL_SCANCODE_LEFT, text.data.textHeight, text.data.textWidth);
case '\"':
return better::horizontalNav(better::updateText(better::updateText(text,key),'\"'),SDL_SCANCODE_LEFT, text.data.textHeight, text.data.textWidth);
default:
if(key == '(' || key == '<' || key == '[') {
if(key == '(' || key == '{' || key == '[') {
return better::autoBracket(text,key);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
main: main.cpp datatypes.cpp fileUtils.cpp renderchars.cpp menubar.cpp
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
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
6 changes: 4 additions & 2 deletions src/Core/renderchars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void better::renderText(SDL_Surface* surface, immer::flex_vector<immer::flex_vec
colSize = topColumn + textWidth;
}
comment = false;
for(int j{topColumn}, otherj{}; j < colSize; ++j, ++otherj) {
for(int j{}, otherj{}; j < colSize; ++j, ++otherj) {
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)))) {
background = colorhighlight;
}
Expand Down Expand Up @@ -202,7 +202,9 @@ void better::renderText(SDL_Surface* surface, immer::flex_vector<immer::flex_vec
else {
foreground = colorfg;
}
better::createLetter(surface, vector[i][j], otherj, otheri, foreground, background); //render text line by line
if(j >= topColumn && j < topColumn + textWidth) {
better::createLetter(surface, vector[i][j], otherj - topColumn, otheri, foreground, background); //render text line by line
}
}
}
}
Expand Down

0 comments on commit 3bfe7f8

Please sign in to comment.