Skip to content

Commit

Permalink
fixed newline bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
vision-05 committed Dec 28, 2020
1 parent 3bfe7f8 commit aaca33e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/Core/datatypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! This file contains all of the user defined structs used throughout the project
//constexpr for textheight and textwidth, edit conditionals, get rid of ternaries
#include "datatypes.hpp"
#include <iostream>

better::Text better::updateText(better::Text textEdit, char newChar) {
const int textHeight {60};
Expand Down Expand Up @@ -55,6 +54,7 @@ better::Text better::newLine(better::Text textEdit) { //create cases for the fol

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

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);
Expand Down Expand Up @@ -105,6 +105,9 @@ int better::getPreviousIndentLevel(better::Text text, int row) {
break;
}
}
return notSpace;
return notSpace;
}

better::Text better::tab(better::Text text) {
return better::updateText(better::updateText(better::updateText(better::updateText(text,' '),' '),' '),' ');
}
9 changes: 9 additions & 0 deletions src/Core/datatypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

namespace better {

constexpr int textWidth() {
return 150;
}

constexpr int textHeight() {
return 60;
}

struct Cursor { //store the line number and column number of the cursor
int row;
int column;
Expand Down Expand Up @@ -51,6 +59,7 @@ better::charMapArr makeCharMapArr(::Uint8 charArray[16]);
better::Text updateText(better::Text textEdit, char newChar);
better::Text backspace(better::Text textEdit);
better::Text newLine(better::Text textEdit);
better::Text tab(better::Text text);

Uint8 getRed(Uint32 color);
Uint8 getGreen(Uint32 color);
Expand Down
1 change: 0 additions & 1 deletion src/Core/fileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! This file handles all of the file stream functionality of the program

#include "fileUtils.hpp"
#include <iostream>

int better::saveFile(immer::flex_vector<immer::flex_vector<char>> contents, std::string filename) {
std::string buffer {""};
Expand Down
30 changes: 20 additions & 10 deletions src/Core/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//! This is the main file of the project, containing the main event loop and renderer

#define SDL_MAIN_HANDLED //done prereleaase
#define SDL_MAIN_HANDLED //reformat code and fix highlighting bugs!!!
//create constexpr for columnwidth and columnheight
#include <SDL2-2.0.12/include/SDL.h>
#include <immer-0.6.2/immer/flex_vector.hpp>
Expand Down Expand Up @@ -46,8 +46,6 @@ char unshiftLetter(char key);
//! better::edit1 initialises a text editor the size of the window passed by its pointer.
//! It also reads in the file into its own text buffer, and contains the event loop for that text edit.

better::Text tab(better::Text text);

better::Text mouseMotion(better::Text text, SDL_Event event, SDL_Surface* surface, SDL_Cursor* guiCursor);

better::Text keyDown(better::Text text, SDL_Event event, SDL_Surface* surface, SDL_Cursor* guiCursor);
Expand Down Expand Up @@ -84,7 +82,7 @@ bool operator!=(better::Text lhs, better::Text rhs);

}

int main(int argc, char* argv[]) {
int WinMain(int argc, char* argv[]) {
SDL_SetMainReady();
SDL_Init(SDL_INIT_VIDEO);

Expand Down Expand Up @@ -328,7 +326,23 @@ better::Text better::keyDown(better::Text text, SDL_Event event, SDL_Surface* su
}
else if(event.key.keysym.scancode == SDL_SCANCODE_RETURN) {
text.highlightStart = text.highlightEnd;
return better::newLine(text);
std::vector<better::Text> texts {text}; //fix scrolling here for newline near bottom of text

if((text.cursor.column - 1 > -1) && ((text.textEdit[text.cursor.row][text.cursor.column - 1] == '{' && text.textEdit[text.cursor.row][text.cursor.column] == '}') || (text.textEdit[text.cursor.row][text.cursor.column - 1] == '(' && text.textEdit[text.cursor.row][text.cursor.column] == ')'))) {
if(texts.back().cursor.row != texts.back().textEdit.size() - 1 && texts.back().cursor.row >= texts.back().topLineNumber + better::textHeight() - 2) {
texts.back().topLineNumber += 3;
}
texts.push_back(better::newLine(better::newLine(texts.back())));
texts.push_back(better::verticalNav(texts.back(),SDL_SCANCODE_UP, better::textHeight(), better::textWidth()));
texts.push_back(better::tab(texts.back()));
}
else {
if(texts.back().cursor.row != texts.back().textEdit.size() - 1 && texts.back().cursor.row >= texts.back().topLineNumber + better::textHeight() - 2) {
texts.back().topLineNumber += 1;
}
texts.push_back(better::newLine(texts.back()));
}
return texts.back();
}

else if(event.key.keysym.scancode == SDL_SCANCODE_TAB) {
Expand Down Expand Up @@ -358,7 +372,7 @@ better::Text better::keyDown(better::Text text, SDL_Event event, SDL_Surface* su
if(text.data.isCaps) {
key = better::shiftLetter(key);
}
if(text.data.isScroll) {
if(text.data.isScroll) { //change this
text.topLineNumber = text.cursor.row;
text.topColumnNumber = 0;
}
Expand Down Expand Up @@ -535,10 +549,6 @@ better::Text better::mouseMotion(better::Text text, SDL_Event event, SDL_Surface
return text;
}

better::Text better::tab(better::Text text) {
return better::updateText(better::updateText(better::updateText(better::updateText(text,' '),' '),' '),' ');
}

void better::quitApp(SDL_Cursor* cursor, SDL_Surface* surface, SDL_Window* window) {
SDL_FreeCursor(cursor);
SDL_FreeSurface(surface);
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++ -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 -mwindows -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

0 comments on commit aaca33e

Please sign in to comment.