Skip to content

Commit

Permalink
Fix #645, fix #673 (#674)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Ermiq authored Sep 15, 2023
1 parent 9e263cd commit 5fcb652
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
47 changes: 42 additions & 5 deletions src/dlangui/widgets/editors.d
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/dlangui/widgets/tabs.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5fcb652

Please sign in to comment.