Skip to content

Commit acfc53e

Browse files
committed
Implemented replace & replace all feature
1 parent b41a423 commit acfc53e

File tree

6 files changed

+70
-2
lines changed

6 files changed

+70
-2
lines changed

client/components/Nav.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class Nav extends React.PureComponent {
4141
this.handleFindNext = this.handleFindNext.bind(this);
4242
this.handleRun = this.handleRun.bind(this);
4343
this.handleFindPrevious = this.handleFindPrevious.bind(this);
44+
this.handleReplace = this.handleReplace.bind(this);
45+
this.handleReplaceAll = this.handleReplaceAll.bind(this);
4446
this.handleStop = this.handleStop.bind(this);
4547
this.handleStartAccessible = this.handleStartAccessible.bind(this);
4648
this.handleStopAccessible = this.handleStopAccessible.bind(this);
@@ -133,6 +135,16 @@ class Nav extends React.PureComponent {
133135
this.setDropdown('none');
134136
}
135137

138+
handleReplace() {
139+
this.props.cmController.showReplace();
140+
this.setDropdown('none');
141+
}
142+
143+
handleReplaceAll() {
144+
this.props.cmController.showReplaceAll();
145+
this.setDropdown('none');
146+
}
147+
136148
handleAddFile() {
137149
this.props.newFile(this.props.rootFile.id);
138150
this.setDropdown('none');
@@ -419,6 +431,26 @@ class Nav extends React.PureComponent {
419431
<span className="nav__keyboard-shortcut">{'\u21E7'}+{metaKeyName}+G</span>
420432
</button>
421433
</li>
434+
<li className="nav__dropdown-item">
435+
<button
436+
onClick={this.handleReplace}
437+
onFocus={this.handleFocusForEdit}
438+
onBlur={this.handleBlur}
439+
>
440+
{this.props.t('Nav.Edit.Replace')}
441+
<span className="nav__keyboard-shortcut">{metaKeyName}+R</span>
442+
</button>
443+
</li>
444+
<li className="nav__dropdown-item">
445+
<button
446+
onClick={this.handleReplaceAll}
447+
onFocus={this.handleFocusForEdit}
448+
onBlur={this.handleBlur}
449+
>
450+
{this.props.t('Nav.Edit.ReplaceAll')}
451+
<span className="nav__keyboard-shortcut">{'\u21E7'}+{metaKeyName}+R</span>
452+
</button>
453+
</li>
422454
</ul>
423455
</li>
424456
<li className={navDropdownState.sketch}>
@@ -793,6 +825,8 @@ Nav.propTypes = {
793825
showFind: PropTypes.func,
794826
findNext: PropTypes.func,
795827
findPrev: PropTypes.func,
828+
showReplace: PropTypes.func,
829+
showReplaceAll: PropTypes.func,
796830
getContent: PropTypes.func
797831
}),
798832
startSketch: PropTypes.func.isRequired,

client/modules/IDE/components/Editor.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class Editor extends React.Component {
7171
this.showFind = this.showFind.bind(this);
7272
this.findNext = this.findNext.bind(this);
7373
this.findPrev = this.findPrev.bind(this);
74+
this.showReplace = this.showReplace.bind(this);
75+
this.showReplaceAll = this.showReplaceAll.bind(this);
7476
this.getContent = this.getContent.bind(this);
7577
}
7678

@@ -122,6 +124,7 @@ class Editor extends React.Component {
122124
[`${metaKey}-G`]: 'findNext',
123125
[`Shift-${metaKey}-G`]: 'findPrev',
124126
[`${metaKey}-R`]: 'replace',
127+
[`Shift-${metaKey}-R`]: 'replaceAll',
125128
});
126129

127130
this.initializeDocuments(this.props.files);
@@ -155,6 +158,8 @@ class Editor extends React.Component {
155158
showFind: this.showFind,
156159
findNext: this.findNext,
157160
findPrev: this.findPrev,
161+
showReplace: this.showReplace,
162+
showReplaceAll: this.showReplaceAll,
158163
getContent: this.getContent
159164
});
160165
}
@@ -264,6 +269,14 @@ class Editor extends React.Component {
264269
this._cm.execCommand('findPersistent');
265270
}
266271

272+
showReplace() {
273+
this._cm.execCommand('replace');
274+
}
275+
276+
showReplaceAll() {
277+
this._cm.execCommand('replaceAll');
278+
}
279+
267280
tidyCode() {
268281
const beautifyOptions = {
269282
indent_size: INDENTATION_AMOUNT,

client/modules/IDE/components/KeyboardShortcutModal.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ function KeyboardShortcutModal() {
3333
</span>
3434
<span>{t('KeyboardShortcuts.CodeEditing.FindPreviousTextMatch')}</span>
3535
</li>
36+
<li className="keyboard-shortcut-item">
37+
<span className="keyboard-shortcut__command">
38+
{metaKeyName} + R
39+
</span>
40+
<span>{t('KeyboardShortcuts.CodeEditing.ReplaceTextMatch')}</span>
41+
</li>
42+
<li className="keyboard-shortcut-item">
43+
<span className="keyboard-shortcut__command">
44+
{metaKeyName} + {'\u21E7'} + R
45+
</span>
46+
<span>{t('KeyboardShortcuts.CodeEditing.ReplaceAllTextMatches')}</span>
47+
</li>
3648
<li className="keyboard-shortcut-item">
3749
<span className="keyboard-shortcut__command">
3850
{metaKeyName} + [

client/styles/components/_keyboard-shortcuts.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
padding: #{20 / $base-font-size}rem;
33
padding-bottom: #{40 / $base-font-size}rem;
44
width: #{450 / $base-font-size}rem;
5+
overflow-y: scroll;
56
}
67

78
.keyboard-shortcuts-note {

translations/locales/en-US/translations.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"TidyCode": "Tidy Code",
1616
"Find": "Find",
1717
"FindNext": "Find Next",
18-
"FindPrevious": "Find Previous"
18+
"FindPrevious": "Find Previous",
19+
"Replace": "Replace",
20+
"ReplaceAll": "Replace All"
1921
},
2022
"Sketch": {
2123
"Title": "Sketch",
@@ -159,6 +161,8 @@
159161
"FindText": "Find Text",
160162
"FindNextMatch": "Find Next Match",
161163
"FindPrevMatch": "Find Previous Match",
164+
"ReplaceTextMatch": "Replace Text Match",
165+
"ReplaceAllTextMatches": "Replace All Text Matches",
162166
"IndentCodeLeft": "Indent Code Left",
163167
"IndentCodeRight": "Indent Code Right",
164168
"CommentLine": "Comment Line",

translations/locales/es-419/translations.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"TidyCode": "Ordenar código",
1616
"Find": "Buscar",
1717
"FindNext": "Buscar siguiente",
18-
"FindPrevious": "Buscar anterior"
18+
"FindPrevious": "Buscar anterior",
19+
"Replace": "Reemplazar",
20+
"ReplaceAll": "Reemplaza todo"
1921
},
2022
"Sketch": {
2123
"Title": "Bosquejo",
@@ -159,6 +161,8 @@
159161
"FindText": "Encontrar texto",
160162
"FindNextMatch": "Encontrar siguiente ocurrencia",
161163
"FindPrevMatch": "Encontrar ocurrencia previa",
164+
"ReplaceTextMatch": "Reemplazar coincidencia de texto",
165+
"ReplaceAllTextMatches": "Reemplazar todas las coincidencias de texto",
162166
"IndentCodeLeft": "Indentar código a la izquierda",
163167
"IndentCodeRight": "Indentar código a la derecha",
164168
"CommentLine": "Comentar línea de código",

0 commit comments

Comments
 (0)