mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
For those who likes to code ❤ (#113)
This commit is contained in:
@@ -63,7 +63,7 @@ void EditorController::didBecomeFirstResponder() {
|
||||
void EditorController::viewWillAppear() {
|
||||
ViewController::viewWillAppear();
|
||||
m_editorView.loadSyntaxHighlighter();
|
||||
m_editorView.setCursorLocation(m_editorView.text() + strlen(m_editorView.text()));
|
||||
m_editorView.setCursorLocation(m_script.content() + *m_script.CursorPosition());
|
||||
}
|
||||
|
||||
void EditorController::viewDidDisappear() {
|
||||
@@ -72,6 +72,7 @@ void EditorController::viewDidDisappear() {
|
||||
}
|
||||
|
||||
bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events::Event event) {
|
||||
m_script.setCursorPosition(textArea->cursorLocation() - m_script.content());
|
||||
if (App::app()->textInputDidReceiveEvent(textArea, event)) {
|
||||
return true;
|
||||
}
|
||||
@@ -157,7 +158,7 @@ void EditorController::cleanStorageEmptySpace() {
|
||||
Ion::Storage::Record::Data scriptValue = m_script.value();
|
||||
Ion::Storage::sharedStorage()->getAvailableSpaceFromEndOfRecord(
|
||||
m_script,
|
||||
scriptValue.size - Script::StatusSize() - (strlen(m_script.content()) + 1)); // TODO optimize number of script fetches
|
||||
scriptValue.size - Script::StatusSize() - Script::CursorPositionSize() - (strlen(m_script.content()) + 1)); // TODO optimize number of script fetches
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "script.h"
|
||||
#include "script_store.h"
|
||||
|
||||
#if APP_SCRIPT_LOG
|
||||
#include<iostream>
|
||||
#endif
|
||||
namespace Code {
|
||||
|
||||
static inline void intToText(int i, char * buffer, int bufferSize) {
|
||||
@@ -69,6 +72,19 @@ uint8_t * StatusFromData(Script::Data d) {
|
||||
return const_cast<uint8_t *>(static_cast<const uint8_t *>(d.buffer));
|
||||
}
|
||||
|
||||
uint8_t * Script::CursorPosition() {
|
||||
assert(!isNull());
|
||||
Data d = value();
|
||||
return StatusFromData(d) + StatusSize();
|
||||
}
|
||||
|
||||
void Script::setCursorPosition(uint8_t position) {
|
||||
assert(!isNull());
|
||||
Data d = value();
|
||||
*CursorPosition() = position;
|
||||
setValue(d);
|
||||
}
|
||||
|
||||
bool Script::autoImportationStatus() const {
|
||||
return getStatutBit(k_autoImportationStatusMask);
|
||||
}
|
||||
@@ -82,7 +98,7 @@ void Script::toggleAutoimportationStatus() {
|
||||
|
||||
const char * Script::content() const {
|
||||
Data d = value();
|
||||
return ((const char *)d.buffer) + StatusSize();
|
||||
return ((const char *)d.buffer) + StatusSize() + CursorPositionSize();
|
||||
}
|
||||
|
||||
bool Script::fetchedFromConsole() const {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
namespace Code {
|
||||
|
||||
/* Record: | Size | Name | Body |
|
||||
* Script: | | | Status | Content |
|
||||
/* Record: | Size | Name | Body |
|
||||
* Script: | | | Status | CursorPosition | Content |
|
||||
*
|
||||
*
|
||||
* |FetchedForVariableBoxBit
|
||||
@@ -23,7 +23,9 @@ namespace Code {
|
||||
* FetchedForVariableBoxBit is used to prevent circular importation problems,
|
||||
* such as scriptA importing scriptB, which imports scriptA. Once we get the
|
||||
* variables from a script to put them in the variable box, we switch the bit to
|
||||
* 1 and won't reload it afterwards. */
|
||||
* 1 and won't reload it afterwards.
|
||||
*
|
||||
* Cursor Position is one byte long and has the cursor position value*/
|
||||
|
||||
class Script : public Ion::Storage::Record {
|
||||
private:
|
||||
@@ -33,6 +35,7 @@ private:
|
||||
|
||||
// See the comment at the beginning of the file
|
||||
static constexpr size_t k_statusSize = 1;
|
||||
static constexpr size_t k_cursorPositionSize = 1;
|
||||
|
||||
public:
|
||||
static constexpr int k_defaultScriptNameMaxSize = 6 + k_defaultScriptNameNumberMaxSize + 1;
|
||||
@@ -43,13 +46,16 @@ public:
|
||||
static bool DefaultName(char buffer[], size_t bufferSize);
|
||||
static bool nameCompliant(const char * name);
|
||||
static constexpr size_t StatusSize() { return k_statusSize; }
|
||||
static constexpr size_t CursorPositionSize() { return k_cursorPositionSize; }
|
||||
|
||||
|
||||
Script(Ion::Storage::Record r = Ion::Storage::Record()) : Record(r) {}
|
||||
bool autoImportationStatus() const;
|
||||
void toggleAutoimportationStatus();
|
||||
const char * content() const;
|
||||
size_t contentSize() { return value().size - k_statusSize; }
|
||||
size_t contentSize() { return value().size - k_statusSize - k_cursorPositionSize; }
|
||||
void setCursorPosition(uint8_t position);
|
||||
uint8_t * CursorPosition();
|
||||
|
||||
/* Fetched status */
|
||||
bool fetchedFromConsole() const;
|
||||
|
||||
@@ -51,7 +51,7 @@ void ScriptStore::clearConsoleFetchInformation() {
|
||||
}
|
||||
|
||||
Script::ErrorStatus ScriptStore::addScriptFromTemplate(const ScriptTemplate * scriptTemplate) {
|
||||
size_t valueSize = Script::StatusSize() + strlen(scriptTemplate->content()) + 1; // (auto importation status + content fetched status) + scriptcontent size + null-terminating char
|
||||
size_t valueSize = Script::StatusSize() + Script::CursorPositionSize() + strlen(scriptTemplate->content()) + 1; // (auto importation status + content fetched status) + scriptcontent size + null-terminating char
|
||||
assert(Script::nameCompliant(scriptTemplate->name()));
|
||||
Script::ErrorStatus err = Ion::Storage::sharedStorage()->createRecordWithFullName(scriptTemplate->name(), scriptTemplate->value(), valueSize);
|
||||
assert(err != Script::ErrorStatus::NonCompliantName);
|
||||
|
||||
@@ -51,7 +51,7 @@ private:
|
||||
* be able to store a Script with default name and its extension, the
|
||||
* importation status (1 char), the default content "from math import *\n"
|
||||
* (20 char) and 10 char of free space. */
|
||||
static constexpr int k_fullFreeSpaceSizeLimit = sizeof(Ion::Storage::record_size_t)+Script::k_defaultScriptNameMaxSize+k_scriptExtensionLength+1+20+10;
|
||||
static constexpr int k_fullFreeSpaceSizeLimit = sizeof(Ion::Storage::record_size_t)+Script::k_defaultScriptNameMaxSize+k_scriptExtensionLength+1+20+10+1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Code {
|
||||
|
||||
constexpr ScriptTemplate emptyScriptTemplate(".py", "\x01" R"(from math import *
|
||||
constexpr ScriptTemplate emptyScriptTemplate(".py", "\x01" "\x00" R"(from math import *
|
||||
)");
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
constexpr ScriptTemplate(const char * name, const char * value) : m_name(name), m_value(value) {}
|
||||
static const ScriptTemplate * Empty();
|
||||
const char * name() const { return m_name; }
|
||||
const char * content() const { return m_value + Script::StatusSize(); }
|
||||
const char * content() const { return m_value + Script::StatusSize() + Script::CursorPositionSize(); }
|
||||
const char * value() const { return m_value; }
|
||||
private:
|
||||
const char * m_name;
|
||||
|
||||
Reference in New Issue
Block a user