1- #include " ../libs/chesto/src/EKeyboard.hpp"
21#include " EditorView.hpp"
2+ #include " ../libs/chesto/src/EKeyboard.hpp"
33#include " MainDisplay.hpp"
44
5+ using namespace Chesto ;
6+
57EditorView::EditorView (Editor* editor)
68{
79 // initialize the text view for the first time, using whatever's in the editor
8- mainTextField = new TextInputElement (editor);
9- mainTextField->x = 10 ;
10- mainTextField->y = 70 ;
11- this ->elements .push_back (mainTextField);
10+ auto mainTextFieldPtr = std::make_unique<TextInputElement>(editor);
11+ mainTextFieldPtr->x = 10 ;
12+ mainTextFieldPtr->y = 70 ;
1213
1314#if defined(_3DS) || defined(_3DS_MOCK)
14- mainTextField ->x += 40 ;
15- mainTextField ->y += SCREEN_HEIGHT ;
15+ mainTextFieldPtr ->x += 40 ;
16+ mainTextFieldPtr ->y += SCREEN_HEIGHT ;
1617#endif
1718
19+ mainTextField = mainTextFieldPtr.get ();
20+ this ->addNode (std::move (mainTextFieldPtr));
21+
1822 this ->editor = editor;
1923 this ->text = editor->text ;
2024
@@ -63,23 +67,24 @@ void EditorView::reset_bounds()
6367 float cursor_y = mainTextField->selectedYPos ;
6468
6569 // if this boolean is set, adjust the textfield in the direction of the cursor
66- if (keepCursorOnscreen) {
70+ if (keepCursorOnscreen)
71+ {
6772#if defined(_3DS) || defined(_3DS_MOCK)
6873 if (cursor_y > SCREEN_HEIGHT - 150 )
69- mainTextField->y -= h/ 2 ;
74+ mainTextField->y -= h / 2 ;
7075 if (cursor_y < 50 )
71- mainTextField->y += h/ 2 ;
76+ mainTextField->y += h / 2 ;
7277#else
7378 if (mainTextField->selectedPos == 0 )
7479 mainTextField->y = 0 ;
7580
7681 bool blockKeyboardDraws = mainTextField->insertMode && !keyboard->immersiveMode ;
7782
7883 if (cursor_y > (blockKeyboardDraws ? 200 : (SCREEN_HEIGHT - 100 )))
79- mainTextField->y -= h/ 2 ;
84+ mainTextField->y -= h / 2 ;
8085
81- if (cursor_y < 50 && mainTextField->y < -1 * h/ 4 )
82- mainTextField->y += h/ 2 ;
86+ if (cursor_y < 50 && mainTextField->y < -1 * h / 4 )
87+ mainTextField->y += h / 2 ;
8388#endif
8489 }
8590}
@@ -90,9 +95,9 @@ bool EditorView::copySelection()
9095
9196 if (copiedText)
9297 delete copiedText;
93-
98+
9499 int pos = mainTextField->selectedPos ;
95- int width = mainTextField->selectedWidth ;
100+ int width = mainTextField->selectedWidth ;
96101
97102 copiedText = new std::string (text->substr (pos, width));
98103 ((MainDisplay*)RootDisplay::mainDisplay)->copiedText = copiedText;
@@ -106,7 +111,7 @@ bool EditorView::pasteSelection()
106111 copiedText = ((MainDisplay*)RootDisplay::mainDisplay)->copiedText ;
107112 if (copiedText == NULL )
108113 return false ;
109-
114+
110115 editor->appendHistory (copiedText->c_str (), mainTextField->selectedPos , false );
111116
112117 for (char & letter : *copiedText)
0 commit comments