mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[escher/expression_field] Renamed dumpLayout
Changed dumpLayout's name to moveCursorAndDumpContent, as the name suggested the method was only usable on layouts (while it also works on text). The method is also no longer marked const, and the previous name could imply that it had no side effects. Likewise, renamed restoreLayout to restoreContent. Change-Id: I46b320e74c07b48e256dc2146f9ecc15af38a8e6
This commit is contained in:
committed by
Émilie Feral
parent
67af3a5b4e
commit
de681705e6
@@ -56,13 +56,13 @@ void EditExpressionController::insertTextBody(const char * text) {
|
||||
void EditExpressionController::didBecomeFirstResponder() {
|
||||
m_contentView.mainView()->scrollToBottom();
|
||||
m_contentView.expressionField()->setEditing(true, false);
|
||||
m_contentView.expressionField()->restoreLayout(m_cacheBuffer, *m_cacheBufferInformation);
|
||||
m_contentView.expressionField()->restoreContent(m_cacheBuffer, *m_cacheBufferInformation);
|
||||
clearCacheBuffer();
|
||||
Container::activeApp()->setFirstResponder(m_contentView.expressionField());
|
||||
}
|
||||
|
||||
void EditExpressionController::willExitResponderChain(Responder * nextFirstResponder) {
|
||||
*m_cacheBufferInformation = m_contentView.expressionField()->dumpLayout(m_cacheBuffer, k_cacheBufferSize);
|
||||
*m_cacheBufferInformation = m_contentView.expressionField()->moveCursorAndDumpContent(m_cacheBuffer, k_cacheBufferSize);
|
||||
::ViewController::willExitResponderChain(nextFirstResponder);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ public:
|
||||
bool inputViewHeightDidChange();
|
||||
bool handleEventWithText(const char * text, bool indentation = false, bool forceCursorRightOfText = false);
|
||||
void setLayoutInsertionCursorEvent(Ion::Events::Event event) { m_layoutField.setInsertionCursorEvent(event); }
|
||||
size_t dumpLayout(char * buffer, size_t bufferSize);
|
||||
void restoreLayout(const char * buffer, size_t size);
|
||||
size_t moveCursorAndDumpContent(char * buffer, size_t bufferSize);
|
||||
void restoreContent(const char * buffer, size_t size);
|
||||
|
||||
/* View */
|
||||
int numberOfSubviews() const override { return 1; }
|
||||
|
||||
@@ -122,13 +122,14 @@ KDCoordinate ExpressionField::inputViewHeight() const {
|
||||
std::max(k_minimalHeight, m_layoutField.minimalSizeForOptimalDisplay().height())));
|
||||
}
|
||||
|
||||
size_t ExpressionField::dumpLayout(char * buffer, size_t bufferSize) {
|
||||
size_t ExpressionField::moveCursorAndDumpContent(char * buffer, size_t bufferSize) {
|
||||
size_t size;
|
||||
size_t returnValue;
|
||||
char * currentLayout;
|
||||
char * currentContent;
|
||||
if (editionIsInTextField()) {
|
||||
size = strlen(m_textField.draftTextBuffer()) + 1;
|
||||
currentLayout = m_textField.draftTextBuffer();
|
||||
m_textField.setCursorLocation(m_textField.cursorLocation() + size - 1);
|
||||
currentContent = m_textField.draftTextBuffer();
|
||||
/* We take advantage of the fact that draftTextBuffer is null terminated to
|
||||
* use a size of 0 as a shorthand for "The buffer contains raw text instead
|
||||
* of layouts", since the size of a layout is at least 32 (the size of an
|
||||
@@ -136,9 +137,9 @@ size_t ExpressionField::dumpLayout(char * buffer, size_t bufferSize) {
|
||||
* has changed and invalidate the data.*/
|
||||
returnValue = 0;
|
||||
} else {
|
||||
/* dumpLayout will be called whenever Calculation exits, event when an
|
||||
* exception occurs. We thus need to check the validity of the layout we
|
||||
* are dumping (m_layoutField.m_contentView.m_expressionView.m_layout).
|
||||
/* moveCursorAndDumpContent will be called whenever Calculation exits,
|
||||
* even when an exception occurs. We thus need to check the validity of the
|
||||
* layout we are dumping (m_layoutField.contentView.expressionView.layout).
|
||||
* However, attempting to get a handle on a layout that has been erased
|
||||
* will crash the program. We need the check to be performed on the
|
||||
* original object in expressionView. */
|
||||
@@ -148,18 +149,18 @@ size_t ExpressionField::dumpLayout(char * buffer, size_t bufferSize) {
|
||||
}
|
||||
m_layoutField.putCursorRightOfLayout();
|
||||
size = m_layoutField.layout().size();
|
||||
currentLayout = reinterpret_cast<char *>(m_layoutField.layout().node());
|
||||
currentContent = reinterpret_cast<char *>(m_layoutField.layout().node());
|
||||
returnValue = size;
|
||||
}
|
||||
if (size > bufferSize - 1) {
|
||||
buffer[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
memcpy(buffer, currentLayout, size);
|
||||
memcpy(buffer, currentContent, size);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
void ExpressionField::restoreLayout(const char * buffer, size_t size) {
|
||||
void ExpressionField::restoreContent(const char * buffer, size_t size) {
|
||||
if (editionIsInTextField()) {
|
||||
if (size != 0 || buffer[0] == 0) {
|
||||
/* A size other than 0 means the buffer contains Layout information
|
||||
|
||||
Reference in New Issue
Block a user