Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CodeEditor indent bug #7922

Merged
merged 21 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/surge-xt/gui/overlays/LuaEditors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,15 +791,27 @@ void SurgeCodeEditorComponent::caretPositionMoved()
}
}

void SurgeCodeEditorComponent::mouseWheelMove(const juce::MouseEvent &e,
const juce::MouseWheelDetails &wheel)
{
auto modifiedMouseWheel = juce::MouseWheelDetails();
mkruselj marked this conversation as resolved.
Show resolved Hide resolved
juce::MouseWheelDetails w(wheel);
if (e.mods.isAltDown())
mkruselj marked this conversation as resolved.
Show resolved Hide resolved
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 +824,7 @@ void SurgeCodeEditorComponent::handleReturnKey()
}
else
{
bool indent = false;

auto trimmedTxt = txt.trim();

if (txt.substring(i, i + 8) == "function")
Expand All @@ -839,10 +851,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 +1154,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
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
Loading