From d4fb6b8b6b1d3f0396881a8bc5059c4ddc28923c Mon Sep 17 00:00:00 2001 From: 00schneider Date: Sun, 2 Oct 2016 09:45:09 +0200 Subject: [PATCH 1/2] Call correctCaretPos() after keyboard navigation If the up/down arrow keys were used for keyboard navigation in a multiline editbox, the position of the caret would become invalid because it was not updated to fit in the new line. This caused incorrect behaviour when entering text after such navigation (ie replacing text when it should have appended). --- src/dlangui/widgets/editors.d | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index a8eb80b3..67874e83 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -2390,6 +2390,7 @@ class EditBox : EditWidgetBase { case SelectUp: if (_caretPos.line > 0) { _caretPos.line--; + correctCaretPos(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); ensureCaretVisible(); } @@ -2398,6 +2399,7 @@ class EditBox : EditWidgetBase { case SelectDown: if (_caretPos.line < _content.length - 1) { _caretPos.line++; + correctCaretPos(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); ensureCaretVisible(); } @@ -2407,6 +2409,7 @@ class EditBox : EditWidgetBase { { ensureCaretVisible(); _caretPos.line = _firstVisibleLine; + correctCaretPos(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); } return true; @@ -2419,6 +2422,7 @@ class EditBox : EditWidgetBase { if (newpos >= _content.length) newpos = _content.length - 1; _caretPos.line = newpos; + correctCaretPos(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); } return true; @@ -2436,6 +2440,7 @@ class EditBox : EditWidgetBase { _firstVisibleLine = newpos; _caretPos.line -= delta; } + correctCaretPos(); measureVisibleText(); updateScrollBars(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); @@ -2454,6 +2459,7 @@ class EditBox : EditWidgetBase { _firstVisibleLine = newpos; _caretPos.line += delta; } + correctCaretPos(); measureVisibleText(); updateScrollBars(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); From 2da2f24f5845ba4592c7e45f6418fd9e3a54c877 Mon Sep 17 00:00:00 2001 From: 00schneider Date: Sun, 2 Oct 2016 09:52:31 +0200 Subject: [PATCH 2/2] Fix formatting (use spaces instead of tabs) --- src/dlangui/widgets/editors.d | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 67874e83..7cd203f2 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -2390,7 +2390,7 @@ class EditBox : EditWidgetBase { case SelectUp: if (_caretPos.line > 0) { _caretPos.line--; - correctCaretPos(); + correctCaretPos(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); ensureCaretVisible(); } @@ -2399,7 +2399,7 @@ class EditBox : EditWidgetBase { case SelectDown: if (_caretPos.line < _content.length - 1) { _caretPos.line++; - correctCaretPos(); + correctCaretPos(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); ensureCaretVisible(); } @@ -2409,7 +2409,7 @@ class EditBox : EditWidgetBase { { ensureCaretVisible(); _caretPos.line = _firstVisibleLine; - correctCaretPos(); + correctCaretPos(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); } return true; @@ -2422,7 +2422,7 @@ class EditBox : EditWidgetBase { if (newpos >= _content.length) newpos = _content.length - 1; _caretPos.line = newpos; - correctCaretPos(); + correctCaretPos(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); } return true; @@ -2440,7 +2440,7 @@ class EditBox : EditWidgetBase { _firstVisibleLine = newpos; _caretPos.line -= delta; } - correctCaretPos(); + correctCaretPos(); measureVisibleText(); updateScrollBars(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); @@ -2459,7 +2459,7 @@ class EditBox : EditWidgetBase { _firstVisibleLine = newpos; _caretPos.line += delta; } - correctCaretPos(); + correctCaretPos(); measureVisibleText(); updateScrollBars(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0);