Skip to content

Commit e612bfc

Browse files
authored
More code editor tweaks (surge-synthesizer#7946)
Consistent kbd shortcut designation in context menu (Ctrl instead of CTRL, use Mac symbol for Cmd instead of CMD) Only allow numerical input in Go to Line Clean up unnecessary empty lines in places
1 parent cf87ac7 commit e612bfc

File tree

2 files changed

+21
-42
lines changed

2 files changed

+21
-42
lines changed

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

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,12 @@ void TextfieldPopup::resize()
342342
GotoLine::GotoLine(juce::CodeEditorComponent &editor, Surge::GUI::Skin::ptr_t skin)
343343
: TextfieldPopup(editor, skin)
344344
{
345-
346345
STYLE_MARGIN_BETWEEN_TEXT_AND_BUTTONS = 0;
347346
// close
348347
createButton({R"(
349348
<svg height="24" width="24" fill="#FFFFFF"><path fill="none" d="m 0.07087901,-959.94314 23.93899499,-0.002 v 23.939 l -23.85812279,-0.0801 z"/><path d="m 8.2546475,-942.56172 -1.1099577,-1.10942 4.4397962,-4.44028 -4.4397962,-4.43942 1.1099577,-1.11028 4.4398655,4.44028 4.439762,-4.44028 1.110026,1.11028 -4.439848,4.43942 4.439848,4.44028 -1.110026,1.10942 -4.439762,-4.43942 z"/></svg>)"},
350349
0);
351-
setHeader("Go to line...");
350+
setHeader("Go to line");
352351
setTextWidth(130);
353352
}
354353

@@ -372,7 +371,6 @@ bool GotoLine::keyPressed(const juce::KeyPress &key, juce::Component *originatin
372371
}
373372
else
374373
{
375-
376374
int line = std::max(0, textfield[0]->getText().getIntValue() - 1);
377375
line = std::min(ed->getDocument().getNumLines(), line);
378376

@@ -395,6 +393,7 @@ void GotoLine::show()
395393
{
396394
currentLine = ed->getCaretPos().getLineNumber();
397395
textfield[0]->setText("");
396+
textfield[0]->setInputRestrictions(4, "0123456789");
398397
TextfieldPopup::show();
399398
startCaretPosition = ed->getCaretPos();
400399
startScroll = ed->getFirstLineOnScreen();
@@ -407,9 +406,11 @@ void GotoLine::hide()
407406
}
408407

409408
void GotoLine::focusLost(FocusChangeType) { hide(); }
409+
410410
int GotoLine::getCurrentLine() { return currentLine; }
411411

412412
void GotoLine::onClick(std::unique_ptr<TextfieldButton> &btn) { hide(); }
413+
413414
/*
414415
---------------------------------------
415416
Search box
@@ -419,7 +420,6 @@ Search box
419420
CodeEditorSearch::CodeEditorSearch(juce::CodeEditorComponent &editor, Surge::GUI::Skin::ptr_t skin)
420421
: TextfieldPopup(editor, skin)
421422
{
422-
423423
setTextWidth(110);
424424
setButtonOffsetAtRow(1, -STYLE_MARGIN_BETWEEN_TEXT_AND_BUTTONS);
425425

@@ -459,10 +459,10 @@ CodeEditorSearch::CodeEditorSearch(juce::CodeEditorComponent &editor, Surge::GUI
459459
<svg height="24" width="24" fill="#FFFFFF"><path fill="none" d="m 0.07087901,-959.94314 23.93899499,-0.002 v 23.939 l -23.85812279,-0.0801 z"/><path d="m 8.2546475,-942.56172 -1.1099577,-1.10942 4.4397962,-4.44028 -4.4397962,-4.43942 1.1099577,-1.11028 4.4398655,4.44028 4.439762,-4.44028 1.110026,1.11028 -4.439848,4.43942 4.439848,4.44028 -1.110026,1.10942 -4.439762,-4.43942 z"/></svg>)"},
460460
0);
461461

462-
setHeader("Find...");
462+
setHeader("Find");
463463

464464
createTextfield(1);
465-
textfield[1]->setHeader("Replace..");
465+
textfield[1]->setHeader("Replace");
466466

467467
// showRows(2);
468468

@@ -514,17 +514,15 @@ void CodeEditorSearch::onClick(std::unique_ptr<TextfieldButton> &btn)
514514
}
515515

516516
int *CodeEditorSearch::getResult() { return result; }
517-
int CodeEditorSearch::getResultTotal() { return resultTotal; }
518517

519-
// void CodeEditorSearch::paint(juce::Graphics &g) {}
518+
int CodeEditorSearch::getResultTotal() { return resultTotal; }
520519

521520
bool CodeEditorSearch::isActive() { return active; }
522521

523522
void CodeEditorSearch::mouseDown(const juce::MouseEvent &event) { saveCaretStartPosition(true); }
524523

525524
void CodeEditorSearch::saveCaretStartPosition(bool onlyReadCaretPosition)
526525
{
527-
528526
if (!ed->isReadOnly())
529527
{
530528
if (!saveCaretStartPositionLock &&
@@ -535,7 +533,6 @@ void CodeEditorSearch::saveCaretStartPosition(bool onlyReadCaretPosition)
535533

536534
if (sel.getEnd() - sel.getStart() != 0)
537535
{
538-
539536
// move caret to beginning of selected
540537
if (ed->getCaretPosition() > sel.getStart())
541538
{
@@ -579,6 +576,7 @@ void CodeEditorSearch::removeHighlightColors()
579576
void CodeEditorSearch::show()
580577
{
581578
TextfieldPopup::show();
579+
582580
// set selected text as search query unless it includes a newline character
583581
auto sel = ed->getHighlightedRegion();
584582
juce::String txt = ed->getTextInRange(sel);
@@ -606,11 +604,11 @@ void CodeEditorSearch::hide()
606604
}
607605

608606
void CodeEditorSearch::textEditorEscapeKeyPressed(juce::TextEditor &) { hide(); }
607+
609608
void CodeEditorSearch::textEditorReturnKeyPressed(juce::TextEditor &) {}
610609

611610
bool CodeEditorSearch::keyPressed(const juce::KeyPress &key, juce::Component *originatingComponent)
612611
{
613-
614612
auto keyCode = key.getKeyCode();
615613

616614
if (key.getKeyCode() == key.tabKey && rowsVisible > 1)
@@ -636,7 +634,6 @@ bool CodeEditorSearch::keyPressed(const juce::KeyPress &key, juce::Component *or
636634
// next / previous search
637635
if (originatingComponent == textfield[0].get())
638636
{
639-
640637
if (key.getModifiers().isShiftDown())
641638
{
642639
showResult(-1, true);
@@ -683,7 +680,6 @@ void CodeEditorSearch::replaceResults(bool all)
683680

684681
while (resultTotal > 0)
685682
{
686-
687683
replaceCurrentResult(textfield[1]->getText());
688684
}
689685
}
@@ -696,7 +692,6 @@ void CodeEditorSearch::replaceResults(bool all)
696692

697693
void CodeEditorSearch::replaceCurrentResult(juce::String txt)
698694
{
699-
700695
if (resultTotal != 0)
701696
{
702697
ed->getDocument().replaceSection(
@@ -722,7 +717,6 @@ void CodeEditorSearch::replaceCurrentResult(juce::String txt)
722717

723718
void CodeEditorSearch::textEditorTextChanged(juce::TextEditor &textEditor)
724719
{
725-
726720
juce::TextEditor *other = dynamic_cast<juce::TextEditor *>(textfield[0].get());
727721

728722
if (&textEditor == other)
@@ -743,7 +737,6 @@ void CodeEditorSearch::showResult(int increment, bool moveCaret)
743737

744738
if (resultTotal == 0)
745739
{
746-
747740
auto bgColor = currentSkin->getColor(Colors::FormulaEditor::Background).darker(1.3);
748741

749742
labelResult->setColour(
@@ -857,7 +850,6 @@ juce::String CodeEditorSearch::getSearchQuery() { return textfield[0]->getText()
857850

858851
void CodeEditorSearch::showReplace(bool showReplaceRow)
859852
{
860-
861853
if (showReplaceRow)
862854
{
863855
showRows(2);
@@ -894,31 +886,32 @@ void SurgeCodeEditorComponent::addPopupMenuItems(juce::PopupMenu &menuToAddTo,
894886
juce::CodeEditorComponent::addPopupMenuItems(menuToAddTo, mouseClickEvent);
895887

896888
#if MAC
897-
std::string commandStr = "CMD";
889+
std::string commandStr = u8"\U00002318";
898890

899891
#else
900-
std::string commandStr = "CTRL";
892+
std::string commandStr = "Ctrl";
901893
#endif
902894

903-
auto find = juce::PopupMenu::Item("Find").setAction([this]() {
895+
auto find = juce::PopupMenu::Item("Find...").setAction([this]() {
904896
search->show();
905897
search->showReplace(false);
906898
gotoLine->hide();
907899
});
908-
find.shortcutKeyDescription = commandStr + "+F";
900+
find.shortcutKeyDescription = commandStr + " + F";
909901

910-
auto replace = juce::PopupMenu::Item("Replace").setAction([this]() {
902+
auto replace = juce::PopupMenu::Item("Replace...").setAction([this]() {
911903
search->show();
912904
search->showReplace(true);
913905
gotoLine->hide();
914906
});
915-
replace.shortcutKeyDescription = commandStr + "+H";
907+
replace.shortcutKeyDescription = commandStr + " + H";
916908

917-
auto gotoline = juce::PopupMenu::Item("Go to line").setAction([this]() {
918-
search->hide();
919-
gotoLine->show();
920-
});
921-
gotoline.shortcutKeyDescription = commandStr + "+G";
909+
auto gotoline =
910+
juce::PopupMenu::Item(Surge::GUI::toOSCase("Go to Line...")).setAction([this]() {
911+
search->hide();
912+
gotoLine->show();
913+
});
914+
gotoline.shortcutKeyDescription = commandStr + " + G";
922915

923916
menuToAddTo.addSeparator();
924917

@@ -940,7 +933,6 @@ void SurgeCodeEditorComponent::addPopupMenuItems(juce::PopupMenu &menuToAddTo,
940933

941934
bool SurgeCodeEditorComponent::keyPressed(const juce::KeyPress &key)
942935
{
943-
944936
bool code = CodeEditorComponent::keyPressed(key);
945937

946938
// update search results
@@ -1003,13 +995,11 @@ void SurgeCodeEditorComponent::paint(juce::Graphics &g)
1003995

1004996
for (int i = 0; i < resultTotal; i++)
1005997
{
1006-
1007998
auto pos = juce::CodeDocument::Position(getDocument(), result[i]);
1008999
auto line = pos.getLineNumber();
10091000

10101001
if (line >= firstLine && line <= lastLine)
10111002
{
1012-
10131003
auto posEnd = juce::CodeDocument::Position(
10141004
getDocument(), result[i] + search->getSearchQuery().length());
10151005

@@ -1036,14 +1026,11 @@ void SurgeCodeEditorComponent::paint(juce::Graphics &g)
10361026

10371027
void SurgeCodeEditorComponent::paintOverChildren(juce::Graphics &g)
10381028
{
1039-
10401029
// Draw search map on scrollbar only when result has changed and cache the result
10411030
if (search != nullptr && search->isVisible())
10421031
{
1043-
10441032
if (search->resultHasChanged)
10451033
{
1046-
10471034
auto result = search->getResult();
10481035
int resultTotal = search->getResultTotal();
10491036

@@ -1155,12 +1142,10 @@ void SurgeCodeEditorComponent::handleReturnKey()
11551142
}
11561143
else
11571144
{
1158-
11591145
auto trimmedTxt = txt.trim();
11601146

11611147
if (txt.substring(i, i + 8) == "function")
11621148
{
1163-
11641149
indent = true;
11651150
}
11661151
else if (txt.substring(i, i + 2) == "if" &&
@@ -1403,7 +1388,6 @@ bool CodeEditorContainerWithApply::keyPressed(const juce::KeyPress &key, juce::C
14031388
// go to line
14041389
else if (key.getModifiers().isCommandDown() && keyCode == 71)
14051390
{
1406-
14071391
bool isgoto = (gotoLine == nullptr);
14081392

14091393
search->hide();
@@ -1453,7 +1437,6 @@ bool CodeEditorContainerWithApply::keyPressed(const juce::KeyPress &key, juce::C
14531437
}
14541438
else
14551439
{
1456-
14571440
return Component::keyPressed(key);
14581441
}
14591442

@@ -1502,7 +1485,6 @@ void CodeEditorContainerWithApply::removeTrailingWhitespaceFromDocument()
15021485
bool CodeEditorContainerWithApply::autoCompleteDeclaration(juce::KeyPress key, std::string start,
15031486
std::string end)
15041487
{
1505-
15061488
auto keyChar = juce::String::charToString((key.getTextCharacter())).toStdString();
15071489

15081490
if (keyChar != start && keyChar != end && key.getKeyCode() != 8)
@@ -1527,7 +1509,6 @@ bool CodeEditorContainerWithApply::autoCompleteDeclaration(juce::KeyPress key, s
15271509
// auto delete closure
15281510
if (key.getKeyCode() == 8)
15291511
{
1530-
15311512
if (selection == 0)
15321513
{
15331514
auto charBefore = text.substring(caretPosition - 1, caretPosition).toStdString();
@@ -1556,7 +1537,6 @@ bool CodeEditorContainerWithApply::autoCompleteDeclaration(juce::KeyPress key, s
15561537

15571538
if (start != end)
15581539
{
1559-
15601540
if (character == start)
15611541
count++;
15621542
if (character == end)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ class TextfieldPopup : public juce::Component,
114114
protected:
115115
juce::CodeEditorComponent *ed;
116116
Surge::GUI::Skin::ptr_t currentSkin;
117-
// std::unique_ptr<Textfield> *textfield;
118117
std::unique_ptr<juce::Label> labelResult;
119118

120119
std::unique_ptr<TextfieldButton> button[8];

0 commit comments

Comments
 (0)