Skip to content

Commit effb181

Browse files
authored
Fix CodeEditor indent bug (surge-synthesizer#7922)
Also faster mousewheeling
1 parent 9df9f5f commit effb181

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/surge-xt/gui/overlays/LuaEditors.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,24 @@ void SurgeCodeEditorComponent::caretPositionMoved()
791791
}
792792
}
793793

794+
void SurgeCodeEditorComponent::mouseWheelMove(const juce::MouseEvent &e,
795+
const juce::MouseWheelDetails &wheel)
796+
{
797+
juce::MouseWheelDetails w(wheel);
798+
w.deltaY *= 4;
799+
CodeEditorComponent::mouseWheelMove(e, w);
800+
}
801+
794802
// Handles auto indentation
795803

796804
void SurgeCodeEditorComponent::handleReturnKey()
797805
{
798-
799806
auto pos = this->getCaretPos();
800807
auto txt = pos.getLineText();
801808
int tabs = 0;
802-
809+
int indexInLine = pos.getIndexInLine();
810+
int actualCharactersBeforeCaret = 0;
811+
bool indent = false;
803812
for (int i = 0; i < txt.length(); i++)
804813
{
805814
if (txt.substring(i, i + 1) == " ")
@@ -812,7 +821,7 @@ void SurgeCodeEditorComponent::handleReturnKey()
812821
}
813822
else
814823
{
815-
bool indent = false;
824+
816825
auto trimmedTxt = txt.trim();
817826

818827
if (txt.substring(i, i + 8) == "function")
@@ -839,10 +848,17 @@ void SurgeCodeEditorComponent::handleReturnKey()
839848

840849
break;
841850
}
851+
852+
if (i < indexInLine)
853+
{
854+
actualCharactersBeforeCaret = tabs;
855+
}
842856
}
843857

844858
this->insertTextAtCaret("\n");
845-
this->insertTextAtCaret(std::string(tabs, ' '));
859+
this->insertTextAtCaret(std::string(
860+
std::min(actualCharactersBeforeCaret + (indent == true ? this->getTabSize() : 0), tabs),
861+
' '));
846862
}
847863

848864
struct EditorColors
@@ -1135,7 +1151,6 @@ bool CodeEditorContainerWithApply::autoCompleteStringDeclaration(juce::String st
11351151
mainEditor->insertTextAtCaret(str);
11361152
}
11371153
return true;
1138-
// sdfsd
11391154
}
11401155

11411156
void CodeEditorContainerWithApply::paint(juce::Graphics &g) { g.fillAll(juce::Colours::black); }
@@ -3003,4 +3018,4 @@ WavetableScriptEditor::getPreCloseChickenBoxMessage()
30033018
}
30043019

30053020
} // namespace Overlays
3006-
} // namespace Surge
3021+
} // namespace Surge

src/surge-xt/gui/overlays/LuaEditors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class SurgeCodeEditorComponent : public juce::CodeEditorComponent
199199
virtual void paint(juce::Graphics &) override;
200200
virtual void setSearch(CodeEditorSearch &s);
201201
virtual void setGotoLine(GotoLine &s);
202+
void mouseWheelMove(const juce::MouseEvent &e, const juce::MouseWheelDetails &d) override;
202203
SurgeCodeEditorComponent(juce::CodeDocument &d, juce::CodeTokeniser *t,
203204
Surge::GUI::Skin::ptr_t &skin);
204205

0 commit comments

Comments
 (0)