@@ -342,13 +342,12 @@ void TextfieldPopup::resize()
342
342
GotoLine::GotoLine (juce::CodeEditorComponent &editor, Surge::GUI::Skin::ptr_t skin)
343
343
: TextfieldPopup(editor, skin)
344
344
{
345
-
346
345
STYLE_MARGIN_BETWEEN_TEXT_AND_BUTTONS = 0 ;
347
346
// close
348
347
createButton ({R"(
349
348
<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>)" },
350
349
0 );
351
- setHeader (" Go to line... " );
350
+ setHeader (" Go to line" );
352
351
setTextWidth (130 );
353
352
}
354
353
@@ -372,7 +371,6 @@ bool GotoLine::keyPressed(const juce::KeyPress &key, juce::Component *originatin
372
371
}
373
372
else
374
373
{
375
-
376
374
int line = std::max (0 , textfield[0 ]->getText ().getIntValue () - 1 );
377
375
line = std::min (ed->getDocument ().getNumLines (), line);
378
376
@@ -395,6 +393,7 @@ void GotoLine::show()
395
393
{
396
394
currentLine = ed->getCaretPos ().getLineNumber ();
397
395
textfield[0 ]->setText (" " );
396
+ textfield[0 ]->setInputRestrictions (4 , " 0123456789" );
398
397
TextfieldPopup::show ();
399
398
startCaretPosition = ed->getCaretPos ();
400
399
startScroll = ed->getFirstLineOnScreen ();
@@ -407,9 +406,11 @@ void GotoLine::hide()
407
406
}
408
407
409
408
void GotoLine::focusLost (FocusChangeType) { hide (); }
409
+
410
410
int GotoLine::getCurrentLine () { return currentLine; }
411
411
412
412
void GotoLine::onClick (std::unique_ptr<TextfieldButton> &btn) { hide (); }
413
+
413
414
/*
414
415
---------------------------------------
415
416
Search box
@@ -419,7 +420,6 @@ Search box
419
420
CodeEditorSearch::CodeEditorSearch (juce::CodeEditorComponent &editor, Surge::GUI::Skin::ptr_t skin)
420
421
: TextfieldPopup(editor, skin)
421
422
{
422
-
423
423
setTextWidth (110 );
424
424
setButtonOffsetAtRow (1 , -STYLE_MARGIN_BETWEEN_TEXT_AND_BUTTONS);
425
425
@@ -459,10 +459,10 @@ CodeEditorSearch::CodeEditorSearch(juce::CodeEditorComponent &editor, Surge::GUI
459
459
<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>)" },
460
460
0 );
461
461
462
- setHeader (" Find... " );
462
+ setHeader (" Find" );
463
463
464
464
createTextfield (1 );
465
- textfield[1 ]->setHeader (" Replace.. " );
465
+ textfield[1 ]->setHeader (" Replace" );
466
466
467
467
// showRows(2);
468
468
@@ -514,17 +514,15 @@ void CodeEditorSearch::onClick(std::unique_ptr<TextfieldButton> &btn)
514
514
}
515
515
516
516
int *CodeEditorSearch::getResult () { return result; }
517
- int CodeEditorSearch::getResultTotal () { return resultTotal; }
518
517
519
- // void CodeEditorSearch::paint(juce::Graphics &g ) {}
518
+ int CodeEditorSearch::getResultTotal ( ) { return resultTotal; }
520
519
521
520
bool CodeEditorSearch::isActive () { return active; }
522
521
523
522
void CodeEditorSearch::mouseDown (const juce::MouseEvent &event) { saveCaretStartPosition (true ); }
524
523
525
524
void CodeEditorSearch::saveCaretStartPosition (bool onlyReadCaretPosition)
526
525
{
527
-
528
526
if (!ed->isReadOnly ())
529
527
{
530
528
if (!saveCaretStartPositionLock &&
@@ -535,7 +533,6 @@ void CodeEditorSearch::saveCaretStartPosition(bool onlyReadCaretPosition)
535
533
536
534
if (sel.getEnd () - sel.getStart () != 0 )
537
535
{
538
-
539
536
// move caret to beginning of selected
540
537
if (ed->getCaretPosition () > sel.getStart ())
541
538
{
@@ -579,6 +576,7 @@ void CodeEditorSearch::removeHighlightColors()
579
576
void CodeEditorSearch::show ()
580
577
{
581
578
TextfieldPopup::show ();
579
+
582
580
// set selected text as search query unless it includes a newline character
583
581
auto sel = ed->getHighlightedRegion ();
584
582
juce::String txt = ed->getTextInRange (sel);
@@ -606,11 +604,11 @@ void CodeEditorSearch::hide()
606
604
}
607
605
608
606
void CodeEditorSearch::textEditorEscapeKeyPressed (juce::TextEditor &) { hide (); }
607
+
609
608
void CodeEditorSearch::textEditorReturnKeyPressed (juce::TextEditor &) {}
610
609
611
610
bool CodeEditorSearch::keyPressed (const juce::KeyPress &key, juce::Component *originatingComponent)
612
611
{
613
-
614
612
auto keyCode = key.getKeyCode ();
615
613
616
614
if (key.getKeyCode () == key.tabKey && rowsVisible > 1 )
@@ -636,7 +634,6 @@ bool CodeEditorSearch::keyPressed(const juce::KeyPress &key, juce::Component *or
636
634
// next / previous search
637
635
if (originatingComponent == textfield[0 ].get ())
638
636
{
639
-
640
637
if (key.getModifiers ().isShiftDown ())
641
638
{
642
639
showResult (-1 , true );
@@ -683,7 +680,6 @@ void CodeEditorSearch::replaceResults(bool all)
683
680
684
681
while (resultTotal > 0 )
685
682
{
686
-
687
683
replaceCurrentResult (textfield[1 ]->getText ());
688
684
}
689
685
}
@@ -696,7 +692,6 @@ void CodeEditorSearch::replaceResults(bool all)
696
692
697
693
void CodeEditorSearch::replaceCurrentResult (juce::String txt)
698
694
{
699
-
700
695
if (resultTotal != 0 )
701
696
{
702
697
ed->getDocument ().replaceSection (
@@ -722,7 +717,6 @@ void CodeEditorSearch::replaceCurrentResult(juce::String txt)
722
717
723
718
void CodeEditorSearch::textEditorTextChanged (juce::TextEditor &textEditor)
724
719
{
725
-
726
720
juce::TextEditor *other = dynamic_cast <juce::TextEditor *>(textfield[0 ].get ());
727
721
728
722
if (&textEditor == other)
@@ -743,7 +737,6 @@ void CodeEditorSearch::showResult(int increment, bool moveCaret)
743
737
744
738
if (resultTotal == 0 )
745
739
{
746
-
747
740
auto bgColor = currentSkin->getColor (Colors::FormulaEditor::Background).darker (1.3 );
748
741
749
742
labelResult->setColour (
@@ -857,7 +850,6 @@ juce::String CodeEditorSearch::getSearchQuery() { return textfield[0]->getText()
857
850
858
851
void CodeEditorSearch::showReplace (bool showReplaceRow)
859
852
{
860
-
861
853
if (showReplaceRow)
862
854
{
863
855
showRows (2 );
@@ -894,31 +886,32 @@ void SurgeCodeEditorComponent::addPopupMenuItems(juce::PopupMenu &menuToAddTo,
894
886
juce::CodeEditorComponent::addPopupMenuItems (menuToAddTo, mouseClickEvent);
895
887
896
888
#if MAC
897
- std::string commandStr = " CMD " ;
889
+ std::string commandStr = u8" \U00002318 " ;
898
890
899
891
#else
900
- std::string commandStr = " CTRL " ;
892
+ std::string commandStr = " Ctrl " ;
901
893
#endif
902
894
903
- auto find = juce::PopupMenu::Item (" Find" ).setAction ([this ]() {
895
+ auto find = juce::PopupMenu::Item (" Find... " ).setAction ([this ]() {
904
896
search->show ();
905
897
search->showReplace (false );
906
898
gotoLine->hide ();
907
899
});
908
- find.shortcutKeyDescription = commandStr + " + F" ;
900
+ find.shortcutKeyDescription = commandStr + " + F" ;
909
901
910
- auto replace = juce::PopupMenu::Item (" Replace" ).setAction ([this ]() {
902
+ auto replace = juce::PopupMenu::Item (" Replace... " ).setAction ([this ]() {
911
903
search->show ();
912
904
search->showReplace (true );
913
905
gotoLine->hide ();
914
906
});
915
- replace.shortcutKeyDescription = commandStr + " + H" ;
907
+ replace.shortcutKeyDescription = commandStr + " + H" ;
916
908
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" ;
922
915
923
916
menuToAddTo.addSeparator ();
924
917
@@ -940,7 +933,6 @@ void SurgeCodeEditorComponent::addPopupMenuItems(juce::PopupMenu &menuToAddTo,
940
933
941
934
bool SurgeCodeEditorComponent::keyPressed (const juce::KeyPress &key)
942
935
{
943
-
944
936
bool code = CodeEditorComponent::keyPressed (key);
945
937
946
938
// update search results
@@ -1003,13 +995,11 @@ void SurgeCodeEditorComponent::paint(juce::Graphics &g)
1003
995
1004
996
for (int i = 0 ; i < resultTotal; i++)
1005
997
{
1006
-
1007
998
auto pos = juce::CodeDocument::Position (getDocument (), result[i]);
1008
999
auto line = pos.getLineNumber ();
1009
1000
1010
1001
if (line >= firstLine && line <= lastLine)
1011
1002
{
1012
-
1013
1003
auto posEnd = juce::CodeDocument::Position (
1014
1004
getDocument (), result[i] + search->getSearchQuery ().length ());
1015
1005
@@ -1036,14 +1026,11 @@ void SurgeCodeEditorComponent::paint(juce::Graphics &g)
1036
1026
1037
1027
void SurgeCodeEditorComponent::paintOverChildren (juce::Graphics &g)
1038
1028
{
1039
-
1040
1029
// Draw search map on scrollbar only when result has changed and cache the result
1041
1030
if (search != nullptr && search->isVisible ())
1042
1031
{
1043
-
1044
1032
if (search->resultHasChanged )
1045
1033
{
1046
-
1047
1034
auto result = search->getResult ();
1048
1035
int resultTotal = search->getResultTotal ();
1049
1036
@@ -1155,12 +1142,10 @@ void SurgeCodeEditorComponent::handleReturnKey()
1155
1142
}
1156
1143
else
1157
1144
{
1158
-
1159
1145
auto trimmedTxt = txt.trim ();
1160
1146
1161
1147
if (txt.substring (i, i + 8 ) == " function" )
1162
1148
{
1163
-
1164
1149
indent = true ;
1165
1150
}
1166
1151
else if (txt.substring (i, i + 2 ) == " if" &&
@@ -1403,7 +1388,6 @@ bool CodeEditorContainerWithApply::keyPressed(const juce::KeyPress &key, juce::C
1403
1388
// go to line
1404
1389
else if (key.getModifiers ().isCommandDown () && keyCode == 71 )
1405
1390
{
1406
-
1407
1391
bool isgoto = (gotoLine == nullptr );
1408
1392
1409
1393
search->hide ();
@@ -1453,7 +1437,6 @@ bool CodeEditorContainerWithApply::keyPressed(const juce::KeyPress &key, juce::C
1453
1437
}
1454
1438
else
1455
1439
{
1456
-
1457
1440
return Component::keyPressed (key);
1458
1441
}
1459
1442
@@ -1502,7 +1485,6 @@ void CodeEditorContainerWithApply::removeTrailingWhitespaceFromDocument()
1502
1485
bool CodeEditorContainerWithApply::autoCompleteDeclaration (juce::KeyPress key, std::string start,
1503
1486
std::string end)
1504
1487
{
1505
-
1506
1488
auto keyChar = juce::String::charToString ((key.getTextCharacter ())).toStdString ();
1507
1489
1508
1490
if (keyChar != start && keyChar != end && key.getKeyCode () != 8 )
@@ -1527,7 +1509,6 @@ bool CodeEditorContainerWithApply::autoCompleteDeclaration(juce::KeyPress key, s
1527
1509
// auto delete closure
1528
1510
if (key.getKeyCode () == 8 )
1529
1511
{
1530
-
1531
1512
if (selection == 0 )
1532
1513
{
1533
1514
auto charBefore = text.substring (caretPosition - 1 , caretPosition).toStdString ();
@@ -1556,7 +1537,6 @@ bool CodeEditorContainerWithApply::autoCompleteDeclaration(juce::KeyPress key, s
1556
1537
1557
1538
if (start != end)
1558
1539
{
1559
-
1560
1540
if (character == start)
1561
1541
count++;
1562
1542
if (character == end)
0 commit comments