Skip to content

Commit

Permalink
Fix CodeEditor indent bug (surge-synthesizer#7922)
Browse files Browse the repository at this point in the history
Also faster mousewheeling
  • Loading branch information
blancoberg authored Dec 14, 2024
1 parent 9df9f5f commit effb181
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/surge-xt/gui/overlays/LuaEditors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,15 +791,24 @@ void SurgeCodeEditorComponent::caretPositionMoved()
}
}

void SurgeCodeEditorComponent::mouseWheelMove(const juce::MouseEvent &e,
const juce::MouseWheelDetails &wheel)
{
juce::MouseWheelDetails w(wheel);
w.deltaY *= 4;
CodeEditorComponent::mouseWheelMove(e, w);
}

// Handles auto indentation

void SurgeCodeEditorComponent::handleReturnKey()
{

auto pos = this->getCaretPos();
auto txt = pos.getLineText();
int tabs = 0;

int indexInLine = pos.getIndexInLine();
int actualCharactersBeforeCaret = 0;
bool indent = false;
for (int i = 0; i < txt.length(); i++)
{
if (txt.substring(i, i + 1) == " ")
Expand All @@ -812,7 +821,7 @@ void SurgeCodeEditorComponent::handleReturnKey()
}
else
{
bool indent = false;

auto trimmedTxt = txt.trim();

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

break;
}

if (i < indexInLine)
{
actualCharactersBeforeCaret = tabs;
}
}

this->insertTextAtCaret("\n");
this->insertTextAtCaret(std::string(tabs, ' '));
this->insertTextAtCaret(std::string(
std::min(actualCharactersBeforeCaret + (indent == true ? this->getTabSize() : 0), tabs),
' '));
}

struct EditorColors
Expand Down Expand Up @@ -1135,7 +1151,6 @@ bool CodeEditorContainerWithApply::autoCompleteStringDeclaration(juce::String st
mainEditor->insertTextAtCaret(str);
}
return true;
// sdfsd
}

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

} // namespace Overlays
} // namespace Surge
} // namespace Surge
1 change: 1 addition & 0 deletions src/surge-xt/gui/overlays/LuaEditors.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class SurgeCodeEditorComponent : public juce::CodeEditorComponent
virtual void paint(juce::Graphics &) override;
virtual void setSearch(CodeEditorSearch &s);
virtual void setGotoLine(GotoLine &s);
void mouseWheelMove(const juce::MouseEvent &e, const juce::MouseWheelDetails &d) override;
SurgeCodeEditorComponent(juce::CodeDocument &d, juce::CodeTokeniser *t,
Surge::GUI::Skin::ptr_t &skin);

Expand Down

0 comments on commit effb181

Please sign in to comment.