Skip to content

Commit 9484071

Browse files
authored
Merge pull request #1552 from SundeepChand/add-replace
Add replace
2 parents c83efa2 + f0783d6 commit 9484071

19 files changed

+813
-457
lines changed

client/components/Nav.jsx

+19-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { setAllAccessibleOutput, setLanguage } from '../modules/IDE/actions/pref
1313
import { logoutUser } from '../modules/User/actions';
1414

1515
import getConfig from '../utils/getConfig';
16-
import { metaKeyName, } from '../utils/metaKey';
16+
import { metaKeyName, metaKey } from '../utils/metaKey';
1717
import { getIsUserOwner } from '../modules/IDE/selectors/users';
1818

1919
import CaretLeftIcon from '../images/left-arrow.svg';
@@ -42,6 +42,7 @@ class Nav extends React.PureComponent {
4242
this.handleFindNext = this.handleFindNext.bind(this);
4343
this.handleRun = this.handleRun.bind(this);
4444
this.handleFindPrevious = this.handleFindPrevious.bind(this);
45+
this.handleReplace = this.handleReplace.bind(this);
4546
this.handleStop = this.handleStop.bind(this);
4647
this.handleStartAccessible = this.handleStartAccessible.bind(this);
4748
this.handleStopAccessible = this.handleStopAccessible.bind(this);
@@ -134,6 +135,11 @@ class Nav extends React.PureComponent {
134135
this.setDropdown('none');
135136
}
136137

138+
handleReplace() {
139+
this.props.cmController.showReplace();
140+
this.setDropdown('none');
141+
}
142+
137143
handleAddFile() {
138144
this.props.newFile(this.props.rootFile.id);
139145
this.setDropdown('none');
@@ -251,6 +257,7 @@ class Nav extends React.PureComponent {
251257
}
252258

253259
renderProjectMenu(navDropdownState) {
260+
const replaceCommand = metaKey === 'Ctrl' ? `${metaKeyName}+H` : `${metaKeyName}+⌥+F`;
254261
return (
255262
<ul className="nav__items-left">
256263
<li className="nav__item-logo">
@@ -416,6 +423,16 @@ class Nav extends React.PureComponent {
416423
<span className="nav__keyboard-shortcut">{'\u21E7'}+{metaKeyName}+G</span>
417424
</button>
418425
</li>
426+
<li className="nav__dropdown-item">
427+
<button
428+
onClick={this.handleReplace}
429+
onFocus={this.handleFocusForEdit}
430+
onBlur={this.handleBlur}
431+
>
432+
{this.props.t('Nav.Edit.Replace')}
433+
<span className="nav__keyboard-shortcut">{replaceCommand}</span>
434+
</button>
435+
</li>
419436
</ul>
420437
</li>
421438
<li className={navDropdownState.sketch}>
@@ -777,6 +794,7 @@ Nav.propTypes = {
777794
showFind: PropTypes.func,
778795
findNext: PropTypes.func,
779796
findPrev: PropTypes.func,
797+
showReplace: PropTypes.func,
780798
getContent: PropTypes.func
781799
}),
782800
startSketch: PropTypes.func.isRequired,

client/components/__test__/Nav.test.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ describe('Nav', () => {
3535
tidyCode: jest.fn(),
3636
showFind: jest.fn(),
3737
findNext: jest.fn(),
38-
findPrev: jest.fn()
38+
findPrev: jest.fn(),
39+
showReplace: jest.fn(),
3940
},
4041
startSketch: jest.fn(),
4142
stopSketch: jest.fn(),

client/components/__test__/__snapshots__/Nav.test.jsx.snap

+11
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ exports[`Nav renders correctly 1`] = `
122122
</span>
123123
</button>
124124
</li>
125+
<li
126+
class="nav__dropdown-item"
127+
>
128+
<button>
129+
<span
130+
class="nav__keyboard-shortcut"
131+
>
132+
⌃+H
133+
</span>
134+
</button>
135+
</li>
125136
</ul>
126137
</li>
127138
<li

client/modules/IDE/components/Editor.jsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import 'codemirror/addon/search/match-highlighter';
2222
import 'codemirror/addon/search/jump-to-line';
2323
import 'codemirror/addon/edit/matchbrackets';
2424
import 'codemirror/addon/edit/closebrackets';
25+
import 'codemirror/addon/selection/mark-selection';
2526

2627
import { JSHINT } from 'jshint';
2728
import { CSSLint } from 'csslint';
@@ -37,7 +38,7 @@ import Timer from '../components/Timer';
3738
import EditorAccessibility from '../components/EditorAccessibility';
3839
import { metaKey, } from '../../../utils/metaKey';
3940

40-
import search from '../../../utils/codemirror-search';
41+
import '../../../utils/codemirror-search';
4142

4243
import beepUrl from '../../../sounds/audioAlert.mp3';
4344
import UnsavedChangesDotIcon from '../../../images/unsaved-changes-dot.svg';
@@ -55,8 +56,6 @@ import * as UserActions from '../../User/actions';
5556
import * as ToastActions from '../actions/toast';
5657
import * as ConsoleActions from '../actions/console';
5758

58-
search(CodeMirror);
59-
6059
const beautifyCSS = beautifyJS.css;
6160
const beautifyHTML = beautifyJS.html;
6261

@@ -86,6 +85,7 @@ class Editor extends React.Component {
8685
this.showFind = this.showFind.bind(this);
8786
this.findNext = this.findNext.bind(this);
8887
this.findPrev = this.findPrev.bind(this);
88+
this.showReplace = this.showReplace.bind(this);
8989
this.getContent = this.getContent.bind(this);
9090
}
9191

@@ -106,6 +106,7 @@ class Editor extends React.Component {
106106
highlightSelectionMatches: true, // highlight current search match
107107
matchBrackets: true,
108108
autoCloseBrackets: this.props.autocloseBracketsQuotes,
109+
styleSelectedText: true,
109110
lint: {
110111
onUpdateLinting: ((annotations) => {
111112
this.props.hideRuntimeErrorWarning();
@@ -122,6 +123,7 @@ class Editor extends React.Component {
122123

123124
delete this._cm.options.lint.options.errors;
124125

126+
const replaceCommand = metaKey === 'Ctrl' ? `${metaKey}-H` : `${metaKey}-Option-F`;
125127
this._cm.setOption('extraKeys', {
126128
Tab: (cm) => {
127129
// might need to specify and indent more?
@@ -137,6 +139,7 @@ class Editor extends React.Component {
137139
[`${metaKey}-F`]: 'findPersistent',
138140
[`${metaKey}-G`]: 'findNext',
139141
[`Shift-${metaKey}-G`]: 'findPrev',
142+
replaceCommand: 'replace',
140143
});
141144

142145
this.initializeDocuments(this.props.files);
@@ -170,6 +173,7 @@ class Editor extends React.Component {
170173
showFind: this.showFind,
171174
findNext: this.findNext,
172175
findPrev: this.findPrev,
176+
showReplace: this.showReplace,
173177
getContent: this.getContent
174178
});
175179
}
@@ -283,6 +287,10 @@ class Editor extends React.Component {
283287
this._cm.execCommand('findPersistent');
284288
}
285289

290+
showReplace() {
291+
this._cm.execCommand('replace');
292+
}
293+
286294
tidyCode() {
287295
const beautifyOptions = {
288296
indent_size: INDENTATION_AMOUNT,

client/modules/IDE/components/KeyboardShortcutModal.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { metaKeyName, } from '../../../utils/metaKey';
3+
import { metaKeyName, metaKey } from '../../../utils/metaKey';
44

55
function KeyboardShortcutModal() {
66
const { t } = useTranslation();
7+
const replaceCommand = metaKey === 'Ctrl' ? `${metaKeyName} + H` : `${metaKeyName} + ⌥ + F`;
78
return (
89
<div className="keyboard-shortcuts">
910
<h3 className="keyboard-shortcuts__title">{t('KeyboardShortcuts.CodeEditing.CodeEditing')}</h3>
@@ -33,6 +34,12 @@ function KeyboardShortcutModal() {
3334
</span>
3435
<span>{t('KeyboardShortcuts.CodeEditing.FindPreviousTextMatch')}</span>
3536
</li>
37+
<li className="keyboard-shortcut-item">
38+
<span className="keyboard-shortcut__command">
39+
{replaceCommand}
40+
</span>
41+
<span>{t('KeyboardShortcuts.CodeEditing.ReplaceTextMatch')}</span>
42+
</li>
3643
<li className="keyboard-shortcut-item">
3744
<span className="keyboard-shortcut__command">
3845
{metaKeyName} + [

client/styles/abstracts/_placeholders.scss

+6
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,15 @@
173173
text-decoration: none;
174174
color: getThemifyVariable('inactive-text-color');
175175
cursor: pointer;
176+
& g, & path {
177+
fill: getThemifyVariable('inactive-text-color');
178+
}
176179
&:hover {
177180
text-decoration: none;
178181
color: getThemifyVariable('heavy-text-color');
182+
& g, & path {
183+
fill: getThemifyVariable('heavy-text-color');
184+
}
179185
}
180186
}
181187
}

client/styles/abstracts/_variables.scss

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ $base-font-size: 12;
22

33
//colors
44
$p5js-pink: #ed225d;
5+
$p5js-pink-opacity: #ed225d80;
56
$processing-blue: #007BBB;
67
$p5js-active-pink: #f10046;
78
$white: #fff;

0 commit comments

Comments
 (0)