From 5fcb6527ecc0a5921156489191aab1c2b550d849 Mon Sep 17 00:00:00 2001 From: Ermiq <58442318+Ermiq@users.noreply.github.com> Date: Fri, 15 Sep 2023 21:22:16 +0500 Subject: [PATCH] Fix #645, fix #673 (#674) * fix #645, fix #673 Fix #673 where the function `renameTab(string ID, dstring name)` in `src/dlangui/widgets/tabs.d` failed to find the tab with the given id because it uses the `TabControl`'s own id due to the misuse of lower/upper case names. Changed the function's argument `ID` that have never been used to `id`. Fix #645 where `EditWidgetBase` doesn't scroll when mouse selection is active and the cursor goes beyond the widget boundaries. Now it scrolls. Additionally, added new type of `EditorActions` to make 2 different types of `EditorActions.ScrollLineUp/Down`. The old `ScrollLineUp/Down` made 3 lines scrolling and it doesn't work well with new mouse selection scrolling when out of bounds (scrolls too fast). So now there are `ScrollLineUp/DownSingle` and `ScrollLineUp/DownTriple`. The single one is used by the mouse selection scrolling, the triple one used in all other cases just like before. * Original ScrollLineUp + ScrollLineUpSingle --- src/dlangui/widgets/editors.d | 47 +++++++++++++++++++++++++++++++---- src/dlangui/widgets/tabs.d | 2 +- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 9d66e8c3..2feec36e 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -180,8 +180,12 @@ enum EditorActions : int { // Scroll operations /// Scroll one line up (not changing cursor) - ScrollLineUp, + ScrollLineUpSingle, /// Scroll one line down (not changing cursor) + ScrollLineDownSingle, + /// Scroll three lines up (not changing cursor) + ScrollLineUp, + /// Scroll three lines down (not changing cursor) ScrollLineDown, /// Scroll one page up (not changing cursor) ScrollPageUp, @@ -817,8 +821,8 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction new Action(EditorActions.DocumentEnd, KeyCode.END, KeyFlag.Control, ActionStateUpdateFlag.never), new Action(EditorActions.SelectDocumentEnd, KeyCode.END, KeyFlag.Control | KeyFlag.Shift, ActionStateUpdateFlag.never), - new Action(EditorActions.ScrollLineUp, KeyCode.UP, KeyFlag.Control, ActionStateUpdateFlag.never), - new Action(EditorActions.ScrollLineDown, KeyCode.DOWN, KeyFlag.Control, ActionStateUpdateFlag.never), + new Action(EditorActions.ScrollLineUpSingle, KeyCode.UP, KeyFlag.Control, ActionStateUpdateFlag.never), + new Action(EditorActions.ScrollLineDownSingle, KeyCode.DOWN, KeyFlag.Control, ActionStateUpdateFlag.never), // Backspace/Del new Action(EditorActions.DelPrevChar, KeyCode.BACK, 0, ActionStateUpdateFlag.never), @@ -2205,6 +2209,12 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction } if (event.action == MouseAction.Move && (event.flags & MouseButton.Left) != 0) { updateCaretPositionByMouse(event.x - _clientRect.left, event.y - _clientRect.top, true); + if (event.y < _clientRect.top) { + handleAction(new Action(EditorActions.ScrollLineUpSingle)); + } + else if (event.y > _clientRect.bottom) { + handleAction(new Action(EditorActions.ScrollLineDownSingle)); + } return true; } if (event.action == MouseAction.Move && event.flags == 0) { @@ -2917,9 +2927,9 @@ class EditBox : EditWidgetBase { } else if (event.action == ScrollAction.PageDown) { dispatchAction(new Action(EditorActions.ScrollPageDown)); } else if (event.action == ScrollAction.LineUp) { - dispatchAction(new Action(EditorActions.ScrollLineUp)); + dispatchAction(new Action(EditorActions.ScrollLineUpSingle)); } else if (event.action == ScrollAction.LineDown) { - dispatchAction(new Action(EditorActions.ScrollLineDown)); + dispatchAction(new Action(EditorActions.ScrollLineDownSingle)); } return true; } @@ -3240,6 +3250,18 @@ class EditBox : EditWidgetBase { } } return true; + case ScrollLineUpSingle: + { + if (_firstVisibleLine > 0) { + _firstVisibleLine -= 1; + if (_firstVisibleLine < 0) + _firstVisibleLine = 0; + measureVisibleText(); + updateScrollBars(); + invalidate(); + } + } + return true; case ScrollPageUp: { int fullLines = _clientRect.height / _lineHeight; @@ -3268,6 +3290,21 @@ class EditBox : EditWidgetBase { } } return true; + case ScrollLineDownSingle: + { + int fullLines = _clientRect.height / _lineHeight; + if (_firstVisibleLine + fullLines < _content.length) { + _firstVisibleLine += 1; + if (_firstVisibleLine > _content.length - fullLines) + _firstVisibleLine = _content.length - fullLines; + if (_firstVisibleLine < 0) + _firstVisibleLine = 0; + measureVisibleText(); + updateScrollBars(); + invalidate(); + } + } + return true; case ScrollPageDown: { int fullLines = _clientRect.height / _lineHeight; diff --git a/src/dlangui/widgets/tabs.d b/src/dlangui/widgets/tabs.d index ecdf4ea3..fe638b7e 100644 --- a/src/dlangui/widgets/tabs.d +++ b/src/dlangui/widgets/tabs.d @@ -475,7 +475,7 @@ class TabControl : WidgetGroupDefaultDrawing { } /// change name of tab - void renameTab(string ID, dstring name) { + void renameTab(string id, dstring name) { int index = _items.indexById(id); if (index >= 0) { renameTab(index, name);