mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 16:57:31 +01:00
[apps/code/editor_controller] Fix backspace event handling
If there are only spaces on the left of the cursor, then a backspace should remove two spaces (or one if there is only one of it). The number of spaces was miscomputed.
This commit is contained in:
committed by
LeaNumworks
parent
9a63be7ac6
commit
5ee130a959
@@ -70,9 +70,19 @@ 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. */
|
||||
const char * text = textArea->text();
|
||||
const char * firstNonSpace = UTF8Helper::NotCodePointSearch(text, ' ', true, textArea->cursorLocation());
|
||||
const char * cursorLocation = textArea->cursorLocation();
|
||||
const char * firstNonSpace = UTF8Helper::NotCodePointSearch(text, ' ', true, cursorLocation);
|
||||
assert(firstNonSpace >= text);
|
||||
if (UTF8Helper::CodePointIs(firstNonSpace, '\n') && ((text - firstNonSpace)/UTF8Decoder::CharSizeOfCodePoint(' ')) >= k_indentationSpacesNumber) {
|
||||
bool cursorIsPrecededOnTheLineBySpacesOnly = false;
|
||||
size_t numberOfSpaces = cursorLocation - firstNonSpace;
|
||||
if (UTF8Helper::CodePointIs(firstNonSpace, '\n')) {
|
||||
cursorIsPrecededOnTheLineBySpacesOnly = true;
|
||||
numberOfSpaces -= UTF8Decoder::CharSizeOfCodePoint('\n');
|
||||
} else if (firstNonSpace == text) {
|
||||
cursorIsPrecededOnTheLineBySpacesOnly = true;
|
||||
}
|
||||
numberOfSpaces = numberOfSpaces / UTF8Decoder::CharSizeOfCodePoint(' ');
|
||||
if (cursorIsPrecededOnTheLineBySpacesOnly && numberOfSpaces >= k_indentationSpacesNumber) {
|
||||
for (int i = 0; i < k_indentationSpacesNumber; i++) {
|
||||
textArea->removeCodePoint();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user