From d139378291624559f3bf1e4a21ebaacc08b49919 Mon Sep 17 00:00:00 2001 From: blancoberg Date: Fri, 3 Jan 2025 09:54:24 +0100 Subject: [PATCH 1/3] scroll and select * Makes it possible to mousewheel scroll and select text at the same time. * Shift + mousewheel scrolls sideways --- src/surge-xt/gui/overlays/LuaEditors.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/surge-xt/gui/overlays/LuaEditors.cpp b/src/surge-xt/gui/overlays/LuaEditors.cpp index 2a649faf60a..f56aec8af6a 100644 --- a/src/surge-xt/gui/overlays/LuaEditors.cpp +++ b/src/surge-xt/gui/overlays/LuaEditors.cpp @@ -1117,7 +1117,18 @@ void SurgeCodeEditorComponent::mouseWheelMove(const juce::MouseEvent &e, { juce::MouseWheelDetails w(wheel); w.deltaY *= 4; - CodeEditorComponent::mouseWheelMove(e, w); + + // makes it possible to mouse wheel scroll and select text at the same time + if (e.mods.isShiftDown()) + { + auto scrollbar = dynamic_cast(getChildren()[1]); + auto pos = scrollbar->getCurrentRange().getStart(); + scrollToColumn(pos - w.deltaY * 10); + } + else + { + scrollBy(-w.deltaY * 10); + } } // Handles auto indentation From d520d74271f6da782f1eb0eeb06ee937a3ba9a0b Mon Sep 17 00:00:00 2001 From: blancoberg Date: Fri, 3 Jan 2025 15:01:02 +0100 Subject: [PATCH 2/3] editor scroll update It turns out that scrollBy() sucks. It scrolls way past its maximum scroll value. --- src/surge-xt/gui/overlays/LuaEditors.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/surge-xt/gui/overlays/LuaEditors.cpp b/src/surge-xt/gui/overlays/LuaEditors.cpp index f56aec8af6a..2dc56a219f7 100644 --- a/src/surge-xt/gui/overlays/LuaEditors.cpp +++ b/src/surge-xt/gui/overlays/LuaEditors.cpp @@ -1123,11 +1123,19 @@ void SurgeCodeEditorComponent::mouseWheelMove(const juce::MouseEvent &e, { auto scrollbar = dynamic_cast(getChildren()[1]); auto pos = scrollbar->getCurrentRange().getStart(); - scrollToColumn(pos - w.deltaY * 10); + + auto width = scrollbar->getCurrentRangeSize(); + auto maxScroll = std::max((double)0, scrollbar->getMaximumRangeLimit() - width); + + scrollToColumn(std::min((double)maxScroll, pos - w.deltaY * 10)); } else { - scrollBy(-w.deltaY * 10); + auto scrollbar = dynamic_cast(getChildren()[0]); + auto maxScroll = std::max(0, getDocument().getNumLines() - getNumLinesOnScreen()); + auto scrollPos = getFirstLineOnScreen(); + + scrollToLine(std::min((double)maxScroll, (double)scrollPos - w.deltaY * 10)); } } From fbb0fe5d1f8c10434d5be4bc1f6f32ba83b56bd4 Mon Sep 17 00:00:00 2001 From: blancoberg Date: Fri, 3 Jan 2025 17:00:30 +0100 Subject: [PATCH 3/3] some fixes Added enum for clearity (hopefully) Null check on scrollbars --- src/surge-xt/gui/overlays/LuaEditors.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/surge-xt/gui/overlays/LuaEditors.cpp b/src/surge-xt/gui/overlays/LuaEditors.cpp index 2dc56a219f7..713a8d55de1 100644 --- a/src/surge-xt/gui/overlays/LuaEditors.cpp +++ b/src/surge-xt/gui/overlays/LuaEditors.cpp @@ -1118,20 +1118,28 @@ void SurgeCodeEditorComponent::mouseWheelMove(const juce::MouseEvent &e, juce::MouseWheelDetails w(wheel); w.deltaY *= 4; + enum + { + verticalScrollbar, + horizontalScrollbar + }; + // makes it possible to mouse wheel scroll and select text at the same time if (e.mods.isShiftDown()) { - auto scrollbar = dynamic_cast(getChildren()[1]); - auto pos = scrollbar->getCurrentRange().getStart(); + auto scrollbar = dynamic_cast(getChildren()[horizontalScrollbar]); - auto width = scrollbar->getCurrentRangeSize(); - auto maxScroll = std::max((double)0, scrollbar->getMaximumRangeLimit() - width); + if (scrollbar != nullptr) + { + auto pos = scrollbar->getCurrentRange().getStart(); + auto width = scrollbar->getCurrentRangeSize(); + auto maxScroll = std::max((double)0, scrollbar->getMaximumRangeLimit() - width); - scrollToColumn(std::min((double)maxScroll, pos - w.deltaY * 10)); + scrollToColumn(std::min((double)maxScroll, pos - w.deltaY * 10)); + } } else { - auto scrollbar = dynamic_cast(getChildren()[0]); auto maxScroll = std::max(0, getDocument().getNumLines() - getNumLinesOnScreen()); auto scrollPos = getFirstLineOnScreen();