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.
This commit is contained in:
Ermiq 2023-09-14 20:50:00 +05:00 committed by GitHub
parent 9e263cdb7f
commit 6962190955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 11 deletions

View File

@ -180,9 +180,13 @@ enum EditorActions : int {
// Scroll operations
/// Scroll one line up (not changing cursor)
ScrollLineUp,
ScrollLineUpSingle,
/// Scroll one line down (not changing cursor)
ScrollLineDown,
ScrollLineDownSingle,
/// Scroll one line up (not changing cursor)
ScrollLineUpTriple,
/// Scroll one line down (not changing cursor)
ScrollLineDownTriple,
/// Scroll one page up (not changing cursor)
ScrollPageUp,
/// Scroll one page down (not changing cursor)
@ -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) {
@ -2236,13 +2246,13 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
return handleAction(new Action(EditorActions.ScrollRight));
if (keyFlags == MouseFlag.Control)
return handleAction(new Action(EditorActions.ZoomOut));
return handleAction(new Action(EditorActions.ScrollLineDown));
return handleAction(new Action(EditorActions.ScrollLineDownTriple));
} else if (event.wheelDelta > 0) {
if (keyFlags == MouseFlag.Shift)
return handleAction(new Action(EditorActions.ScrollLeft));
if (keyFlags == MouseFlag.Control)
return handleAction(new Action(EditorActions.ZoomIn));
return handleAction(new Action(EditorActions.ScrollLineUp));
return handleAction(new Action(EditorActions.ScrollLineUpTriple));
}
}
cancelHoverTimer();
@ -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;
}
@ -3228,7 +3238,19 @@ class EditBox : EditWidgetBase {
}
}
return true;
case ScrollLineUp:
case ScrollLineUpSingle:
{
if (_firstVisibleLine > 0) {
_firstVisibleLine -= 1;
if (_firstVisibleLine < 0)
_firstVisibleLine = 0;
measureVisibleText();
updateScrollBars();
invalidate();
}
}
return true;
case ScrollLineUpTriple:
{
if (_firstVisibleLine > 0) {
_firstVisibleLine -= 3;
@ -3253,7 +3275,22 @@ class EditBox : EditWidgetBase {
}
}
return true;
case ScrollLineDown:
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 ScrollLineDownTriple:
{
int fullLines = _clientRect.height / _lineHeight;
if (_firstVisibleLine + fullLines < _content.length) {

View File

@ -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);