[apps/escher] Rename cursorTextLocation as cursorLocation

This commit is contained in:
Léa Saviot
2019-01-23 16:11:35 +01:00
committed by Émilie Feral
parent 6765de4598
commit bd2ea41fbe
12 changed files with 94 additions and 94 deletions

View File

@@ -44,7 +44,7 @@ void EditorController::didBecomeFirstResponder() {
void EditorController::viewWillAppear() {
m_editorView.loadSyntaxHighlighter();
m_editorView.setCursorTextLocation(m_editorView.text() + strlen(m_editorView.text()));
m_editorView.setCursorLocation(m_editorView.text() + strlen(m_editorView.text()));
}
void EditorController::viewDidDisappear() {
@@ -70,7 +70,7 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
/* If the cursor is on the left of the text of a line, backspace one
* indentation space at a time. */
char * text = const_cast<char *>(textArea->text());
const char * charBeforeCursorPointer = textArea->cursorTextLocation()-1;
const char * charBeforeCursorPointer = textArea->cursorLocation()-1;
int indentationSize = 0;
while (charBeforeCursorPointer >= text && *charBeforeCursorPointer == ' ') {
charBeforeCursorPointer--;
@@ -89,7 +89,7 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
/* If the cursor is on the left of the text of a line, a space triggers an
* indentation. */
char * text = const_cast<char *>(textArea->text());
const char * charBeforeCursorPointer = textArea->cursorTextLocation()-1;
const char * charBeforeCursorPointer = textArea->cursorLocation()-1;
while (charBeforeCursorPointer >= text && *charBeforeCursorPointer == ' ') {
charBeforeCursorPointer--;
}

View File

@@ -16,8 +16,8 @@ public:
void setText(char * textBuffer, size_t textBufferSize) {
m_textArea.setText(textBuffer, textBufferSize);
}
bool setCursorTextLocation(const char * location) {
return m_textArea.setCursorTextLocation(location);
bool setCursorLocation(const char * location) {
return m_textArea.setCursorLocation(location);
}
void loadSyntaxHighlighter() { m_textArea.loadSyntaxHighlighter(); };
void unloadSyntaxHighlighter() { m_textArea.unloadSyntaxHighlighter(); };

View File

@@ -126,7 +126,7 @@ void MenuController::renameSelectedScript() {
app()->setFirstResponder(myCell);
myCell->setHighlighted(false);
myCell->textField()->setEditing(true, false);
myCell->textField()->setCursorTextLocation(myCell->textField()->text() + strlen(myCell->textField()->text()));
myCell->textField()->setCursorLocation(myCell->textField()->text() + strlen(myCell->textField()->text()));
}
void MenuController::deleteScript(Script script) {
@@ -285,7 +285,7 @@ bool MenuController::textFieldShouldFinishEditing(TextField * textField, Ion::Ev
bool MenuController::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) {
if (event == Ion::Events::Right
&& textField->isEditing()
&& textField->cursorTextLocation() == textField->text() + textField->draftTextLength()) {
&& textField->cursorLocation() == textField->text() + textField->draftTextLength()) {
return true;
}
if (event == Ion::Events::Clear && textField->isEditing()) {
@@ -294,7 +294,7 @@ bool MenuController::textFieldDidReceiveEvent(TextField * textField, Ion::Events
assert(k_bufferSize >= 1 + strlen(ScriptStore::k_scriptExtension) + 1);
strlcpy(&buffer[1], ScriptStore::k_scriptExtension, strlen(ScriptStore::k_scriptExtension) + 1);
textField->setText(buffer);
textField->setCursorTextLocation(textField->text());
textField->setCursorLocation(textField->text());
return true;
}
return false;
@@ -318,7 +318,7 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char
* default name and let the user modify it. */
if (!foundDefaultName) {
textField->setText(numberedDefaultName);
textField->setCursorTextLocation(textField->draftTextBuffer() + defaultNameLength);
textField->setCursorLocation(textField->draftTextBuffer() + defaultNameLength);
}
newName = const_cast<const char *>(numberedDefaultName);
}
@@ -351,8 +351,8 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char
bool MenuController::textFieldDidHandleEvent(TextField * textField, bool returnValue, bool textSizeDidChange) {
int scriptExtensionLength = 1 + strlen(ScriptStore::k_scriptExtension);
const char * maxPointerLocation = textField->text() + textField->draftTextLength() - scriptExtensionLength;
if (textField->isEditing() && textField->cursorTextLocation() > maxPointerLocation) {
textField->setCursorTextLocation(maxPointerLocation);
if (textField->isEditing() && textField->cursorLocation() > maxPointerLocation) {
textField->setCursorLocation(maxPointerLocation);
}
return returnValue;
}

View File

@@ -203,10 +203,10 @@ bool CalculationController::textFieldDidHandleEvent(::TextField * textField, boo
bool CalculationController::textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) {
return TextFieldDelegate::textFieldShouldFinishEditing(textField, event)
|| (event == Ion::Events::Right
&& textField->cursorTextLocation() == textField->text() + textField->draftTextLength()
&& textField->cursorLocation() == textField->text() + textField->draftTextLength()
&& selectedColumn() < m_calculation->numberOfParameters())
|| (event == Ion::Events::Left
&& textField->cursorTextLocation() == textField->text());
&& textField->cursorLocation() == textField->text());
}
bool CalculationController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {

View File

@@ -19,8 +19,8 @@ bool EditableCellTableViewController::textFieldShouldFinishEditing(TextField * t
return TextFieldDelegate::textFieldShouldFinishEditing(textField, event)
|| (event == Ion::Events::Down && selectedRow() < numberOfRows()-1)
|| (event == Ion::Events::Up && selectedRow() > 0)
|| (event == Ion::Events::Right && (textField->cursorTextLocation() == textField->draftTextBuffer() + textField->draftTextLength()) && selectedColumn() < numberOfColumns()-1)
|| (event == Ion::Events::Left && textField->cursorTextLocation() == textField->draftTextBuffer() && selectedColumn() > 0);
|| (event == Ion::Events::Right && (textField->cursorLocation() == textField->draftTextBuffer() + textField->draftTextLength()) && selectedColumn() < numberOfColumns()-1)
|| (event == Ion::Events::Left && textField->cursorLocation() == textField->draftTextBuffer() && selectedColumn() > 0);
}
bool EditableCellTableViewController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {

View File

@@ -2,7 +2,7 @@
namespace Shared {
void TextFieldWithExtension::willSetCursorTextLocation(const char * * location) {
void TextFieldWithExtension::willSetCursorLocation(const char * * location) {
size_t textLength = strlen(text());
assert(textLength >= m_extensionLength);
const char * maxLocation = m_contentView.draftTextBuffer() + (textLength - m_extensionLength);
@@ -24,7 +24,7 @@ bool TextFieldWithExtension::removeTextBeforeExtension(bool whole) {
assert(isEditing());
const char * extension = m_contentView.draftTextBuffer() + (strlen(text()) - m_extensionLength);
assert(extension >= m_contentView.draftTextBuffer() && extension < m_contentView.draftTextBuffer() + (ContentView::k_maxBufferSize - m_extensionLength));
char * destination = whole ? m_contentView.draftTextBuffer() : const_cast<char *>(cursorTextLocation());
char * destination = whole ? m_contentView.draftTextBuffer() : const_cast<char *>(cursorLocation());
if (destination == extension) {
return false;
}
@@ -32,7 +32,7 @@ bool TextFieldWithExtension::removeTextBeforeExtension(bool whole) {
assert(destination < extension);
m_contentView.willModifyTextBuffer();
strlcpy(destination, extension, ContentView::k_maxBufferSize - (destination - m_contentView.draftTextBuffer()));
m_contentView.setCursorTextLocation(destination);
m_contentView.setCursorLocation(destination);
m_contentView.didModifyTextBuffer();
layoutSubviews();
return true;

View File

@@ -24,7 +24,7 @@ public:
m_extensionLength(extensionLength)
{}
private:
void willSetCursorTextLocation(const char * * location) override;
void willSetCursorLocation(const char * * location) override;
bool privateRemoveEndOfLine() override;
void removeWholeText() override;
bool removeTextBeforeExtension(bool whole);

View File

@@ -98,7 +98,7 @@ protected:
TextInput::ContentView(font),
m_text(nullptr, 0)
{
m_cursorTextLocation = m_text.text();
m_cursorLocation = m_text.text();
}
void drawRect(KDContext * ctx, KDRect rect) const override;
void drawStringAt(KDContext * ctx, int line, int column, const char * text, size_t length, KDColor textColor, KDColor backgroundColor) const;

View File

@@ -12,8 +12,8 @@ public:
void setFont(const KDFont * font) { contentView()->setFont(font); }
const char * text() const { return nonEditableContentView()->text(); }
bool removeCodePoint();
const char * cursorTextLocation() const { return nonEditableContentView()->cursorTextLocation(); }
bool setCursorTextLocation(const char * location);
const char * cursorLocation() const { return nonEditableContentView()->cursorLocation(); }
bool setCursorLocation(const char * location);
virtual void scrollToCursor();
protected:
class ContentView : public View {
@@ -22,12 +22,12 @@ protected:
View(),
m_cursorView(),
m_font(font),
m_cursorTextLocation(nullptr)
m_cursorLocation(nullptr)
{}
void setFont(const KDFont * font);
const KDFont * font() const { return m_font; }
const char * cursorTextLocation() const { assert(m_cursorTextLocation != nullptr); return m_cursorTextLocation; }
void setCursorTextLocation(const char * cursorTextLocation);
const char * cursorLocation() const { assert(m_cursorLocation != nullptr); return m_cursorLocation; }
void setCursorLocation(const char * cursorLocation);
virtual const char * text() const = 0;
virtual bool insertTextAtLocation(const char * text, const char * location) = 0;
virtual bool removeCodePoint() = 0;
@@ -39,7 +39,7 @@ protected:
virtual KDRect glyphFrameAtPosition(const char * position) const = 0;
TextCursorView m_cursorView;
const KDFont * m_font;
const char * m_cursorTextLocation;
const char * m_cursorLocation;
virtual KDRect dirtyRectFromPosition(const char * position, bool lineBreak) const;
private:
int numberOfSubviews() const override { return 1; }
@@ -61,7 +61,7 @@ protected:
}
virtual const ContentView * nonEditableContentView() const = 0;
private:
virtual void willSetCursorTextLocation(const char * * location) {}
virtual void willSetCursorLocation(const char * * location) {}
virtual bool privateRemoveEndOfLine();
};

View File

@@ -21,7 +21,7 @@ TextArea::TextArea(Responder * parentResponder, View * contentView, const KDFont
}
bool TextArea::handleEventWithText(const char * text, bool indentation, bool forceCursorRightOfText) {
const char * nextCursorLocation = cursorTextLocation();
const char * nextCursorLocation = cursorLocation();
const char * cursorPositionInCommand = TextInputHelpers::CursorPositionInCommand(text);
@@ -32,7 +32,7 @@ bool TextArea::handleEventWithText(const char * text, bool indentation, bool for
UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, text, UCodePointEmpty, &cursorPositionInCommand);
// Insert the text
if ((indentation && insertTextWithIndentation(buffer, cursorTextLocation())) || insertTextAtLocation(buffer, cursorTextLocation())) {
if ((indentation && insertTextWithIndentation(buffer, cursorLocation())) || insertTextAtLocation(buffer, cursorLocation())) {
// Set the cursor location
if (forceCursorRightOfText) {
nextCursorLocation += strlen(buffer);
@@ -40,7 +40,7 @@ bool TextArea::handleEventWithText(const char * text, bool indentation, bool for
nextCursorLocation += cursorPositionInCommand - text;
}
}
setCursorTextLocation(nextCursorLocation);
setCursorLocation(nextCursorLocation);
return true;
}
@@ -50,20 +50,20 @@ bool TextArea::handleEvent(Ion::Events::Event event) {
} else if (handleBoxEvent(app(), event)) {
return true;
} else if (event == Ion::Events::Left) {
if (cursorTextLocation() <= text()) {
assert(cursorTextLocation() == text());
if (cursorLocation() <= text()) {
assert(cursorLocation() == text());
return false;
}
UTF8Decoder decoder(text(), cursorTextLocation());
UTF8Decoder decoder(text(), cursorLocation());
decoder.previousCodePoint();
return setCursorTextLocation(decoder.stringPosition());
return setCursorLocation(decoder.stringPosition());
} else if (event == Ion::Events::Right) {
if (*cursorTextLocation() == 0) {
if (*cursorLocation() == 0) {
return false;
}
UTF8Decoder decoder(text(), cursorTextLocation());
UTF8Decoder decoder(text(), cursorLocation());
decoder.nextCodePoint();
return setCursorTextLocation(decoder.stringPosition());
return setCursorLocation(decoder.stringPosition());
} else if (event == Ion::Events::Up) {
contentView()->moveCursorGeo(0, -1);
} else if (event == Ion::Events::Down) {
@@ -98,7 +98,7 @@ void TextArea::setText(char * textBuffer, size_t textBufferSize) {
bool TextArea::insertTextWithIndentation(const char * textBuffer, const char * location) {
int indentation = indentationBeforeCursor();
const char * previousChar = cursorTextLocation()-1;
const char * previousChar = cursorLocation()-1;
if (previousChar >= const_cast<TextArea *>(this)->contentView()->text() && *previousChar == ':') {
indentation += k_indentationSpaces;
}
@@ -127,7 +127,7 @@ bool TextArea::insertTextWithIndentation(const char * textBuffer, const char * l
}
int TextArea::indentationBeforeCursor() const {
const char * p = cursorTextLocation()-1;
const char * p = cursorLocation()-1;
int indentationSize = 0;
// No need to use the UTF8Decoder here, be cause we look for an ASCII char.
while (p >= const_cast<TextArea *>(this)->contentView()->text() && *p != '\n') {
@@ -366,7 +366,7 @@ KDSize TextArea::ContentView::minimalSizeForOptimalDisplay() const {
void TextArea::TextArea::ContentView::setText(char * textBuffer, size_t textBufferSize) {
m_text.setText(textBuffer, textBufferSize);
m_cursorTextLocation = text();
m_cursorLocation = text();
}
bool TextArea::TextArea::ContentView::insertTextAtLocation(const char * text, const char * location) {
@@ -389,39 +389,39 @@ bool TextArea::TextArea::ContentView::insertTextAtLocation(const char * text, co
}
bool TextArea::TextArea::ContentView::removeCodePoint() {
if (cursorTextLocation() <= text()) {
assert(cursorTextLocation() == text());
if (cursorLocation() <= text()) {
assert(cursorLocation() == text());
return false;
}
bool lineBreak = false;
const char * cursorLoc = cursorTextLocation();
const char * cursorLoc = cursorLocation();
lineBreak = m_text.removeCodePoint(&cursorLoc) == '\n';
setCursorTextLocation(cursorLoc); // Update the cursor
setCursorLocation(cursorLoc); // Update the cursor
layoutSubviews(); // Reposition the cursor
reloadRectFromPosition(cursorTextLocation(), lineBreak);
reloadRectFromPosition(cursorLocation(), lineBreak);
return true;
}
bool TextArea::ContentView::removeEndOfLine() {
size_t removedLine = m_text.removeRemainingLine(cursorTextLocation(), 1);
size_t removedLine = m_text.removeRemainingLine(cursorLocation(), 1);
if (removedLine > 0) {
layoutSubviews();
reloadRectFromPosition(cursorTextLocation(), false);
reloadRectFromPosition(cursorLocation(), false);
return true;
}
return false;
}
bool TextArea::ContentView::removeStartOfLine() {
if (cursorTextLocation() <= text()) {
assert(cursorTextLocation() == text());
if (cursorLocation() <= text()) {
assert(cursorLocation() == text());
return false;
}
size_t removedLine = m_text.removeRemainingLine(cursorTextLocation(), -1); //TODO LEA Before : cursorTextLocation()-1
size_t removedLine = m_text.removeRemainingLine(cursorLocation(), -1); //TODO LEA Before : cursorLocation()-1
if (removedLine > 0) {
assert(cursorTextLocation() >= text() + removedLine);
setCursorTextLocation(cursorTextLocation() - removedLine);
reloadRectFromPosition(cursorTextLocation(), false);
assert(cursorLocation() >= text() + removedLine);
setCursorLocation(cursorLocation() - removedLine);
reloadRectFromPosition(cursorLocation(), false);
return true;
}
return false;
@@ -453,6 +453,6 @@ KDRect TextArea::ContentView::glyphFrameAtPosition(const char * position) const
}
void TextArea::ContentView::moveCursorGeo(int deltaX, int deltaY) {
Text::Position p = m_text.positionAtPointer(cursorTextLocation());
setCursorTextLocation(m_text.pointerAtPosition(Text::Position(p.column() + deltaX, p.line() + deltaY)));
Text::Position p = m_text.positionAtPointer(cursorLocation());
setCursorLocation(m_text.pointerAtPosition(Text::Position(p.column() + deltaX, p.line() + deltaY)));
}

View File

@@ -22,7 +22,7 @@ TextField::ContentView::ContentView(char * textBuffer, char * draftTextBuffer, s
m_backgroundColor(backgroundColor)
{
assert(m_textBufferSize <= k_maxBufferSize);
m_cursorTextLocation = draftTextBuffer;
m_cursorLocation = draftTextBuffer;
}
void TextField::ContentView::setBackgroundColor(KDColor backgroundColor) {
@@ -80,17 +80,17 @@ void TextField::ContentView::setEditing(bool isEditing, bool reinitDrafBuffer) {
reinitDraftTextBuffer();
}
m_currentDraftTextLength = strlen(m_draftTextBuffer);
if (m_cursorTextLocation < m_draftTextBuffer
|| m_cursorTextLocation > m_draftTextBuffer + m_currentDraftTextLength)
if (m_cursorLocation < m_draftTextBuffer
|| m_cursorLocation > m_draftTextBuffer + m_currentDraftTextLength)
{
m_cursorTextLocation = m_draftTextBuffer + m_currentDraftTextLength;
m_cursorLocation = m_draftTextBuffer + m_currentDraftTextLength;
}
markRectAsDirty(bounds());
layoutSubviews();
}
void TextField::ContentView::reinitDraftTextBuffer() {
setCursorTextLocation(m_draftTextBuffer);
setCursorLocation(m_draftTextBuffer);
m_draftTextBuffer[0] = 0;
m_currentDraftTextLength = 0;
}
@@ -143,28 +143,28 @@ KDSize TextField::ContentView::minimalSizeForOptimalDisplay() const {
bool TextField::ContentView::removeCodePoint() {
assert(m_isEditing);
if (cursorTextLocation() <= m_draftTextBuffer) {
assert(cursorTextLocation() == m_draftTextBuffer);
if (cursorLocation() <= m_draftTextBuffer) {
assert(cursorLocation() == m_draftTextBuffer);
return false;
}
UTF8Decoder decoder(m_draftTextBuffer, cursorTextLocation());
UTF8Decoder decoder(m_draftTextBuffer, cursorLocation());
decoder.previousCodePoint();
const char * newCursorLocation = decoder.stringPosition();
assert(newCursorLocation < cursorTextLocation());
int removedCodePointLength = cursorTextLocation() - newCursorLocation;
assert(newCursorLocation < cursorLocation());
int removedCodePointLength = cursorLocation() - newCursorLocation;
m_currentDraftTextLength-= removedCodePointLength;
if (m_horizontalAlignment > 0.0f) {
reloadRectFromPosition(m_draftTextBuffer);
}
setCursorTextLocation(newCursorLocation);
setCursorLocation(newCursorLocation);
if (m_horizontalAlignment == 0.0f) {
reloadRectFromPosition(cursorTextLocation());
reloadRectFromPosition(cursorLocation());
}
for (char * k = const_cast<char *>(cursorTextLocation()); k < m_draftTextBuffer + m_currentDraftTextLength + removedCodePointLength; k++) {
for (char * k = const_cast<char *>(cursorLocation()); k < m_draftTextBuffer + m_currentDraftTextLength + removedCodePointLength; k++) {
*k = *(k+removedCodePointLength);
if (*k == 0) {
break;
@@ -178,12 +178,12 @@ bool TextField::ContentView::removeCodePoint() {
bool TextField::ContentView::removeEndOfLine() {
assert(m_isEditing);
if (m_currentDraftTextLength == cursorTextLocation() - m_draftTextBuffer) {
if (m_currentDraftTextLength == cursorLocation() - m_draftTextBuffer) {
return false;
}
reloadRectFromPosition(m_horizontalAlignment == 0.0f ? cursorTextLocation() : m_draftTextBuffer);
m_currentDraftTextLength = cursorTextLocation() - m_draftTextBuffer;
*(const_cast<char *>(cursorTextLocation())) = 0;
reloadRectFromPosition(m_horizontalAlignment == 0.0f ? cursorLocation() : m_draftTextBuffer);
m_currentDraftTextLength = cursorLocation() - m_draftTextBuffer;
*(const_cast<char *>(cursorLocation())) = 0;
layoutSubviews();
return true;
}
@@ -262,7 +262,7 @@ void TextField::setText(const char * text) {
m_contentView.setText(text);
/* Set the cursor location here and not in ContentView::setText so that
* TextInput::willSetCursorLocation is called. */
setCursorTextLocation(m_contentView.draftTextBuffer()+strlen(text));
setCursorLocation(m_contentView.draftTextBuffer()+strlen(text));
}
void TextField::setAlignment(float horizontalAlignment, float verticalAlignment) {
@@ -286,7 +286,7 @@ bool TextField::privateHandleEvent(Ion::Events::Event event) {
}
if (isEditing() && shouldFinishEditing(event)) {
char bufferText[ContentView::k_maxBufferSize];
const char * cursorLoc = cursorTextLocation();
const char * cursorLoc = cursorLocation();
if (m_hasTwoBuffers) {
strlcpy(bufferText, m_contentView.textBuffer(), ContentView::k_maxBufferSize);
strlcpy(m_contentView.textBuffer(), m_contentView.draftTextBuffer(), m_contentView.bufferSize());
@@ -310,7 +310,7 @@ bool TextField::privateHandleEvent(Ion::Events::Event event) {
* reset the textfield in the same state as before */
setText(m_contentView.textBuffer());
strlcpy(m_contentView.textBuffer(), bufferText, ContentView::k_maxBufferSize);
setCursorTextLocation(cursorLoc);
setCursorLocation(cursorLoc);
}
return true;
}
@@ -359,7 +359,7 @@ CodePoint TextField::XNTCodePoint(CodePoint defaultXNTCodePoint) {
/* Let's assume everything before the cursor is nested correctly, which is
* reasonable if the expression is being entered left-to-right. */
const char * text = this->text();
const char * location = cursorTextLocation();
const char * location = cursorLocation();
UTF8Decoder decoder(text, text + (location - m_contentView.draftTextBuffer()));
unsigned level = 0;
while (location > m_contentView.draftTextBuffer()) {
@@ -431,25 +431,25 @@ void TextField::scrollToCursor() {
}
bool TextField::privateHandleMoveEvent(Ion::Events::Event event) {
if (event == Ion::Events::Left && isEditing() && cursorTextLocation() > m_contentView.draftTextBuffer()) {
if (event == Ion::Events::Left && isEditing() && cursorLocation() > m_contentView.draftTextBuffer()) {
assert(isEditing());
UTF8Decoder decoder(m_contentView.draftTextBuffer(), cursorTextLocation());
UTF8Decoder decoder(m_contentView.draftTextBuffer(), cursorLocation());
decoder.previousCodePoint();
return setCursorTextLocation(decoder.stringPosition());
return setCursorLocation(decoder.stringPosition());
}
if (event == Ion::Events::ShiftLeft && isEditing()) {
assert(isEditing());
return setCursorTextLocation(m_contentView.draftTextBuffer());
return setCursorLocation(m_contentView.draftTextBuffer());
}
if (event == Ion::Events::Right && isEditing() && cursorTextLocation() < m_contentView.draftTextBuffer() + draftTextLength()) {
if (event == Ion::Events::Right && isEditing() && cursorLocation() < m_contentView.draftTextBuffer() + draftTextLength()) {
assert(isEditing());
UTF8Decoder decoder(m_contentView.draftTextBuffer(), cursorTextLocation());
UTF8Decoder decoder(m_contentView.draftTextBuffer(), cursorLocation());
decoder.nextCodePoint();
return setCursorTextLocation(decoder.stringPosition());
return setCursorLocation(decoder.stringPosition());
}
if (event == Ion::Events::ShiftRight && isEditing()) {
assert(isEditing());
return setCursorTextLocation(m_contentView.draftTextBuffer() + draftTextLength());
return setCursorLocation(m_contentView.draftTextBuffer() + draftTextLength());
}
return false;
}
@@ -466,7 +466,7 @@ bool TextField::handleEventWithText(const char * eventText, bool indentation, bo
if (eventText[0] == 0) {
/* For instance, the event might be EXE on a non-editing text field to start
* edition. */
setCursorTextLocation(m_contentView.draftTextBuffer());
setCursorLocation(m_contentView.draftTextBuffer());
return m_delegate->textFieldDidHandleEvent(this, true, previousTextLength != 0);
}
@@ -476,18 +476,18 @@ bool TextField::handleEventWithText(const char * eventText, bool indentation, bo
UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, eventText, UCodePointEmpty);
const char * nextCursorLocation = m_contentView.draftTextBuffer() + draftTextLength();
if (insertTextAtLocation(buffer, cursorTextLocation())) {
if (insertTextAtLocation(buffer, cursorLocation())) {
/* The cursor position depends on the text as we sometimes want to position
* the cursor at the end of the text and sometimes after the first
* parenthesis. */
nextCursorLocation = cursorTextLocation();
nextCursorLocation = cursorLocation();
if (forceCursorRightOfText) {
nextCursorLocation+= strlen(buffer);
} else {
nextCursorLocation+= TextInputHelpers::CursorPositionInCommand(eventText) - eventText;
}
}
setCursorTextLocation(nextCursorLocation);
setCursorLocation(nextCursorLocation);
return m_delegate->textFieldDidHandleEvent(this, true, strlen(text()) != previousTextLength);
}

View File

@@ -6,11 +6,11 @@
static inline const char * minCharPointer(const char * x, const char * y) { return x < y ? x : y; }
static inline const char * maxCharPointer(const char * x, const char * y) { return x > y ? x : y; }
void TextInput::ContentView::setCursorTextLocation(const char * location) {
void TextInput::ContentView::setCursorLocation(const char * location) {
assert(location != nullptr);
assert(location >= editedText());
const char * adjustedLocation = minCharPointer(location, editedText() + editedTextLength());
m_cursorTextLocation = adjustedLocation;
m_cursorLocation = adjustedLocation;
layoutSubviews();
}
@@ -20,7 +20,7 @@ void TextInput::ContentView::setFont(const KDFont * font) {
}
KDRect TextInput::ContentView::cursorRect() {
return glyphFrameAtPosition(m_cursorTextLocation);
return glyphFrameAtPosition(m_cursorLocation);
}
void TextInput::ContentView::layoutSubviews() {
@@ -68,11 +68,11 @@ void TextInput::scrollToCursor() {
scrollToContentRect(contentView()->cursorRect(), true);
}
bool TextInput::setCursorTextLocation(const char * location) {
bool TextInput::setCursorLocation(const char * location) {
assert(location != nullptr);
const char * adjustedLocation = maxCharPointer(location, text());
willSetCursorTextLocation(&adjustedLocation);
contentView()->setCursorTextLocation(adjustedLocation);
willSetCursorLocation(&adjustedLocation);
contentView()->setCursorLocation(adjustedLocation);
scrollToCursor();
return true;
}