From 9138d35a1087b5176f13b64a0ed5a434e4c6aee9 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 7 Sep 2017 12:02:24 +0300 Subject: [PATCH] clear selection on home/end key if needed - close #421 --- src/dlangui/widgets/editors.d | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index e33f8396..a0e229fb 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -1247,6 +1247,12 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction return _content.lineRange(_caretPos.line); } + /// clears selection (don't change text, just unselect) + void clearSelection() { + _selectionRange = TextRange(_caretPos, _caretPos); + invalidate(); + } + protected bool removeRangeText(TextRange range) { if (range.empty) return false; @@ -1390,6 +1396,9 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction _caretPos.pos = space.firstNonSpaceIndex; ensureCaretVisible(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); + if (a.id == EditorActions.LineBegin && _caretPos == oldCaretPos) { + clearSelection(); + } } return true; case DocumentEnd: @@ -1407,6 +1416,8 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction _caretPos.pos = cast(int)currentLine.length; ensureCaretVisible(); updateSelectionAfterCursorMovement(oldCaretPos, (a.id & 1) != 0); + } else if (a.id == EditorActions.LineEnd) { + clearSelection(); } return true; case DelPrevWord: