[apps/escher] Factorize TxtArea and Code::EditorCtrlr's k_indentSpaces

This commit is contained in:
Léa Saviot
2019-06-28 14:18:07 +02:00
committed by Émilie Feral
parent 1d5220ccb2
commit e8be088478
3 changed files with 7 additions and 7 deletions

View File

@@ -82,8 +82,8 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
cursorIsPrecededOnTheLineBySpacesOnly = true;
}
numberOfSpaces = numberOfSpaces / UTF8Decoder::CharSizeOfCodePoint(' ');
if (cursorIsPrecededOnTheLineBySpacesOnly && numberOfSpaces >= k_indentationSpacesNumber) {
for (int i = 0; i < k_indentationSpacesNumber; i++) {
if (cursorIsPrecededOnTheLineBySpacesOnly && numberOfSpaces >= TextArea::k_indentationSpaces) {
for (int i = 0; i < TextArea::k_indentationSpaces; i++) {
textArea->removePreviousGlyph();
}
return true;
@@ -96,11 +96,11 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
assert(firstNonSpace >= text);
if (UTF8Helper::CodePointIs(firstNonSpace, '\n')) {
assert(UTF8Decoder::CharSizeOfCodePoint(' ') == 1);
char indentationBuffer[k_indentationSpacesNumber+1];
for (int i = 0; i < k_indentationSpacesNumber; i++) {
char indentationBuffer[TextArea::k_indentationSpaces+1];
for (int i = 0; i < TextArea::k_indentationSpaces; i++) {
indentationBuffer[i] = ' ';
}
indentationBuffer[k_indentationSpacesNumber] = 0;
indentationBuffer[TextArea::k_indentationSpaces] = 0;
textArea->handleEventWithText(indentationBuffer);
return true;
}

View File

@@ -33,7 +33,6 @@ public:
VariableBoxController * variableBoxForInputEventHandler(InputEventHandler * textInput) override;
private:
static constexpr int k_indentationSpacesNumber = 2; //TODO LEA merge with text area k_indentationSpaces
StackViewController * stackController();
void saveScript();
EditorView m_editorView;

View File

@@ -9,6 +9,8 @@
class TextArea : public TextInput, public InputEventHandler {
public:
static constexpr int k_indentationSpaces = 2;
TextArea(Responder * parentResponder, View * contentView, const KDFont * font = KDFont::LargeFont);
void setDelegates(InputEventHandlerDelegate * inputEventHandlerDelegate, TextAreaDelegate * delegate) { m_inputEventHandlerDelegate = inputEventHandlerDelegate; m_delegate = delegate; }
bool handleEvent(Ion::Events::Event event) override;
@@ -124,7 +126,6 @@ protected:
ContentView * contentView() { return static_cast<ContentView *>(TextInput::contentView()); }
private:
static constexpr int k_indentationSpaces = 2;
TextAreaDelegate * m_delegate;
};