Skip to content

Commit aaca33e

Browse files
committed
fixed newline bugs
1 parent 3bfe7f8 commit aaca33e

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

src/Core/datatypes.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! This file contains all of the user defined structs used throughout the project
33
//constexpr for textheight and textwidth, edit conditionals, get rid of ternaries
44
#include "datatypes.hpp"
5-
#include <iostream>
65

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

5655
bool endOfText {textEdit.cursor.row == textEdit.textEdit.size() - 1 ? true : false};
5756
bool textSizeRightSize {textEdit.textEdit.size() > (textHeight - 1) ? true : false}; //if end of text make sure to not just append a new row
57+
5858
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
5959
int prevIndent {better::getPreviousIndentLevel(textEdit, textEdit.cursor.row)};
6060
texts.push_back(newText);
@@ -105,6 +105,9 @@ int better::getPreviousIndentLevel(better::Text text, int row) {
105105
break;
106106
}
107107
}
108-
return notSpace;
108+
return notSpace;
109109
}
110110

111+
better::Text better::tab(better::Text text) {
112+
return better::updateText(better::updateText(better::updateText(better::updateText(text,' '),' '),' '),' ');
113+
}

src/Core/datatypes.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212
namespace better {
1313

14+
constexpr int textWidth() {
15+
return 150;
16+
}
17+
18+
constexpr int textHeight() {
19+
return 60;
20+
}
21+
1422
struct Cursor { //store the line number and column number of the cursor
1523
int row;
1624
int column;
@@ -51,6 +59,7 @@ better::charMapArr makeCharMapArr(::Uint8 charArray[16]);
5159
better::Text updateText(better::Text textEdit, char newChar);
5260
better::Text backspace(better::Text textEdit);
5361
better::Text newLine(better::Text textEdit);
62+
better::Text tab(better::Text text);
5463

5564
Uint8 getRed(Uint32 color);
5665
Uint8 getGreen(Uint32 color);

src/Core/fileUtils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! This file handles all of the file stream functionality of the program
33

44
#include "fileUtils.hpp"
5-
#include <iostream>
65

76
int better::saveFile(immer::flex_vector<immer::flex_vector<char>> contents, std::string filename) {
87
std::string buffer {""};

src/Core/main.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! @file
22
//! This is the main file of the project, containing the main event loop and renderer
33

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

49-
better::Text tab(better::Text text);
50-
5149
better::Text mouseMotion(better::Text text, SDL_Event event, SDL_Surface* surface, SDL_Cursor* guiCursor);
5250

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

8583
}
8684

87-
int main(int argc, char* argv[]) {
85+
int WinMain(int argc, char* argv[]) {
8886
SDL_SetMainReady();
8987
SDL_Init(SDL_INIT_VIDEO);
9088

@@ -328,7 +326,23 @@ better::Text better::keyDown(better::Text text, SDL_Event event, SDL_Surface* su
328326
}
329327
else if(event.key.keysym.scancode == SDL_SCANCODE_RETURN) {
330328
text.highlightStart = text.highlightEnd;
331-
return better::newLine(text);
329+
std::vector<better::Text> texts {text}; //fix scrolling here for newline near bottom of text
330+
331+
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] == ')'))) {
332+
if(texts.back().cursor.row != texts.back().textEdit.size() - 1 && texts.back().cursor.row >= texts.back().topLineNumber + better::textHeight() - 2) {
333+
texts.back().topLineNumber += 3;
334+
}
335+
texts.push_back(better::newLine(better::newLine(texts.back())));
336+
texts.push_back(better::verticalNav(texts.back(),SDL_SCANCODE_UP, better::textHeight(), better::textWidth()));
337+
texts.push_back(better::tab(texts.back()));
338+
}
339+
else {
340+
if(texts.back().cursor.row != texts.back().textEdit.size() - 1 && texts.back().cursor.row >= texts.back().topLineNumber + better::textHeight() - 2) {
341+
texts.back().topLineNumber += 1;
342+
}
343+
texts.push_back(better::newLine(texts.back()));
344+
}
345+
return texts.back();
332346
}
333347

334348
else if(event.key.keysym.scancode == SDL_SCANCODE_TAB) {
@@ -358,7 +372,7 @@ better::Text better::keyDown(better::Text text, SDL_Event event, SDL_Surface* su
358372
if(text.data.isCaps) {
359373
key = better::shiftLetter(key);
360374
}
361-
if(text.data.isScroll) {
375+
if(text.data.isScroll) { //change this
362376
text.topLineNumber = text.cursor.row;
363377
text.topColumnNumber = 0;
364378
}
@@ -535,10 +549,6 @@ better::Text better::mouseMotion(better::Text text, SDL_Event event, SDL_Surface
535549
return text;
536550
}
537551

538-
better::Text better::tab(better::Text text) {
539-
return better::updateText(better::updateText(better::updateText(better::updateText(text,' '),' '),' '),' ');
540-
}
541-
542552
void better::quitApp(SDL_Cursor* cursor, SDL_Surface* surface, SDL_Window* window) {
543553
SDL_FreeCursor(cursor);
544554
SDL_FreeSurface(surface);

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++ -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 -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 commit comments

Comments
 (0)