Fix cursor storage (#120)

This commit is contained in:
Yaya-Cout
2022-01-10 20:53:38 +01:00
committed by GitHub
parent 685e73c52d
commit 8126e0da7e
9 changed files with 19 additions and 20 deletions

View File

@@ -30,7 +30,7 @@ public:
* - MiddleOfIdentifier is the cursor is in the middle of an identifier, * - MiddleOfIdentifier is the cursor is in the middle of an identifier,
* - No identifier otherwise. * - No identifier otherwise.
* The autocompletionLocation can be provided with autocompletionLocation, or * The autocompletionLocation can be provided with autocompletionLocation, or
* retreived with autocompletionLocationBeginning and autocompletionLocationEnd. */ * retrieved with autocompletionLocationBeginning and autocompletionLocationEnd. */
AutocompletionType autocompletionType(const char * autocompletionLocation = nullptr, const char ** autocompletionLocationBeginning = nullptr, const char ** autocompletionLocationEnd = nullptr) const; AutocompletionType autocompletionType(const char * autocompletionLocation = nullptr, const char ** autocompletionLocationBeginning = nullptr, const char ** autocompletionLocationEnd = nullptr) const;
bool isAutocompleting() const { return m_contentView.isAutocompleting(); } bool isAutocompleting() const { return m_contentView.isAutocompleting(); }
protected: protected:

View File

@@ -2,7 +2,7 @@
#include "script_store.h" #include "script_store.h"
#if APP_SCRIPT_LOG #if APP_SCRIPT_LOG
#include<iostream> #include <iostream>
#endif #endif
namespace Code { namespace Code {
@@ -72,13 +72,12 @@ uint8_t * StatusFromData(Script::Data d) {
return const_cast<uint8_t *>(static_cast<const uint8_t *>(d.buffer)); return const_cast<uint8_t *>(static_cast<const uint8_t *>(d.buffer));
} }
uint8_t * Script::CursorPosition() { uint16_t * Script::CursorPosition() {
assert(!isNull()); assert(!isNull());
Data d = value(); Data d = value();
return StatusFromData(d) + StatusSize(); return (uint16_t *)(StatusFromData(d) + StatusSize());
} }
void Script::setCursorPosition(uint16_t position) {
void Script::setCursorPosition(uint8_t position) {
assert(!isNull()); assert(!isNull());
Data d = value(); Data d = value();
*CursorPosition() = position; *CursorPosition() = position;

View File

@@ -23,9 +23,9 @@ namespace Code {
* FetchedForVariableBoxBit is used to prevent circular importation problems, * FetchedForVariableBoxBit is used to prevent circular importation problems,
* such as scriptA importing scriptB, which imports scriptA. Once we get the * 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 * 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*/ * Cursor Position is two bytes long and has the cursor position value */
class Script : public Ion::Storage::Record { class Script : public Ion::Storage::Record {
private: private:
@@ -35,7 +35,7 @@ private:
// See the comment at the beginning of the file // See the comment at the beginning of the file
static constexpr size_t k_statusSize = 1; static constexpr size_t k_statusSize = 1;
static constexpr size_t k_cursorPositionSize = 1; static constexpr size_t k_cursorPositionSize = 2;
public: public:
static constexpr int k_defaultScriptNameMaxSize = 6 + k_defaultScriptNameNumberMaxSize + 1; static constexpr int k_defaultScriptNameMaxSize = 6 + k_defaultScriptNameNumberMaxSize + 1;
@@ -54,8 +54,8 @@ public:
void toggleAutoimportationStatus(); void toggleAutoimportationStatus();
const char * content() const; const char * content() const;
size_t contentSize() { return value().size - k_statusSize - k_cursorPositionSize; } size_t contentSize() { return value().size - k_statusSize - k_cursorPositionSize; }
void setCursorPosition(uint8_t position); void setCursorPosition(uint16_t position);
uint8_t * CursorPosition(); uint16_t * CursorPosition();
/* Fetched status */ /* Fetched status */
bool fetchedFromConsole() const; bool fetchedFromConsole() const;

View File

@@ -51,7 +51,7 @@ void ScriptStore::clearConsoleFetchInformation() {
} }
Script::ErrorStatus ScriptStore::addScriptFromTemplate(const ScriptTemplate * scriptTemplate) { Script::ErrorStatus ScriptStore::addScriptFromTemplate(const ScriptTemplate * scriptTemplate) {
size_t valueSize = Script::StatusSize() + Script::CursorPositionSize() + 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 + cursor position + content fetched status) + scriptcontent size + null-terminating char
assert(Script::nameCompliant(scriptTemplate->name())); assert(Script::nameCompliant(scriptTemplate->name()));
Script::ErrorStatus err = Ion::Storage::sharedStorage()->createRecordWithFullName(scriptTemplate->name(), scriptTemplate->value(), valueSize); Script::ErrorStatus err = Ion::Storage::sharedStorage()->createRecordWithFullName(scriptTemplate->name(), scriptTemplate->value(), valueSize);
assert(err != Script::ErrorStatus::NonCompliantName); assert(err != Script::ErrorStatus::NonCompliantName);

View File

@@ -49,9 +49,9 @@ private:
* k_fullFreeSpaceSizeLimit, we consider the script store as full. * k_fullFreeSpaceSizeLimit, we consider the script store as full.
* To be able to add a new empty record, the available space should at least * To be able to add a new empty record, the available space should at least
* be able to store a Script with default name and its extension, the * be able to store a Script with default name and its extension, the
* importation status (1 char), the default content "from math import *\n" * importation status (1 char), the cursor (2 char), the default content "from math import *\n"
* (20 char) and 10 char of free space. */ * (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+1; static constexpr int k_fullFreeSpaceSizeLimit = sizeof(Ion::Storage::record_size_t)+Script::k_defaultScriptNameMaxSize+k_scriptExtensionLength+1+20+10+2;
}; };
} }

View File

@@ -2,7 +2,7 @@
namespace Code { namespace Code {
constexpr ScriptTemplate emptyScriptTemplate(".py", "\x01" "\x00" R"(from math import * constexpr ScriptTemplate emptyScriptTemplate(".py", "\x01" "\x00\x00" R"(from math import *
)"); )");

View File

@@ -63,7 +63,7 @@ QUIZ_CASE(variable_box_controller) {
}; };
// FIXME This test does not load imported variables for now // FIXME This test does not load imported variables for now
assert_variables_are( assert_variables_are(
"\x01\x01 from math import *\nfroo=3", "\x01\x01\x01 from math import *\nfroo=3",
"fr", "fr",
expectedVariables, expectedVariables,
sizeof(expectedVariables) / sizeof(const char *)); sizeof(expectedVariables) / sizeof(const char *));

View File

@@ -122,8 +122,8 @@ public:
// Useful // Useful
static bool FullNameCompliant(const char * name); static bool FullNameCompliant(const char * name);
// User by Python OS module // Used by Python OS module
int numberOfRecords(); int numberOfRecords();
Record recordAtIndex(int index); Record recordAtIndex(int index);

View File

@@ -46,7 +46,7 @@ public:
/* This function allows to convert Evaluation to derived Evaluation. /* This function allows to convert Evaluation to derived Evaluation.
* *
* We could have overriden the operator T(). However, even with the * We could have overriden the operator T(). However, even with the
* 'explicit' keyword (which prevents implicit casts), direct initilization * 'explicit' keyword (which prevents implicit casts), direct initialization
* are enable which can lead to weird code: * are enable which can lead to weird code:
* ie, you can write: 'Complex<float> a(2); MatrixComplex<float> b(a);' * ie, you can write: 'Complex<float> a(2); MatrixComplex<float> b(a);'
* */ * */